Search in sources :

Example 1 with ApacheAsyncHttpClientIT

use of com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT in project uavstack by uavorg.

the class HttpAsyncClientHookProxy method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * install proxy to InternalHttpAsyncClient
     */
    dpInstall.installProxy("org.apache.http.impl.nio.client.InternalHttpAsyncClient", new String[] { "com.creditease.uav.hook.httpclients.async.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("execute".equals(m.getName())) {
                if (m.getParameterTypes().length == 4) {
                    dpInstall.defineLocalVal(m, "mObj", ApacheAsyncHttpClientIT.class);
                    m.insertBefore("{mObj=new ApacheAsyncHttpClientIT(\"" + appid + "\"); " + "$2=mObj.makeConsumer($2);$4=mObj.doAsyncStart(new Object[]{$1,$2,$3,$4});}");
                    m.insertAfter("{$_=mObj.doAsyncEnd(new Object[]{$_});}");
                }
            }
        }
    }, false);
    /**
     * install proxy to MinimalHttpAsyncClient
     */
    dpInstall.installProxy("org.apache.http.impl.nio.client.MinimalHttpAsyncClient", new String[] { "com.creditease.uav.hook.httpclients.async.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("execute".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", ApacheAsyncHttpClientIT.class);
                if (m.getParameterTypes().length == 4) {
                    m.insertBefore("{mObj=new ApacheAsyncHttpClientIT(\"" + appid + "\"); $2=mObj.makeConsumer($2);$4=mObj.doAsyncStart(new Object[]{$1,$2,$3,$4});}");
                    m.insertAfter("{$_=mObj.doAsyncEnd(new Object[]{$_});}");
                } else if (m.getParameterTypes().length == 5) {
                    m.insertBefore("{mObj=new ApacheAsyncHttpClientIT(\"" + appid + "\"); $3=mObj.makeConsumers($3);$5=mObj.doAsyncStart(new Object[]{$1,$2,$3,$4,$5});}");
                    m.insertAfter("{$_=mObj.doAsyncEnd(new Object[]{$_});}");
                }
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) ApacheAsyncHttpClientIT(com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Aggregations

ApacheAsyncHttpClientIT (com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT)1 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)1 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)1