[Dancer-users] RPC and Exception Handling

Tim King timk at jtimothyking.com
Tue Aug 2 05:41:16 CEST 2011

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.)

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?


More information about the Dancer-users mailing list