如何将数据从SOAP处理程序传递回Web服务客户端? [英] How can I pass data back from a SOAP handler to a webservice client?
问题描述
(跟踪此问题:获取原始XML响应来自Java Web服务客户端)
我有一个SOAP消息处理程序,它能够获取Web服务响应的原始XML.我需要将此XML放入Web服务客户端,以便可以在响应发送之前对响应执行一些XSL转换.我在想出一种从SOAP处理程序获取数据的好方法时遇到了麻烦,该SOAP处理程序捕获传入的消息,并使原始XML可用于生成的(从WSDL)Web服务客户端.有什么想法甚至可行吗?
I've got a SOAP message handler that is able to get the raw XML of a web service response. I need to get this XML into the webservice client so I can perform some XSL transformations on the response before sending it on its way. I'm having trouble figuring out a good way to get data from a SOAP handler that catches incoming messages, and makes the raw XML available to a generated (from a WSDL) web service client. Any ideas if this is even feasible?
我想出了类似这样的东西:
I've come up with something like this:
public class CustomSOAPHandler implements javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>
{
private String myXML;
public String getMyXML()
{
return myXML;
}
...
public boolean handleMessage(SOAPMessageContext context)
{
...
myXML = this.getRawXML(context.getMessage());
}
//elsewhere in the application:
...
myService.doSomething(someRequest);
for (Handler h: ((BindingProvider)myService).getBinding().getHandlerChain())
{
if (h instanceof CustomSOAPHandler )
{
System.out.println("HandlerResult: "+ ((CustomSOAPHandler )h).getMyXML());
}
}
在非常简单的测试中,这似乎可行.但是这种解决方案似乎有点便宜.我不喜欢将原始XML设置为链处理程序的成员,而且我有一种直觉,认为这违反了许多其他最佳实践.有人有更优雅的方法吗?
In very simple tests, this seems to work. But this solution feels somewhat like a cheap hack. I don't like setting the raw XML as a member of the chain handler, and I have a gut feeling this violates many other best practices. Does anyone have a more elegant way of doing this?
推荐答案
解决方案是使用JAXB将对象转换回XML.我并不是真的想要这样做,因为让Web服务客户端接收XML,将其转换为POJO,仅将POJO转换回XML似乎是多余的,但是它确实有效.
The solution was to use JAXB to convert the objects back to XML. I didn't really want to do this because it seems redundant to have the webservice client receive XML, convert it to a POJO, only to have that POJO converted back to XML, but it works.
这篇关于如何将数据从SOAP处理程序传递回Web服务客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!