1.增加拦截器实例化的判断,#36。
2.httpClient-4.x-plugin,全面支持4.0版本。完成4.2和4.3差异化API测试。
This commit is contained in:
parent
8365964493
commit
720c4ced6f
|
|
@ -50,7 +50,7 @@ public class EnhanceClazz4Interceptor {
|
|||
|
||||
private void enhance0(String interceptorDefineClassName)
|
||||
throws InstantiationException, IllegalAccessException,
|
||||
ClassNotFoundException {
|
||||
ClassNotFoundException, EnhanceException {
|
||||
logger.debug("prepare to enhance class by {}.",
|
||||
interceptorDefineClassName);
|
||||
InterceptorDefine define = (InterceptorDefine) Class.forName(
|
||||
|
|
@ -94,6 +94,9 @@ public class EnhanceClazz4Interceptor {
|
|||
* required by interceptorDefineClass. <br/>
|
||||
*/
|
||||
IAroundInterceptor interceptor = define.instance();
|
||||
if(interceptor == null){
|
||||
throw new EnhanceException("no IAroundInterceptor instance. ");
|
||||
}
|
||||
|
||||
DynamicType.Builder<?> newClassBuilder = new ByteBuddy().subclass(
|
||||
originClass, ConstructorStrategy.Default.IMITATE_SUPER_CLASS);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor;
|
||||
|
||||
public class EnhanceException extends Exception {
|
||||
private static final long serialVersionUID = -2234782755784217255L;
|
||||
|
||||
public EnhanceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EnhanceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,12 +23,21 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import com.ai.cloud.skywalking.plugin.interceptor.MethodInvokeContext;
|
|||
|
||||
public class HttpClientExecuteInterceptor implements IAroundInterceptor {
|
||||
/**
|
||||
* TODO: need laod from config
|
||||
* default headname of sky walking context<br/>
|
||||
*/
|
||||
public static String traceHearName = "";
|
||||
public static String TRACE_HEAD_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class HttpClientExecuteInterceptor implements IAroundInterceptor {
|
|||
HttpRequest httpRequest = (HttpRequest) allArguments[1];
|
||||
httpRequest
|
||||
.setHeader(
|
||||
traceHearName,
|
||||
TRACE_HEAD_NAME,
|
||||
"ContextData="
|
||||
+ sender.beforeSend(
|
||||
Identification
|
||||
|
|
|
|||
|
|
@ -1,11 +1,5 @@
|
|||
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 {
|
||||
|
|
@ -20,13 +14,10 @@ public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
|
|||
* public final HttpResponse execute(HttpHost target, HttpRequest request,
|
||||
* HttpContext context)<br/>
|
||||
*
|
||||
* since version 4.3,intercept method: doExecute<br/>
|
||||
*/
|
||||
@Override
|
||||
public InterceptPoint[] getBeInterceptedMethods() {
|
||||
return new InterceptPoint[] {
|
||||
new InterceptPoint("doExecute"),
|
||||
new InterceptPoint("execute", HttpHost.class,
|
||||
HttpRequest.class, HttpContext.class) };
|
||||
new InterceptPoint("doExecute")};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package org.skywalking.httpClient.v4.plugin.define;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint;
|
||||
|
||||
public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine {
|
||||
/**
|
||||
* DefaultRequestDirector is default implement.<br/>
|
||||
* usually use in version 4.0-4.2<br/>
|
||||
* since 4.3, this class is Deprecated.
|
||||
*/
|
||||
@Override
|
||||
public String getBeInterceptedClassName() {
|
||||
return "org.apache.http.impl.client.DefaultRequestDirector";
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterceptPoint[] getBeInterceptedMethods() {
|
||||
return new InterceptPoint[] {
|
||||
new InterceptPoint("execute")};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
org.skywalking.httpClient.v4.plugin.define.AbstractHttpClientPluginDefine
|
||||
org.skywalking.httpClient.v4.plugin.define.InternalHttpClientPluginDefine
|
||||
org.skywalking.httpClient.v4.plugin.define.MinimalHttpClientPluginDefine
|
||||
org.skywalking.httpClient.v4.plugin.define.MinimalHttpClientPluginDefine
|
||||
org.skywalking.httpClient.v4.plugin.define.DefaultRequestDirectorPluginDefine
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.skywalking.httpClient.v4.plugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.TracingBootstrap;
|
||||
|
||||
public class TestHttpClientV42 {
|
||||
@Test
|
||||
public void testsql() throws IllegalAccessException,
|
||||
IllegalArgumentException, InvocationTargetException,
|
||||
NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
TracingBootstrap
|
||||
.main(new String[] { "org.skywalking.httpClient.v4.plugin.TestHttpClientV42" });
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException,
|
||||
SQLException, InterruptedException, ClientProtocolException, IOException {
|
||||
// 默认的client类。
|
||||
HttpClient client = new DefaultHttpClient();
|
||||
// 设置为get取连接的方式.
|
||||
HttpGet get = new HttpGet("http://www.baidu.com");
|
||||
// 得到返回的response.
|
||||
HttpResponse response = client.execute(get);
|
||||
// 得到返回的client里面的实体对象信息.
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
System.out.println("内容编码是:" + entity.getContentEncoding());
|
||||
System.out.println("内容类型是:" + entity.getContentType());
|
||||
// 得到返回的主体内容.
|
||||
InputStream instream = entity.getContent();
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(instream, "UTF-8"));
|
||||
System.out.println(reader.readLine());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭连接.
|
||||
client.getConnectionManager().shutdown();
|
||||
|
||||
Thread.sleep(5*1000);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue