开发者

How to implement introspection in Apache XML-RPC server applications?

We have a Java server back-end that uses Apache XML-RPC to make its services available to PHP apps (don't ask me, it was already built this way when I arrived), and wished it to adhere to the unofficial XML-RPC introspection spec. In theory, Apache XML-RPC has support for that, but the example given on their page:

public class MyXmlRpcServlet extends XmlRpcServlet {
    protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()
        throws XmlRpcException {
        PropertyHandlerMapping mapping =
            (PropertyHandlerMapping) newXmlRpcHandlerMapping();
        XmlRpcSystemImpl.addSystemHandler(mapping);
    }
}

will not compile. It is clearly missing a return statement, and I've tried to return the created 'mapping', but then at the first request the server (recursively?) repeats the call to newXmlRpcHandlerMapping() until thr开发者_运维百科owing a java.lang.StackOverflowError.

Question is: Does anyone know how to add introspection to such an app? Either fixing this example, or providing a working one would be awesome. It doesn't really need to be that spec (anything that would allow us to generate a listing of methods and their parameters would be nice), but it seems to be a cool standard (in the otherwise non-cool world of XML-RPC. :-) )

Thank you!


Thanks to a coworker's tip I got the answer: the overriden method is calling itself, not the superclass' version. Here is the fixed code:

public class MyXmlRpcServlet extends XmlRpcServlet {
    @Override
    protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()
        throws XmlRpcException {
        PropertyHandlerMapping mapping = (PropertyHandlerMapping) super
            .newXmlRpcHandlerMapping();
        XmlRpcSystemImpl.addSystemHandler(mapping);
        return mapping;
}
}

Once you add that and replace XmlRpcServlet in your web.xml with this version, you can call introspection methods!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜