From cf93d1eee16327f98e62a94306c56d14370aaa4c Mon Sep 17 00:00:00 2001 From: zhangxin10 Date: Thu, 31 Dec 2015 10:24:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0httpClient4.3=E7=9A=84?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=202.=20=E4=BF=AE=E6=94=B9=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- skywalking-sdk-plugin/dubbo-plugin/pom.xml | 2 +- .../httpclient-4.3.x-plugin/pom.xml | 38 +++++ .../httpclient/v43x/HttpClientTracing.java | 40 +++++ .../v43x/SWTracingCloseableHttpClient.java | 139 ++++++++++++++++++ .../httpclient-plugin/pom.xml | 55 ------- skywalking-sdk-plugin/jdbc-plugin/pom.xml | 2 +- skywalking-sdk-plugin/pom.xml | 12 +- skywalking-sdk-plugin/web-plugin/pom.xml | 2 +- 8 files changed, 231 insertions(+), 59 deletions(-) create mode 100644 skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml create mode 100644 skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/HttpClientTracing.java create mode 100644 skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/SWTracingCloseableHttpClient.java delete mode 100644 skywalking-sdk-plugin/httpclient-plugin/pom.xml diff --git a/skywalking-sdk-plugin/dubbo-plugin/pom.xml b/skywalking-sdk-plugin/dubbo-plugin/pom.xml index d0e2e7722..d9a652d47 100644 --- a/skywalking-sdk-plugin/dubbo-plugin/pom.xml +++ b/skywalking-sdk-plugin/dubbo-plugin/pom.xml @@ -10,7 +10,7 @@ skywalking-dubbo-plugin jar - spring-plugin + dubbo-plugin http://maven.apache.org diff --git a/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml new file mode 100644 index 000000000..06ba6b9df --- /dev/null +++ b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/pom.xml @@ -0,0 +1,38 @@ + + + skywalking-sdk-plugin + com.ai.cloud + 1.0-SNAPSHOT + + 4.0.0 + + skywalking-httpclient-4.3.x-plugin + jar + + httpclient-4.3.x-plugin + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + com.ai.cloud + skywalking-api + 1.0-SNAPSHOT + + + org.apache.httpcomponents + httpclient + 4.3 + + + diff --git a/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/HttpClientTracing.java b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/HttpClientTracing.java new file mode 100644 index 000000000..2bd5c94a0 --- /dev/null +++ b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/HttpClientTracing.java @@ -0,0 +1,40 @@ +package com.ai.cloud.skywalking.plugin.httpclient.v43x; + +import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender; +import com.ai.cloud.skywalking.conf.AuthDesc; +import com.ai.cloud.skywalking.model.Identification; +import org.apache.http.HttpRequest; + +import java.io.IOException; + +public class HttpClientTracing { + + private static RPCBuriedPointSender sender = new RPCBuriedPointSender(); + + public static R execute(String url, String traceHearName, HttpRequest httpRequest, Executor executor) throws IOException { + if (!AuthDesc.isAuth()) { + return executor.execute(); + } + + try { + httpRequest.setHeader(traceHearName, + "ContextData=" + sender.beforeSend(Identification.newBuilder() + .viewPoint(url) + .spanType("W") + .build()) + .toString()); + return executor.execute(); + } catch (IOException e) { + sender.handleException(e); + throw e; + } finally { + sender.afterSend(); + } + } + + public interface Executor { + R execute() throws IOException; + } + + +} diff --git a/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/SWTracingCloseableHttpClient.java b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/SWTracingCloseableHttpClient.java new file mode 100644 index 000000000..b3827907f --- /dev/null +++ b/skywalking-sdk-plugin/httpclient-4.3.x-plugin/src/main/java/com/ai/cloud/skywalking/plugin/httpclient/v43x/SWTracingCloseableHttpClient.java @@ -0,0 +1,139 @@ +package com.ai.cloud.skywalking.plugin.httpclient.v43x; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpContext; + +import java.io.IOException; + +public class SWTracingCloseableHttpClient extends CloseableHttpClient { + private static final String DEFAULT_TRACE_NAME = "SkyWalking-TRACING-NAME"; + + private CloseableHttpClient client; + private String traceHeaderName; + + public SWTracingCloseableHttpClient(CloseableHttpClient client, String traceHeaderName) { + this.client = client; + if (traceHeaderName == null || traceHeaderName.length() <= 0) { + throw new IllegalArgumentException("Trace header name can not be null"); + } + this.traceHeaderName = traceHeaderName; + } + + public SWTracingCloseableHttpClient(CloseableHttpClient client) { + this.client = client; + this.traceHeaderName = DEFAULT_TRACE_NAME; + } + + @Override + public void close() throws IOException { + client.close(); + } + + @Override + public HttpParams getParams() { + return client.getParams(); + } + + @Override + public ClientConnectionManager getConnectionManager() { + return client.getConnectionManager(); + } + + @Override + public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public CloseableHttpResponse execute() throws IOException { + return client.execute(request); + } + }); + } + + @Override + public CloseableHttpResponse execute(final HttpUriRequest request, final HttpContext context) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public CloseableHttpResponse execute() throws IOException { + return client.execute(request, context); + } + }); + } + + @Override + public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public CloseableHttpResponse execute() throws IOException { + return client.execute(target, request); + } + }); + } + + @Override + protected CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public CloseableHttpResponse execute() throws IOException { + return client.execute(target, request, context); + } + }); + } + + @Override + public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public CloseableHttpResponse execute() throws IOException { + return client.execute(target, request, context); + } + }); + } + + @Override + public T execute(final HttpUriRequest request, final ResponseHandler responseHandler) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public T execute() throws IOException { + return client.execute(request, responseHandler); + } + }); + } + + @Override + public T execute(final HttpUriRequest request, final ResponseHandler responseHandler, final HttpContext context) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public T execute() throws IOException { + return client.execute(request, responseHandler, context); + } + }); + } + + @Override + public T execute(final HttpHost target, final HttpRequest request, final ResponseHandler responseHandler) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public T execute() throws IOException { + return client.execute(target, request, responseHandler); + } + }); + } + + @Override + public T execute(final HttpHost target, final HttpRequest request, final ResponseHandler responseHandler, final HttpContext context) throws IOException, ClientProtocolException { + return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor() { + @Override + public T execute() throws IOException { + return client.execute(target, request, responseHandler, context); + } + }); + } +} diff --git a/skywalking-sdk-plugin/httpclient-plugin/pom.xml b/skywalking-sdk-plugin/httpclient-plugin/pom.xml deleted file mode 100644 index 36371955d..000000000 --- a/skywalking-sdk-plugin/httpclient-plugin/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - skywalking-sdk-plugin - com.ai.cloud - 1.0-SNAPSHOT - - 4.0.0 - - skywalking-httpClient-plugin - jar - - httpClient-plugin - http://maven.apache.org - - - UTF-8 - - - - - com.ai.cloud - skywalking-api - ${project.version} - - - org.apache.httpcomponents - httpclient - 4.2.1 - compile - - - - - - org.apache.maven.plugins - maven-deploy-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - - attach-sources - - jar - - - - - - - diff --git a/skywalking-sdk-plugin/jdbc-plugin/pom.xml b/skywalking-sdk-plugin/jdbc-plugin/pom.xml index eb8c5759a..48bfac4b9 100644 --- a/skywalking-sdk-plugin/jdbc-plugin/pom.xml +++ b/skywalking-sdk-plugin/jdbc-plugin/pom.xml @@ -10,7 +10,7 @@ skywalking-jdbc-plugin jar - spring-plugin + jdbc-plugin http://maven.apache.org diff --git a/skywalking-sdk-plugin/pom.xml b/skywalking-sdk-plugin/pom.xml index 091051cd8..fffd93e23 100644 --- a/skywalking-sdk-plugin/pom.xml +++ b/skywalking-sdk-plugin/pom.xml @@ -10,7 +10,8 @@ spring-plugin jdbc-plugin web-plugin - httpclient-plugin + httpclient-4.2.x-plugin + httpclient-4.3.x-plugin pom @@ -50,4 +51,13 @@ + + + + + company-private-nexus-library-snapshots + company-private-nexus-library-snapshots + http://10.1.228.199:18081/nexus/content/repositories/snapshots/ + + diff --git a/skywalking-sdk-plugin/web-plugin/pom.xml b/skywalking-sdk-plugin/web-plugin/pom.xml index 050f81ab4..a64f27ab6 100644 --- a/skywalking-sdk-plugin/web-plugin/pom.xml +++ b/skywalking-sdk-plugin/web-plugin/pom.xml @@ -10,7 +10,7 @@ skywalking-web-plugin jar - spring-plugin + web-plugin http://maven.apache.org