Search in sources :

Example 1 with JdbcDriverIT

use of com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT in project uavstack by uavorg.

the class JdbcHookProxy method injectDBCP2.

/**
 * inject DBCP2
 *
 * NOTE: DBCP is default injected by injectDriverManager
 *
 * @param webapploader
 * @param ic
 */
private void injectDBCP2(ClassLoader webapploader, InterceptContext ic) {
    try {
        webapploader.loadClass("org.apache.commons.dbcp2.Constants");
    } catch (ClassNotFoundException e) {
        return;
    }
    if (isHookEventDone("isInjectDBCP2")) {
        return;
    }
    final String appid = this.getAppID(ic);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject DBCP2 BasicDataSource
     */
    dpInstall.installProxy("org.apache.commons.dbcp2.DriverConnectionFactory", new String[] { "com.creditease.uav.hook.jdbc.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("createConnection".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", JdbcDriverIT.class);
                m.insertBefore("{mObj=new JdbcDriverIT(\"" + appid + "\");mObj.setJDBCUrlByObjField(this,\"_connectUri\");}");
                m.insertAfter("{$_=mObj.doProxyConnection($_);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 2 with JdbcDriverIT

use of com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT in project uavstack by uavorg.

the class JdbcHookProxy method injectDriverManager.

/**
 * inject DriverManager
 *
 * @param webapploader
 * @param appid
 * @return
 */
private void injectDriverManager(ClassLoader webapploader, InterceptContext ic) {
    if (isHookEventDone("isInjectDrvMgr")) {
        return;
    }
    JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));
    jdbcDriverIT.initSomeDrivers(webapploader);
    Enumeration<Driver> eu = DriverManager.getDrivers();
    while (eu.hasMoreElements()) {
        Driver dr = eu.nextElement();
        jdbcDriverIT.doRegisterDriver(dr, true);
    }
}
Also used : Driver(java.sql.Driver) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 3 with JdbcDriverIT

use of com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT in project uavstack by uavorg.

the class JdbcHookProxy method injectHikari.

/**
 * inject Hikari
 *
 * @param webapploader
 * @param ic
 */
private void injectHikari(ClassLoader webapploader, InterceptContext ic) {
    try {
        webapploader.loadClass("com.zaxxer.hikari.HikariConfigMXBean");
    } catch (ClassNotFoundException e) {
        return;
    }
    if (isHookEventDone("isInjectHikari")) {
        return;
    }
    final String appid = this.getAppID(ic);
    final String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject DBCP2 BasicDataSource
     */
    dpInstall.installProxy("com.zaxxer.hikari.HikariDataSource", new String[] { "com.creditease.uav.hook.jdbc.interceptors", "com.creditease.uav.hook.jdbc.pools.hikari.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("getConnection".equals(m.getName()) && (m.getParameterTypes() == null || m.getParameterTypes().length == 0)) {
                dpInstall.defineLocalVal(m, "mObj", JdbcDriverIT.class);
                // dpInstall.defineLocalVal(m, "mObj2", HikariIT.class);
                m.insertBefore("{mObj=new JdbcDriverIT(\"" + appid + "\");mObj.setJDBCUrl(this.getJdbcUrl());new HikariIT(\"" + contextPath + "\",this);}");
                m.insertAfter("{$_=mObj.doProxyConnection($_);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 4 with JdbcDriverIT

use of com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT in project uavstack by uavorg.

the class JdbcHookProxy method injectTomcatDBCP2.

/**
 * inject TomcatDBCP2
 *
 * @param webapploader
 * @param ic
 */
private void injectTomcatDBCP2(ClassLoader webapploader, InterceptContext ic) {
    try {
        webapploader.loadClass("org.apache.tomcat.dbcp.dbcp2.Constants");
    } catch (ClassNotFoundException e) {
        return;
    }
    if (isHookEventDone("isInjectTomcatDBCP2")) {
        return;
    }
    final String appid = this.getAppID(ic);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject Tomcat DBCP2 BasicDataSource
     */
    dpInstall.installProxy("org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory", new String[] { "com.creditease.uav.hook.jdbc.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("createConnection".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", JdbcDriverIT.class);
                m.insertBefore("{mObj=new JdbcDriverIT(\"" + appid + "\");mObj.setJDBCUrlByObjField(this,\"_connectUri\");}");
                m.insertAfter("{$_=mObj.doProxyConnection($_);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 5 with JdbcDriverIT

use of com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT in project uavstack by uavorg.

the class JdbcHookProxy method injectDataSource.

/**
 * inject ApplicationServer DataSource
 *
 * @param webapploader
 * @param appid
 */
private void injectDataSource(InterceptContext ic) {
    Object resObj = ic.get(InterceptConstants.RESOURCEOBJ);
    Object resCfgObj = ic.get(InterceptConstants.RESOURCECFG);
    if (resObj == null || resCfgObj == null) {
        return;
    }
    if (isHookEventDone("isInjectDataSource")) {
        return;
    }
    JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));
    ServerVendor vendor = (ServerVendor) this.getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    /**
     * NOTE: Tomcat use ResourceFactory to get DataSource Object, then we can get the url from config (Reference)
     * Diff AppServer the behavior may be not the same. SpringBoot default uses Tomcat as its default app server
     */
    if (vendor == ServerVendor.TOMCAT || vendor == ServerVendor.SPRINGBOOT) {
        Object dsProxy = jdbcDriverIT.doProxyDataSource(resObj, resCfgObj, "Tomcat");
        ic.put(InterceptConstants.RESOURCEOBJ, dsProxy);
    }
}
Also used : ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Aggregations

JdbcDriverIT (com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)6 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)4 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)4 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)1 Driver (java.sql.Driver)1