use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.
the class SpringBootTomcatPlusIT method onResourceCreate.
@Override
public Object onResourceCreate(Object... args) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
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);
StandardContext sc = (StandardContext) context.get(InterceptConstants.CONTEXTOBJ);
/**
* 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, sc.getLoader().getClassLoader().getParent());
context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
String contextPath = (String) ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true);
context.put(InterceptConstants.CONTEXTPATH, contextPath);
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);
String basePath = sContext.getRealPath("");
/*
* NOTE: springboot couldn't get the basePath through method "getRealPath", temporary process
*/
if (basePath == null) {
basePath = "";
} else if (basePath.lastIndexOf("/") == (basePath.length() - 1) || basePath.lastIndexOf("\\") == (basePath.length() - 1)) {
basePath = basePath.substring(0, basePath.length() - 1);
}
context.put(InterceptConstants.BASEPATH, basePath);
context.put(InterceptConstants.RESOURCEOBJ, args[0]);
context.put(InterceptConstants.RESOURCECFG, args[1]);
iSupport.doIntercept(context);
return context.get(InterceptConstants.RESOURCEOBJ);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.
the class SpringBootTomcatPlusIT method onAppStarting.
/**
* onAppStarting
*
* @param args
*/
@Override
public void onAppStarting(Object... args) {
StandardContext sc = (StandardContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
/**
* 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, sc.getLoader().getClassLoader().getParent());
context.put(InterceptConstants.WEBWORKDIR, sc.getWorkPath());
String contextPath = (String) ReflectionHelper.getField(StandardContext.class, sc, "encodedPath", true);
context.put(InterceptConstants.CONTEXTPATH, contextPath);
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);
String basePath = sContext.getRealPath("");
/*
* NOTE: springboot couldn't get the basePath through method "getRealPath", temporary process
*/
if (basePath == null) {
basePath = "";
} else if (basePath.lastIndexOf("/") == (basePath.length() - 1) || basePath.lastIndexOf("\\") == (basePath.length() - 1)) {
basePath = basePath.substring(0, basePath.length() - 1);
}
context.put(InterceptConstants.BASEPATH, basePath);
iSupport.doIntercept(context);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext 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);
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext in project uavstack by uavorg.
the class HttpAsyncClientHookProxy method InsertInterceptToClients.
public void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {
if (isHookEventDone("InsertInterceptToClients")) {
return;
}
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
String basePath = (String) ic.get(InterceptConstants.BASEPATH);
final String appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
doInstallDProxy(webapploader, appid);
}
Aggregations