use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.
the class TomcatPlusIT method onServletStop.
/**
* onServletStop
*
* @param args
*/
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);
context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
context.put(InterceptConstants.CONTEXTPATH, sw.getServletContext().getContextPath());
iSupport.doIntercept(context);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
Aggregations