Hello,
I have an Apache Wink customization that I would like to implement for my
client that I wanted to check for approval within the Apache Wink community. My
worry is I am touching objects I should not be touching. I have a need (that is
fairly difficult to explain) to execute a method within my resource handler
before the method that serves the request. Below I have shown a very simple
sample. I have created a RequestHandler that modifies the reflectionMethod of
the SearchResult and sets it back at the end of the request.
I would greatly appreciate if anyone had a thought about the customization and
would advice me do something else. The code I want to execute must be within my
resource handler as I have below because all my resource handlers must extend
an abstract class, and the code I need to execute is a method within that
abstract class. The Resource Handler must also be fully instantiated because
the code in my clients method uses the objects populated by the MessageContext.
****
I just realized as I was typing this email that I don’t believe I can do this
because I am going to have concurrency issues when another identical request
comes in before this request finishes…...
***
Thanks in advance!
My Resource Handler and my Request Handler code below:
public abstract class MyAbstractResourceHandler extends
MyClientsAbstractResourceHandler{
@Context
protected InterceptingContext interceptingContext = null;
public Object doInterception(){
super.doSomething();
return
interceptingContext.getMethod().invoke(interceptingContext.getInvocationParams());
}
}
@Override
public void handleRequest(MessageContext messageContext, HandlersChain
handlersChain) throws Throwable {
SearchResult searchResult =
messageContext.getAttribute(SearchResult.class);
MethodMetadata methodMetaData =
searchResult.getMethod().getMetadata();
Method javaMethod = methodMetaData.getReflectionMethod();
try{
Object[] parameters =
searchResult.getInvocationParameters();
InterceptingContext interceptingContext = new
InterceptingContextImpl(javaMethod, parameters);
messageContext.setAttribute(InterceptingContext,
interceptingContext);
Method interceptingMethod =
MyAbstractResourceHandler.class.getMethod(“doInterception”);
searchResult.getMethod().getMetadata().setReflectionMethod(interceptingMethod);
searchResult.setInvocationParameters(new Object[]{});
handlersChain.doChain(messageContext);
}
finally{
methodMetaData.setReflectionMethod(javaMethod);
}
}
Thanks!!!!