Search in sources :

Example 11 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class LogBackHookProxy method InsertIntercept.

private void InsertIntercept(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("insertLogbackIntercepter")) {
        return;
    }
    ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    if (vendor == ServerVendor.SPRINGBOOT) {
        return;
    }
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    // 定义一个类里面的hook变量并初始化,防止每次拦截write时都初始化对象
    dpInstall.defineField("uavLogHook", LogIT.class, "ch.qos.logback.core.encoder.LayoutWrappingEncoder", "new LogIT()");
    dpInstall.installProxy("ch.qos.logback.core.encoder.LayoutWrappingEncoder", new String[] { "com.creditease.uav.log.hook.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("convertToBytes".equals(m.getName())) {
                m.insertBefore("{$1=uavLogHook.formatLog($1);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 12 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class WebServiceListener method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid, String contextPath) {
    // like SMS, which uses the sun jax-ws RI/Metro-jax-ws RI bind webservices when the servlet starts should
    // profile in ComponentProfileHandler
    FastClasspathScanner fcs = new FastClasspathScanner(new ClassLoader[] { webapploader });
    fcs.scan();
    List<String> endPoints = fcs.getNamesOfDirectSubclassesOf("javax.xml.ws.Endpoint");
    if (!endPoints.isEmpty()) {
        dpInstall.setTargetClassLoader(webapploader);
        for (int i = 0; i < endPoints.size(); i++) {
            dpInstall.installProxy(endPoints.get(i), new String[] { "com.creditease.uav.monitorframework.webservice.interceptors" }, new DynamicProxyProcessor() {

                @Override
                public void process(DPMethod m) throws Exception {
                    if ("publish".equals(m.getName()) && m.getParameterTypes().length > 0 && m.getParameterTypes()[0].getSimpleName().equals("String")) {
                        dpInstall.defineLocalVal(m, "mObj", WebServiceListenerIT.class);
                        m.insertBefore("{mObj=new WebServiceListenerIT(\"" + appid + "\");mObj.obtainWsInfo($1,getImplementor());}");
                    }
                }
            }, false);
        }
        // release loader
        dpInstall.releaseTargetClassLoader();
    }
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) WebServiceListenerIT(com.creditease.uav.monitorframework.webservice.interceptors.WebServiceListenerIT)

Example 13 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod 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)

Example 14 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class HttpClientHookProxy method doInstallDProxy.

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

        @Override
        public void process(DPMethod m) throws Exception {
            if ("execute".equals(m.getName())) {
                if (m.getParameterTypes().length == 3 && m.getReturnType().getSimpleName().equals("HttpResponse")) {
                    m.insertBefore("{ApacheHttpClientIT.start(\"" + appid + "\",new Object[]{$1,$2,$3});}");
                    m.insertAfter("{ApacheHttpClientIT.end(new Object[]{$_});}");
                    dpInstall.addCatch(m, "ApacheHttpClientIT.end(new Object[]{$e});");
                }
            }
        }
    }, false);
    /**
     * install proxy to InternalHttpClient after 4.3
     */
    dpInstall.installProxy("org.apache.http.impl.client.InternalHttpClient", new String[] { "com.creditease.uav.hook.httpclients.sync.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("doExecute".equals(m.getName())) {
                m.insertBefore("{ApacheHttpClientIT.start(\"" + appid + "\",new Object[]{$1,$2,$3});}");
                m.insertAfter("{ApacheHttpClientIT.end(new Object[]{$_});}");
                dpInstall.addCatch(m, "ApacheHttpClientIT.end(new Object[]{$e});");
            }
        }
    }, false);
    /**
     * install proxy to MinimalHttpClient after 4.3
     */
    dpInstall.installProxy("org.apache.http.impl.client.MinimalHttpClient", new String[] { "com.creditease.uav.hook.httpclients.sync.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("doExecute".equals(m.getName())) {
                m.insertBefore("{ApacheHttpClientIT.start(\"" + appid + "\",new Object[]{$1,$2,$3});}");
                m.insertAfter("{ApacheHttpClientIT.end(new Object[]{$_});}");
                dpInstall.addCatch(m, "ApacheHttpClientIT.end(new Object[]{$e});");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 15 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class HttpClient3HookProxy method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * install proxy to httpclient 3.x
     */
    dpInstall.installProxy("org.apache.commons.httpclient.HttpClient", new String[] { "com.creditease.uav.hook.httpclients3.sync.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("executeMethod".equals(m.getName()) && m.getParameterTypes().length == 3) {
                m.insertBefore("{ApacheHttpClient3IT.start(\"" + appid + "\",new Object[]{$1,$2,$3});}");
                m.insertAfter("{ApacheHttpClient3IT.end(new Object[]{$2});}");
                dpInstall.addCatch(m, "ApacheHttpClient3IT.end(new Object[]{$e});");
            }
        }
    }, false);
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Aggregations

DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)21 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)20 JdbcDriverIT (com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)4 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)3 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)2 DubboIT (com.creditease.uav.hook.dubbo.interceptors.DubboIT)1 ApacheAsyncHttpClientIT (com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT)1 JaxWSHookIT (com.creditease.uav.hook.jaxws.interceptors.JaxWSHookIT)1 DBCPIT (com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)1 MybatisIT (com.creditease.uav.hook.jdbc.pools.mybatis.interceptors.MybatisIT)1 MongoClientIT (com.creditease.uav.hook.mongoclients.interceptors.MongoClientIT)1 RabbitmqIT (com.creditease.uav.hook.rabbitmq.interceptors.RabbitmqIT)1 AredisCommandObjectIT (com.creditease.uav.hook.redis.aredis.interceptors.AredisCommandObjectIT)1 DPClass (com.creditease.uav.monitorframework.dproxy.bytecode.DPClass)1 WebServiceListenerIT (com.creditease.uav.monitorframework.webservice.interceptors.WebServiceListenerIT)1 FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)1