我应该如何在服务器端使用 Apache XML-RPC 的 TypeConvertorFactory ?
我正在努力让 Apache XML-RPC 调用我的 TypeConvertorFactory。它在客户端调用它(到目前为止仅返回确认有效的值,尚未测试参数),但服务器端根本不调用它。
我的初始化代码如下所示:
XmlRpcServlet servlet = new XmlRpcServlet();
XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl();
config.setEnabledForExtensions(true);
servlet.getXmlRpcServletServer().setConfig(config);
servlet.getXmlRpcServletServer().setTypeConverterFactory(
new ServerTypeConvertorFactory());
API 如下所示:
private interface API {
AvailableLicencesResponse availableLicences();
}
AvailableLicencesResponse 只是一个普通的、无聊的、尽管深度嵌套的 JavaBean。
目前,服务器以 Base64 形式发送此响应(这是有效的,因为我调用了 setEnabledForExtensions(true)
- 但如果我不调用它,我会收到“意外的流结束”类型错误,没有任何其他错误告诉我原因。)
我在 ServerTypeConvertorFactory 中设置了断点,并且似乎没有在服务器上调用任何方法。相同的断点显示,当服务器传回结果时,客户端调用 Convert() ,但由于序列化魔法,结果已经是正确的类型,因此我不需要转换它。
本质上,我想做的是实现一个符合标准 XML-RPC 的有线协议(并且不使用大量的 Base64 数据...),同时仍然拥有一个不需要一千次转换的 API,调用 Map.get()。我还想避免进行不必要的调用,这就是为什么我返回一个 bean,而不是使用单独的方法来获取它的每个属性,这也可以工作。
(另外,如果有比这个更容易使用的 API,我愿意接受建议。一开始它非常简单,但直到您需要自定义它为止。此外,任何建议 Axis 或其他基于 SOAP 的 API 的人都会黎明时分被枪杀。)
I am struggling to get Apache XML-RPC to call my TypeConvertorFactory at all. It is calling it on the client side (only return values confirmed to work so far, haven't tested parameters) but the server side isn't calling it at all.
My initialisation code looks like this:
XmlRpcServlet servlet = new XmlRpcServlet();
XmlRpcServerConfigImpl config = new XmlRpcServerConfigImpl();
config.setEnabledForExtensions(true);
servlet.getXmlRpcServletServer().setConfig(config);
servlet.getXmlRpcServletServer().setTypeConverterFactory(
new ServerTypeConvertorFactory());
The API looks like this:
private interface API {
AvailableLicencesResponse availableLicences();
}
AvailableLicencesResponse is just an ordinary boring, albeit deeply nested JavaBean.
At the moment, the server sends this response as Base64 (this works because I called setEnabledForExtensions(true)
- but if I don't call that, I get "unexpected end of stream" type errors instead, with no additional error anywhere to tell me why.)
I have set breakpoints inside ServerTypeConvertorFactory and it seems that none of the methods are being called on the server. The same breakpoints show the client calling convert() when the server hands back the result, but the result is already the correct type due to serialisation magic so I don't need to convert it.
Essentially, what I am trying to do is to implement a wire protocol which conforms to standard XML-RPC (and doesn't use huge amounts of Base64 data...) while still having an API which doesn't require a thousand casts and calls to Map.get(). I also want to avoid having to make more calls than necessary, which is why I'm returning a bean instead of having separate methods to get each property of it, which would have worked too.
(Also, if there is a simpler to use API than this one, I'm open for suggestions. It started out being really easy, but that's until you need to customise it. Also, anyone suggesting Axis or other SOAP-based APIs will be shot at dawn.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论