Here is the method:
public static boolean startModule(Module mod, ServletContext servletContext, boolean delayContextRefresh)
Here is the method call in a java file:
WebModuleUtil.startModule(module, getServletContext(), false);
I cannot make any changes to these files, but I want to intercept the method and add some of my code (I want access to the parameters as well)
Code I wrote in another java file but not successful:
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() {
// TODO Auto-generated method stub
return null;
}