Search in sources :

Example 46 with InterceptContext

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

the class SpringBootTomcatPlusIT method onSpringBeanRegist.

/**
 * springboot load beans before web container start, hook opr should be done before beanRegist in case of duplicate
 * definition ,so we define SPRING_BEAN_REGIST event to trigger hook
 */
public void onSpringBeanRegist(Object... args) {
    if (!isWebServerContext(args[0])) {
        return;
    }
    String contextPath = (String) args[1];
    if (contextPath == null || "/".equals(contextPath)) {
        contextPath = "";
    }
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.SPRING_BEAN_REGIST);
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
    context.put(InterceptConstants.CONTEXTPATH, contextPath);
    context.put(InterceptConstants.BASEPATH, "");
    iSupport.doIntercept(context);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport)

Example 47 with InterceptContext

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

the class SpringBootTomcatPlusIT method onServletStop.

/**
 * onServletStop
 *
 * @param args
 */
@Override
public void onServletStop(Object... args) {
    StandardWrapper sw = (StandardWrapper) args[0];
    Servlet servlet = (Servlet) args[1];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.BEFORE_SERVLET_DESTROY);
    context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
    /**
     * NOTE: spring boot rewrite the tomcat webappclassloader, makes the addURL for nothing, then we can't do
     * anything on this we may use its webappclassloader's parent as the classloader
     */
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader().getParent());
    context.put(InterceptConstants.CONTEXTPATH, sw.getServletContext().getContextPath());
    iSupport.doIntercept(context);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) Servlet(javax.servlet.Servlet) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Example 48 with InterceptContext

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

the class SpringBootTomcatPlusIT method startServer.

/**
 * startUAVServer
 */
public void startServer(String port, String contextPath, String appName, Object arg) {
    if (!isWebServerContext(arg)) {
        return;
    }
    // integrate Tomcat log
    UAVServer.instance().setLog(new TomcatLog("MonitorServer"));
    // start Monitor Server when server starts
    UAVServer.instance().start(new Object[] { UAVServer.ServerVendor.SPRINGBOOT });
    // set appid
    setAppid(contextPath);
    // set the connector port
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_LISTEN_PORT, DataConvertHelper.toInt(port, 8080));
    InterceptSupport iSupport = InterceptSupport.instance();
    // this context will be transmited from springboot mainThread to webcontainerInit thread then back to mainThread
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_STARTED);
    context.put(InterceptConstants.APPNAME, appName);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) TomcatLog(com.creditease.tomcat.plus.util.TomcatLog)

Example 49 with InterceptContext

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

the class SpringBootTomcatPlusIT method onServletStart.

/**
 * onServletStart
 *
 * @param args
 */
@Override
public void onServletStart(Object... args) {
    StandardWrapper sw = (StandardWrapper) args[0];
    Servlet servlet = (Servlet) args[1];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.AFTER_SERVET_INIT);
    context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
    /**
     * NOTE: spring boot rewrite the tomcat webappclassloader, makes the addURL for nothing, then we can't do
     * anything on this we may use its webappclassloader's parent as the classloader
     */
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader().getParent());
    context.put(InterceptConstants.CONTEXTPATH, sw.getServletContext().getContextPath());
    iSupport.doIntercept(context);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) Servlet(javax.servlet.Servlet) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Example 50 with InterceptContext

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

the class TomcatPlusIT method onServletStart.

/**
 * onServletStart
 *
 * @param args
 */
public void onServletStart(Object... args) {
    StandardWrapper sw = (StandardWrapper) args[0];
    Servlet servlet = (Servlet) args[1];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.AFTER_SERVET_INIT);
    context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
    context.put(InterceptConstants.CONTEXTPATH, sw.getServletContext().getContextPath());
    iSupport.doIntercept(context);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) Servlet(javax.servlet.Servlet) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Aggregations

InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)61 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 HashMap (java.util.HashMap)3 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)3 IConfigurationManager (com.creditease.agent.spi.IConfigurationManager)2 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)2 WebServiceProfileInfo (com.creditease.uav.profiling.handlers.webservice.WebServiceProfileInfo)2