提交 cf93d1ee 编写于 作者: Z zhangxin10

1.添加httpClient4.3的插件

2. 修改工程名字
上级 5c51f5af
......@@ -10,7 +10,7 @@
<artifactId>skywalking-dubbo-plugin</artifactId>
<packaging>jar</packaging>
<name>spring-plugin</name>
<name>dubbo-plugin</name>
<url>http://maven.apache.org</url>
<properties>
......
......@@ -7,10 +7,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skywalking-httpClient-plugin</artifactId>
<artifactId>skywalking-httpclient-4.3.x-plugin</artifactId>
<packaging>jar</packaging>
<name>httpClient-plugin</name>
<name>httpclient-4.3.x-plugin</name>
<url>http://maven.apache.org</url>
<properties>
......@@ -18,38 +18,21 @@
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-api</artifactId>
<version>${project.version}</version>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
<scope>compile</scope>
<version>4.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<!-- 源码插件 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
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> R execute(String url, String traceHearName, HttpRequest httpRequest, Executor<R> 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> {
R execute() throws IOException;
}
}
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<CloseableHttpResponse>() {
@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<CloseableHttpResponse>() {
@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<CloseableHttpResponse>() {
@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<CloseableHttpResponse>() {
@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<CloseableHttpResponse>() {
@Override
public CloseableHttpResponse execute() throws IOException {
return client.execute(target, request, context);
}
});
}
@Override
public <T> T execute(final HttpUriRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
@Override
public T execute() throws IOException {
return client.execute(request, responseHandler);
}
});
}
@Override
public <T> T execute(final HttpUriRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
@Override
public T execute() throws IOException {
return client.execute(request, responseHandler, context);
}
});
}
@Override
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
@Override
public T execute() throws IOException {
return client.execute(target, request, responseHandler);
}
});
}
@Override
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
@Override
public T execute() throws IOException {
return client.execute(target, request, responseHandler, context);
}
});
}
}
......@@ -10,7 +10,7 @@
<artifactId>skywalking-jdbc-plugin</artifactId>
<packaging>jar</packaging>
<name>spring-plugin</name>
<name>jdbc-plugin</name>
<url>http://maven.apache.org</url>
<properties>
......
......@@ -10,7 +10,8 @@
<module>spring-plugin</module>
<module>jdbc-plugin</module>
<module>web-plugin</module>
<module>httpclient-plugin</module>
<module>httpclient-4.2.x-plugin</module>
<module>httpclient-4.3.x-plugin</module>
</modules>
<packaging>pom</packaging>
......@@ -50,4 +51,13 @@
</plugin>
</plugins>
</build>
<!--发布-->
<distributionManagement>
<snapshotRepository>
<id>company-private-nexus-library-snapshots</id>
<name>company-private-nexus-library-snapshots</name>
<url>http://10.1.228.199:18081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
......@@ -10,7 +10,7 @@
<artifactId>skywalking-web-plugin</artifactId>
<packaging>jar</packaging>
<name>spring-plugin</name>
<name>web-plugin</name>
<url>http://maven.apache.org</url>
<properties>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册