Commit 09fd93c5 authored by 吴晟's avatar 吴晟
Browse files

1.修复api拦截器,异常没有正常抛出的BUG。

2.提交基于httpClient 4.x的插件代码。暂未完成所有功能。完成4.3下的测试,4.2待测试。
parent 80da19e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+10 −1
Original line number Diff line number Diff line
@@ -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 <br/>
		 * add '$$Origin' at the end of be enhanced classname <br/>
@@ -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()
+1 −0
Original line number Diff line number Diff line
@@ -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(
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
+3 −12
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.ai.cloud</groupId>
@@ -14,6 +13,7 @@
		<module>web-plugin</module>
		<module>httpclient-4.2.x-plugin</module>
		<module>httpclient-4.3.x-plugin</module>
    	<module>skywalking-httpClient-4.x-plugin</module>
  </modules>
	<packaging>pom</packaging>

@@ -53,13 +53,4 @@
			</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>
 No newline at end of file
Loading