diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java
index 787a3b9bc..43f35815e 100644
--- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java
+++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/ClassMethodInterceptor.java
@@ -51,11 +51,11 @@ public class ClassMethodInterceptor {
} catch(Throwable t){
try {
interceptor.handleMethodException(t, instanceContext, interceptorContext, ret);
- throw t;
} catch (Throwable t2) {
logger.error("class[{}] handle method[{}] exception failue:{}",
obj.getClass(), method.getName(), t2.getMessage(), t2);
}
+ throw t;
}finally {
try {
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
index bfe215db4..022d62ae5 100644
--- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
+++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
@@ -15,6 +15,7 @@ import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.SuperMethodCall;
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
import net.bytebuddy.pool.TypePool;
+import net.bytebuddy.pool.TypePool.Resolution;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -59,6 +60,14 @@ public class EnhanceClazz4Interceptor {
logger.debug("prepare to enhance class {} by {}.",
enhanceOriginClassName, interceptorDefineClassName);
+
+ Resolution resolution = typePool.describe(enhanceOriginClassName);
+ if(!resolution.isResolved()){
+ logger.warn("class {} can't be resolved, enhance by {} failue.",
+ enhanceOriginClassName, interceptorDefineClassName);
+ return;
+ }
+
/**
* rename origin class
* add '$$Origin' at the end of be enhanced classname
@@ -67,7 +76,7 @@ public class EnhanceClazz4Interceptor {
*/
String renameClassName = enhanceOriginClassName + "$$Origin";
Class> originClass = new ByteBuddy()
- .redefine(typePool.describe(enhanceOriginClassName).resolve(),
+ .redefine(resolution.resolve(),
ClassFileLocator.ForClassLoader.ofClassPath())
.name(renameClassName)
.make()
diff --git a/skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java b/skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
index aedb8829c..204573bc3 100644
--- a/skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
+++ b/skywalking-api/src/test/java/test/ai/cloud/bytebuddy/SimulateMain.java
@@ -14,6 +14,7 @@ public class SimulateMain {
public static void main(String[] args) throws NoSuchFieldException,
SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException {
TypePool typePool = TypePool.Default.ofClassPath();
+ System.out.println(typePool.describe("test.ai.cloud.bytebuddy.TestClass").isResolved());
Class> newClazz = new ByteBuddy()
.redefine(
diff --git a/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml
index 5784905ba..a7bab323f 100644
--- a/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml
+++ b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml
@@ -33,6 +33,7 @@
org.apache.httpcomponents
httpclient
4.3
+ compile
diff --git a/skywalking-sdk-plugin/pom.xml b/skywalking-sdk-plugin/pom.xml
index c87e9eff2..a62a34a9b 100644
--- a/skywalking-sdk-plugin/pom.xml
+++ b/skywalking-sdk-plugin/pom.xml
@@ -1,6 +1,5 @@
-
+
4.0.0
com.ai.cloud
@@ -14,7 +13,8 @@
web-plugin
httpclient-4.2.x-plugin
httpclient-4.3.x-plugin
-
+ skywalking-httpClient-4.x-plugin
+
pom
skywalking-sdk-plugin
@@ -53,13 +53,4 @@
-
-
-
-
- company-private-nexus-library-snapshots
- company-private-nexus-library-snapshots
- http://10.1.228.199:18081/nexus/content/repositories/snapshots/
-
-
\ No newline at end of file
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/pom.xml b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/pom.xml
new file mode 100644
index 000000000..11ed432c3
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ com.ai.cloud
+ skywalking-sdk-plugin
+ 1.0-SNAPSHOT
+
+ skywalking-httpClient-4.x-plugin
+ skywalking-httpClient-4.x-plugin
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ com.ai.cloud
+ skywalking-api
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.3
+ test
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.4.1
+ test
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+
+
+ maven-compiler-plugin
+
+ 1.7
+ 1.7
+ ${project.build.sourceEncoding}
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.4.3
+
+ ${project.build.sourceEncoding}
+
+
+
+
+
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java
new file mode 100644
index 000000000..fc9a12a3f
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java
@@ -0,0 +1,76 @@
+package org.skywalking.httpClient.v4.plugin;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+
+import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
+import com.ai.cloud.skywalking.model.Identification;
+import com.ai.cloud.skywalking.plugin.interceptor.ConstructorInvokeContext;
+import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
+import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
+import com.ai.cloud.skywalking.plugin.interceptor.MethodInvokeContext;
+
+public class HttpClientExecuteInterceptor implements IAroundInterceptor {
+ /**
+ * TODO: need laod from config
+ */
+ public static String traceHearName = "";
+
+ private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
+
+ @Override
+ public void onConstruct(EnhancedClassInstanceContext context,
+ ConstructorInvokeContext interceptorContext) {
+ }
+
+ @Override
+ public void beforeMethod(EnhancedClassInstanceContext context,
+ MethodInvokeContext interceptorContext) {
+ Object[] allArguments = interceptorContext.allArguments();
+ if (allArguments[0] == null || allArguments[1] == null) {
+ // illegal args, can't trace. ignore.
+ return;
+ }
+ HttpHost httpHost = (HttpHost) allArguments[0];
+ HttpRequest httpRequest = (HttpRequest) allArguments[1];
+ httpRequest
+ .setHeader(
+ traceHearName,
+ "ContextData="
+ + sender.beforeSend(
+ Identification
+ .newBuilder()
+ .viewPoint(
+ httpHost.toURI()
+ .toString())
+ .spanType(
+ WebBuriedPointType
+ .instance())
+ .build()).toString());
+ }
+
+ @Override
+ public Object afterMethod(EnhancedClassInstanceContext context,
+ MethodInvokeContext interceptorContext, Object ret) {
+ Object[] allArguments = interceptorContext.allArguments();
+ if (allArguments[0] == null || allArguments[1] == null) {
+ // illegal args, can't trace. ignore.
+ return ret;
+ }
+ sender.afterSend();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(Throwable t,
+ EnhancedClassInstanceContext context,
+ MethodInvokeContext interceptorContext, Object ret) {
+ Object[] allArguments = interceptorContext.allArguments();
+ if (allArguments[0] == null || allArguments[1] == null) {
+ // illegal args, can't trace. ignore.
+ return;
+ }
+ sender.handleException(t);
+ }
+
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/WebBuriedPointType.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/WebBuriedPointType.java
new file mode 100644
index 000000000..df2342a83
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/WebBuriedPointType.java
@@ -0,0 +1,31 @@
+package org.skywalking.httpClient.v4.plugin;
+
+import com.ai.cloud.skywalking.api.IBuriedPointType;
+import com.ai.cloud.skywalking.protocol.CallType;
+
+public class WebBuriedPointType implements IBuriedPointType {
+
+ private static WebBuriedPointType webBuriedPointType;
+
+ public static IBuriedPointType instance() {
+ if (webBuriedPointType == null) {
+ webBuriedPointType = new WebBuriedPointType();
+ }
+
+ return webBuriedPointType;
+ }
+
+ @Override
+ public String getTypeName() {
+ return "W";
+ }
+
+ @Override
+ public CallType getCallType() {
+ return CallType.SYNC;
+ }
+
+ private WebBuriedPointType() {
+ // Non
+ }
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java
new file mode 100644
index 000000000..5e601321a
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java
@@ -0,0 +1,32 @@
+package org.skywalking.httpClient.v4.plugin.define;
+
+import io.netty.handler.codec.http.HttpRequest;
+
+import javax.xml.ws.spi.http.HttpContext;
+
+import org.apache.http.HttpHost;
+
+import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
+
+public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
+
+ @Override
+ public String getBeInterceptedClassName() {
+ return "org.apache.http.impl.client.AbstractHttpClient";
+ }
+
+ /**
+ * version 4.2, intercept method: execute, intercept
+ * public final HttpResponse execute(HttpHost target, HttpRequest request,
+ * HttpContext context)
+ *
+ * since version 4.3,intercept method: doExecute
+ */
+ @Override
+ public InterceptPoint[] getBeInterceptedMethods() {
+ return new InterceptPoint[] {
+ new InterceptPoint("doExecute"),
+ new InterceptPoint("execute", HttpHost.class,
+ HttpRequest.class, HttpContext.class) };
+ }
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/HttpClientPluginDefine.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/HttpClientPluginDefine.java
new file mode 100644
index 000000000..316c4edf6
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/HttpClientPluginDefine.java
@@ -0,0 +1,15 @@
+package org.skywalking.httpClient.v4.plugin.define;
+
+import org.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor;
+
+import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
+import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
+
+public abstract class HttpClientPluginDefine implements InterceptorDefine {
+
+ @Override
+ public IAroundInterceptor instance() {
+ return new HttpClientExecuteInterceptor();
+ }
+
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java
new file mode 100644
index 000000000..8ad3a754d
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/InternalHttpClientPluginDefine.java
@@ -0,0 +1,16 @@
+package org.skywalking.httpClient.v4.plugin.define;
+
+import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
+
+public class InternalHttpClientPluginDefine extends HttpClientPluginDefine {
+ @Override
+ public InterceptPoint[] getBeInterceptedMethods() {
+ return new InterceptPoint[]{new InterceptPoint("doExecute")};
+ }
+
+ @Override
+ public String getBeInterceptedClassName() {
+ return "org.apache.http.impl.client.InternalHttpClient";
+ }
+
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java
new file mode 100644
index 000000000..32479cb38
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/MinimalHttpClientPluginDefine.java
@@ -0,0 +1,16 @@
+package org.skywalking.httpClient.v4.plugin.define;
+
+import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
+
+public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine {
+ @Override
+ public InterceptPoint[] getBeInterceptedMethods() {
+ return new InterceptPoint[]{new InterceptPoint("doExecute")};
+ }
+
+ @Override
+ public String getBeInterceptedClassName() {
+ return "org.apache.http.impl.client.MinimalHttpClient";
+ }
+
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 000000000..4c138b961
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,3 @@
+org.skywalking.httpClient.v4.plugin.define.AbstractHttpClientPluginDefine
+org.skywalking.httpClient.v4.plugin.define.InternalHttpClientPluginDefine
+org.skywalking.httpClient.v4.plugin.define.MinimalHttpClientPluginDefine
\ No newline at end of file
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV43.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV43.java
new file mode 100644
index 000000000..5e3eff022
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV43.java
@@ -0,0 +1,60 @@
+package org.skywalking.httpClient.v4.plugin;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.junit.Test;
+
+import com.ai.cloud.skywalking.plugin.TracingBootstrap;
+
+public class TestHttpClientV43 {
+ @Test
+ public void testsql() throws IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException,
+ NoSuchMethodException, SecurityException, ClassNotFoundException {
+ TracingBootstrap
+ .main(new String[] { "org.skywalking.httpClient.v4.plugin.TestHttpClientV43" });
+ }
+
+ public static void main(String[] args) throws ClassNotFoundException,
+ SQLException, InterruptedException {
+ HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
+ // HttpClient
+ CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
+
+ HttpGet httpGet = new HttpGet("http://www.baidu.com");
+ System.out.println(httpGet.getRequestLine());
+ try {
+ // 执行get请求
+ HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
+ // 获取响应消息实体
+ HttpEntity entity = httpResponse.getEntity();
+ // 响应状态
+ System.out.println("status:" + httpResponse.getStatusLine());
+ // 判断响应实体是否为空
+ if (entity != null) {
+ System.out.println("contentEncoding:"
+ + entity.getContentEncoding());
+ System.out.println("response content:"
+ + EntityUtils.toString(entity));
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try { // 关闭流并释放资源
+ closeableHttpClient.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ Thread.sleep(5*1000);
+ }
+}
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/log4j2.xml b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/log4j2.xml
new file mode 100644
index 000000000..4e2af7485
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/log4j2.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/sky-walking.auth b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/sky-walking.auth
new file mode 100644
index 000000000..c794ea37c
--- /dev/null
+++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin/src/test/resources/sky-walking.auth
@@ -0,0 +1,47 @@
+#skyWalking用户ID
+skywalking.user_id=123
+#skyWalking应用编码
+skywalking.application_code=test
+#skywalking auth的环境变量名字
+skywalking.auth_system_env_name=SKYWALKING_RUN
+#skywalking数据编码
+skywalking.charset=UTF-8
+
+#是否打印数据
+buriedpoint.printf=true
+#埋点异常的最大长度
+buriedpoint.max_exception_stack_length=4000
+#业务字段的最大长度
+buriedpoint.businesskey_max_length=300
+#过滤异常
+buriedpoint.exclusive_exceptions=java.lang.RuntimeException
+
+#最大发送者的连接数阀比例
+sender.connect_percent=100
+#发送服务端配置
+sender.servers_addr=127.0.0.1:34000
+#最大发送的副本数量
+sender.max_copy_num=2
+#发送的最大长度
+sender.max_send_length=20000
+#当没有Sender时,尝试获取sender的等待周期
+sender.retry_get_sender_wait_interval=2000
+#是否开启发送消息
+sender.is_off=false
+
+
+#最大消费线程数
+consumer.max_consumer=2
+#消费者最大等待时间
+consumer.max_wait_time=5
+#发送失败等待时间
+consumer.consumer_fail_retry_wait_interval=50
+
+#每个Buffer的最大个数
+buffer.buffer_max_size=18000
+#Buffer池的最大长度
+buffer.pool_size=5
+
+#发送检查线程检查周期
+senderchecker.check_polling_time=200
+