Search in sources :

Example 26 with InterceptSupport

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

the class TomcatPlusIT method onResourceInit.

/**
 * on Resource Init
 *
 * @param args
 */
public void onResourceInit(Object... args) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        /**
         * after tomcat8, tomcat use ParallelWebappClassLoader instead of WebappClassLoader as it's webapp's
         * classloader, both of them are extends WebappClassLoaderBase
         */
        Class<?> cls = cl.loadClass("org.apache.catalina.loader.WebappClassLoaderBase");
        if (!cls.isAssignableFrom(cl.getClass())) {
            return;
        }
    } catch (ClassNotFoundException e) {
        /**
         * before tomcat7.0.64(include), WebappClassLoaderBase doesn't exist
         */
        if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
            return;
        }
    }
    /**
     * for Application Starting's Resource Init
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    if (context == null) {
        return;
    }
    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);
    if (sc == null) {
        return;
    }
    context.put(InterceptConstants.WEBAPPLOADER, sc.getLoader().getClassLoader());
    context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
    context.put(InterceptConstants.CONTEXTPATH, ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true));
    context.put(InterceptConstants.APPNAME, ReflectionHelper.getField(StandardContext.class, sc, "displayName", true));
    ServletContext sContext = (ServletContext) ReflectionHelper.getField(StandardContext.class, sc, "context", true);
    context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
    getBasePath(context, sContext);
    iSupport.doIntercept(context);
    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_INIT);
    ic.put(InterceptConstants.CONTEXTOBJ, sc);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) WebappClassLoader(org.apache.catalina.loader.WebappClassLoader) ServletContext(javax.servlet.ServletContext)

Example 27 with InterceptSupport

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

the class TomcatPlusIT method onAppInit.

/**
 * onAppInit
 *
 * @param args
 */
public void onAppInit(Object... args) {
    StandardContext sc = (StandardContext) 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 : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext)

Example 28 with InterceptSupport

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

the class GlobalFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    InterceptSupport iSupport = InterceptSupport.instance();
    /**
     * Step 1: request
     */
    InterceptContext context = iSupport.createInterceptContext(Event.GLOBAL_FILTER_REQUEST);
    context.put(InterceptConstants.HTTPREQUEST, request);
    context.put(InterceptConstants.HTTPRESPONSE, response);
    context.put(InterceptConstants.FILTERCHAIN, chain);
    iSupport.doIntercept(context);
    // NOTE: get the response, it is a chance for global filter handler to replace response object
    HttpServletResponse tmpResponse = (HttpServletResponse) context.get(InterceptConstants.HTTPRESPONSE);
    // NOTE: get the request, it is a chance for global filter handler to replace request object
    HttpServletRequest tmpRequest = (HttpServletRequest) context.get(InterceptConstants.HTTPREQUEST);
    /**
     * check if get the stop request token,if yes then stop the request
     */
    Object token = context.get(InterceptConstants.STOPREQUEST);
    if (token == null) {
        /**
         * Step 2: run service
         */
        try {
            chain.doFilter(tmpRequest, tmpResponse);
        } catch (Throwable e) {
            inteceptResponse(iSupport, context);
            throw new RuntimeException(e);
        }
    }
    /**
     * Step 3: response
     */
    inteceptResponse(iSupport, context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 29 with InterceptSupport

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

the class InterceptFrameworkSupportor method start.

@Override
public void start() {
    String listenersString = System.getProperty("com.creditease.uav.interceptlisteners");
    if (null == listenersString) {
        return;
    }
    String[] defaultListeners = listenersString.split(",");
    // Step 1: install intercept listeners
    InterceptSupport is = InterceptSupport.instance();
    for (String listenerClass : defaultListeners) {
        InterceptEventListener listener = is.createInterceptEventListener(listenerClass);
        if (listener != null) {
            if (this.logger.isLogEnabled()) {
                this.logger.info("InterceptEventListener[" + listenerClass + "] load SUCCESS");
            }
            is.addEventListener(listener);
        }
    }
    // Step 2: register UAVServerController
    ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    GlobalFilterDispatchListener listener = (GlobalFilterDispatchListener) InterceptSupport.instance().getEventListener(GlobalFilterDispatchListener.class);
    // MSCP
    if (vendor == ServerVendor.MSCP) {
    // TODO
    } else // JEE
    {
        listener.registerHandler(new UAVServerJEEController("UAVServerJEEController"));
    }
    // init MonitorUrlFilterMgr
    MonitorUrlFilterMgr.getInstance().init();
}
Also used : InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) GlobalFilterDispatchListener(com.creditease.uav.appserver.listeners.GlobalFilterDispatchListener) UAVServerJEEController(com.creditease.monitor.globalfilter.jee.UAVServerJEEController) InterceptEventListener(com.creditease.monitor.interceptframework.spi.InterceptEventListener)

Example 30 with InterceptSupport

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

the class InterceptFrameworkSupportor method stop.

@Override
public void stop() {
    InterceptSupport is = InterceptSupport.instance();
    is.clearListeners();
    super.stop();
}
Also used : InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport)

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