You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Fabio Mancinelli <fa...@gmail.com> on 2008/04/30 13:01:11 UTC

Intercepting calls to the handler

Dear all,

Probably I have a simple problem but I cannot find the solution.
I have my XMLRPC backend running fine on a web application through a servlet.

Now what I would like to do is to wrap each method call into a
try/catch/finally because of some initialization/cleanup that I need
to perform at every method call.

So I was wondering if there was a clean way for replacing the
RelfectiveXmlRpcHandler and its execute method (that as far as I
understand is the place where the invocation occurs) so that I can do
something like:

class MyReflectiveXmlRpcHandler extends ReflectiveXmlRpcHandler {
 ...
 Object execute(XmlRpcRequest request) throws XmlRpcException {
    try {
      //My setup here
      super.execute(request)
    }
    catch(XmlRpcException e) {
      throw e;
    }
    finally {
      //My cleanup
    }
  }
}

Where and how should I register this extended ReflectiveXmlRpcHandler?
Is there a code snippet for such a use case?

Thank you for your help.

Cheers,
Fabio

Re: Intercepting calls to the handler

Posted by "Fabio M." <fa...@gmail.com>.

Fabio M. wrote:
> 
> ...
> Where and how should I register this extended ReflectiveXmlRpcHandler?
> Is there a code snippet for such a use case?
> 

I reply to myself because I've find a way. Basically I redefined the
newXmlRpcHandler method in the PropertyHandlerMapping. The implementation is
basically the same, but instead of returning RelfectiveXmlRpcHandler and
ReflectiveXmlRpcMetaDataHandler (that are hard-coded in the original
implementation) I return custom subclasses of the twos.

The subclass of ReflectiveXmlRpcHandler overrides the execute method where I
perform my "setup" logic and then I invoke the acutal method by simply
delegating to the superclass.

The subclass of ReflectiveXmlRpcMetaDataHandler is basically a copy of the
original one that extends my custom subclass of ReflectiveXmlRpcHandler.

Everything works, but I have a question: is it this a correct way for
implementing what I described?

Thank you for your help.

Cheers,
Fabio
-- 
View this message in context: http://www.nabble.com/Intercepting-calls-to-the-handler-tp16980113p16987013.html
Sent from the Apache Xml-RPC - Dev mailing list archive at Nabble.com.