Search in sources :

Example 1 with DBCPIT

use of com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT in project uavstack by uavorg.

the class DBCPHookProxy method InsertInterceptToClients.

/**
 * InsertInterceptToClients
 *
 * @param ic
 */
private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("InsertInterceptToClients")) {
        return;
    }
    InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
    String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
    String basePath = (String) ic.get(InterceptConstants.BASEPATH);
    appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * DBCP 1.x
     */
    dpInstall.installProxy("org.apache.commons.dbcp.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    /**
     * DBCP 2.x
     */
    dpInstall.installProxy("org.apache.commons.dbcp2.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    /**
     * Tomcat DBCP 2.x after 8
     */
    dpInstall.installProxy("org.apache.tomcat.dbcp.dbcp2.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) DBCPIT(com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)

Aggregations

InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)1 DBCPIT (com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)1 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)1 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)1