Search in sources :

Example 6 with InterceptSupport

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

the class TomcatPlusIT method onAppStarting.

/**
 * onAppStarting
 *
 * @param args
 */
public void onAppStarting(Object... args) {
    // release the left contexts
    StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_INIT);
    StandardInterceptContextHelper.releaseContext(Event.WEBCONTAINER_RESOURCE_CREATE);
    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
    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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 7 with InterceptSupport

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

the class TomcatPlusIT method onAppStart.

/**
 * onAppStart
 *
 * @param args
 */
public void onAppStart(Object... args) {
    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STARTED);
    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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 8 with InterceptSupport

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

the class TomcatPlusIT method onResourceCreate.

/**
 * on Resource Create
 */
public Object onResourceCreate(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 args[0];
        }
    } catch (ClassNotFoundException e) {
        /**
         * before tomcat7.0.64(include), WebappClassLoaderBase doesn't exist
         */
        if (!WebappClassLoader.class.isAssignableFrom(cl.getClass())) {
            return args[0];
        }
    }
    /**
     * for Application Starting's Resource Create
     */
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE, false);
    if (context == null) {
        return args[0];
    }
    StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);
    if (sc == null) {
        return args[0];
    }
    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);
    context.put(InterceptConstants.RESOURCEOBJ, args[0]);
    context.put(InterceptConstants.RESOURCECFG, args[1]);
    iSupport.doIntercept(context);
    InterceptContext ic = iSupport.getThreadLocalContext(Event.WEBCONTAINER_RESOURCE_CREATE);
    ic.put(InterceptConstants.CONTEXTOBJ, sc);
    return context.get(InterceptConstants.RESOURCEOBJ);
}
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 9 with InterceptSupport

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

the class TomcatPlusIT method onAppStop.

/**
 * onAppStop
 *
 * @param args
 */
public void onAppStop(Object... args) {
    StandardContext sc = (StandardContext) args[0];
    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_STOPPED);
    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);
}
Also used : InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) InterceptSupport(com.creditease.monitor.interceptframework.InterceptSupport) StandardContext(org.apache.catalina.core.StandardContext) ServletContext(javax.servlet.ServletContext)

Example 10 with InterceptSupport

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

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