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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations