Search in sources :

Example 6 with InterceptContext

use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.

the class JettyPlusIT method onAppInit.

/**
 * onAppInit
 *
 * @param args
 */
public void onAppInit(Object... args) {
    App sc = (App) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    InterceptContext ic2 = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);
    /**
     * NOTE: onAppInit, we put the Context Object into threadlocal, then all other later process for
     * PRE_WEBCONTAINER_INIT, which can get the object, as not everywhere we can get the object
     *
     * for example, the DataSource related injection
     */
    ic.put(InterceptConstants.CONTEXTOBJ, sc);
    ic2.put(InterceptConstants.CONTEXTOBJ, sc);
}
Also used : App(org.eclipse.jetty.deploy.App) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport)

Example 7 with InterceptContext

use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.

the class JettyPlusIT method onAppStart.

/**
 * onAppStart
 *
 * @param args
 */
public void onAppStart(Object... args) {
    WebAppContext sc = getWebAppContext(args);
    if (sc == null) {
        return;
    }
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STARTED);
    context.put(InterceptConstants.WEBAPPLOADER, sc.getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getServletContext().getRealPath(""));
    context.put(InterceptConstants.CONTEXTPATH, sc.getContextPath());
    context.put(InterceptConstants.APPNAME, sc.getDisplayName());
    ServletContext sContext = sc.getServletContext();
    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
    getBasePath(context, sContext);
    iSupport.doIntercept(context);
    // GlobalFilter
    sc.addFilter("com.creditease.monitor.jee.filters.GlobalFilter", "/*", EnumSet.of(DispatcherType.REQUEST));
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) ServletContext(javax.servlet.ServletContext)

Example 8 with InterceptContext

use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.

the class MybatisHookProxy method InsertInterceptToClients.

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);
    dpInstall.setTargetClassLoader(webapploader);
    dpInstall.installProxy("org.apache.ibatis.datasource.pooled.PooledDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.mybatis.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", MybatisIT.class);
                m.insertBefore("{mObj=new MybatisIT(\"" + 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) MybatisIT(com.creditease.uav.hook.jdbc.pools.mybatis.interceptors.MybatisIT)

Example 9 with InterceptContext

use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.

the class RabbitmqHookProxy method InsertInterceptToClients.

public 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);
    final String appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
    doInstallDProxy(webapploader, appid);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext)

Example 10 with InterceptContext

use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.

the class ComponentProfileHandler method getDynInfoForWebService.

@SuppressWarnings("unchecked")
private void getDynInfoForWebService(String componentClassName, ProfileElementInstance inst, ProfileContext context, Map<String, Class<?>> annoAvailableClasses, FastClasspathScanner fcs) {
    if (!componentClassName.equals("javax.jws.WebService")) {
        return;
    }
    Class<?> annoClass = annoAvailableClasses.get(componentClassName);
    if (null == annoClass) {
        return;
    }
    List<String> coms = fcs.getNamesOfClassesWithAnnotation(annoClass);
    if (null == coms || coms.isEmpty()) {
        return;
    }
    // construct data "dyn" for webservice
    InterceptContext ic = context.get(InterceptContext.class);
    List<WebServiceProfileInfo> wsli = (ArrayList<WebServiceProfileInfo>) ic.get("webservice.profile.info");
    if (wsli == null || wsli.isEmpty()) {
        return;
    }
    for (WebServiceProfileInfo wslinfo : wsli) {
        String url = wslinfo.getUrl();
        String clazz = (wslinfo.getImpl() instanceof String) ? (String) wslinfo.getImpl() : wslinfo.getImpl().getClass().getName();
        if (coms.contains(clazz)) {
            Map<String, Object> dynInfos = new LinkedHashMap<String, Object>();
            Map<String, Object> info = (Map<String, Object>) inst.getValues().get(clazz);
            dynInfos.put("url", url);
            dynInfos.put("className", clazz);
            info.put("dyn", dynInfos);
            inst.getValues().put(clazz, info);
        }
    }
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) ArrayList(java.util.ArrayList) WebServiceProfileInfo(com.creditease.uav.profiling.handlers.webservice.WebServiceProfileInfo) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)66 InterceptSupport (com.creditease.monitor.interceptframework.InterceptSupport)28 ServletContext (javax.servlet.ServletContext)12 StandardContext (org.apache.catalina.core.StandardContext)12 Servlet (javax.servlet.Servlet)6 ProfileElementInstance (com.creditease.uav.profiling.spi.ProfileElementInstance)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 StandardWrapper (org.apache.catalina.core.StandardWrapper)4 WebappClassLoader (org.apache.catalina.loader.WebappClassLoader)4 UAVServer (com.creditease.monitor.UAVServer)3 Event (com.creditease.monitor.interceptframework.spi.InterceptContext.Event)3 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)3 DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)3 DubboServiceProfileInfo (com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo)3 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ServletException (javax.servlet.ServletException)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)3