[Dancer-users] RPC and Exception Handling
dkrotkine at gmail.com
Tue Aug 2 11:43:04 CEST 2011
Le 2 août 2011 à 05:41, Tim King <timk at jtimothyking.com> a écrit :
> Hi, all.
> We're developing an XML-RPC web service using Dancer, and I thought
> one of you might be able to give us some pointers.
> We thought that developing an XML-RPC serializer would be the right
> approach. The serializer would decode the XML-RPC request and encode
> the XML-RPC response. However, we ran into a couple problems:
> 1. An RPC request contains a method name, as well as the method
> parameters. On deserialization, the RPC serializer would have to
> rewrite the request object, modifying the request path as specified
> by RPC method contained in the request body. However, the Dancer
> serializer API only allows the serializer to set request parameters,
> but not other fields of the request. The only way the serializer can
> modify the request path is to do so as a side-effect, via
> Dancer::SharedData, which strikes me as poor design.
> 2. Certain error conditions in the serializer and in the request
> handler need to be able to generate an RPC fault message. In
> particular, we'd like to be able to throw exceptions and have them
> caught by the infrastructure, which would then convert them to
> appropriate RPC fault messages. But Dancer doesn't seem to have any
> way to catch exceptions thrown from handlers or to insert app-
> specific code into the Dancer call graph. We can't even subclass
> Dancer::Route, for example, and extend it, because Dancer provides
> no way to inject our app-specific classes into Dancer's framework.
> (We were particularly disappointed at this discovery.)
The latest version of Dancer contains Dancer::Exception, it's an
exception handling module dedicated to Dancer.
Using it you can raise system or custom exceptions, and catch it later
and execute dedicated code.
Dancer::Exception is young and suggestions for improvments are
welcome. The Pod should be good enough for you to start raising and
catching custom exceptions. The next release will allow finer catching
of system exceptions as well.
Subclassing and custom code injection is something we will adress
soon. Indeed it's far from being perfect for now.
> So the approach we're working on now is to use an RPC plugin. This
> plugin decodes the RPC request, creates a new request object for the
> RPC method, then calls Dancer::Handler->handle_request() to route it
> to the correct handler. Then it encodes the response back into the
> corresponding RPC response format. The plugin code will also catch
> exceptions that the handlers throw, converting them as appropriate
> into RPC faults.
> Comments? Do you think we're on the right track?
> Dancer-users mailing list
> Dancer-users at perldancer.org
More information about the Dancer-users