如何在 Apache XML-RPC 服务器应用程序中实现自省?

发布于 2024-12-02 12:58:19 字数 1037 浏览 2 评论 0原文

我们有一个 Java 服务器后端,它使用 Apache XML-RPC 来提供其服务PHP 应用程序(不要问我,当我到达时它已经以这种方式构建),并希望它遵守 非官方XML-RPC 自省规范。理论上,Apache XML-RPC 对此支持,但是其页面上给出的示例 :

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

不会编译。它显然缺少 return 语句,并且我尝试返回创建的“映射”,但是在第一个请求时,服务器(递归地?)重复调用 newXmlRpcHandlerMapping()直到抛出java.lang.StackOverflowError

问题是:有谁知道如何向这样的应用程序添加内省功能?要么修复这个例子,要么提供一个可用的例子,那就太棒了。它实际上并不需要是那个规范(任何允许我们生成方法及其参数列表的东西都很好),但它似乎是一个很酷的标准(在其他非-XML-RPC 的酷世界:-) )

谢谢!

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 throwing 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中性美 2024-12-09 12:58:19

感谢同事的提示,我得到了答案:重写方法正在调用自身,而不是超类的版本。这是固定代码:

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

一旦添加该代码并用此版本替换 web.xml 中的 XmlRpcServlet,您就可以调用内省方法!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文