Search in sources :

Example 21 with InterceptSupport

use of com.creditease.monitor.interceptframework.InterceptSupport 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 22 with InterceptSupport

use of com.creditease.monitor.interceptframework.InterceptSupport 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 23 with InterceptSupport

use of com.creditease.monitor.interceptframework.InterceptSupport 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 24 with InterceptSupport

use of com.creditease.monitor.interceptframework.InterceptSupport 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 25 with InterceptSupport

use of com.creditease.monitor.interceptframework.InterceptSupport 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

InterceptSupport (com.creditease.monitor.interceptframework.InterceptSupport)30 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)28 ServletContext (javax.servlet.ServletContext)12 StandardContext (org.apache.catalina.core.StandardContext)12 Servlet (javax.servlet.Servlet)6 StandardWrapper (org.apache.catalina.core.StandardWrapper)4 WebappClassLoader (org.apache.catalina.loader.WebappClassLoader)4 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)3 IConfigurationManager (com.creditease.agent.spi.IConfigurationManager)2 ServletException (javax.servlet.ServletException)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)1 UAVServerJEEController (com.creditease.monitor.globalfilter.jee.UAVServerJEEController)1 InterceptEventListener (com.creditease.monitor.interceptframework.spi.InterceptEventListener)1 TomcatLog (com.creditease.tomcat.plus.util.TomcatLog)1 GlobalFilterDispatchListener (com.creditease.uav.appserver.listeners.GlobalFilterDispatchListener)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 App (org.eclipse.jetty.deploy.App)1