Here is a way:
public static boolean startModule(Module mod, ServletContext servletContext, boolean delayContextRefresh)
Here is the method call in the java file:
WebModuleUtil.startModule(module, getServletContext(), false);
I cannot make any changes to these files, but I want to intercept the method and add part of my code (I also want to access the parameters)
Code that I wrote in another java file, but not successfully:
public void main(String[] args) throws Exception {
Module module = null;
WebModuleUtil wmb = new WebModuleUtil();
ProxyFactory pf = new ProxyFactory(wmb);
pf.addAdvice(new MethodInterceptor() {
public Object invoke(MethodInvocation invocation) throws Throwable {
if (invocation.getMethod().getName().startsWith("start")) {
System.out.println("method " + invocation.getMethod() + " is called on " + invocation.getThis()
+ " with args " + invocation.getArguments());
System.out.println("********************");
Object ret = invocation.proceed();
System.out.println("method " + invocation.getMethod() + " returns " + ret);
return ret;
}
return null;
}
});
WebModuleUtil proxy = (WebModuleUtil) pf.getProxy();
proxy.startModule(module, getServletContext(), false);
}
private static ServletContext getServletContext() {
return null;
}
source
share