I am using a dispatch client to access a web service. All my params are correct, there are no errors and, examining the response with Wireshark, I can definitely see that the correct response is received at the network layer. But at the java application layer, my response Source is empty.
public void testDispatch(QName serviceName, QName portName, String endp开发者_JAVA百科ointAddress, String action) throws Exception {
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
String requestXml = buildRequestXml();
Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, action);
Source request = new StreamSource(new StringReader(requestXml));
Source response = dispatch.invoke(request);
Transformer copier = TransformerFactory.newInstance().newTransformer();
copier.transform(response, new StreamResult(System.out));
}
I tried to transform to a DOMResult, same thing, an empty root node. Any ideas?
I would invoke the service with Proxy API, then compare the Soap messages.
There may be a difference in namespaces that prevent JAXB from proper unmarshalling.
My working solution for the problem:
StreamResult xmlOutput = new StreamResult(new StringWriter());
Transformer copier = TransformerFactory.newInstance().newTransformer();
copier.transform(responseStream, xmlOutput);
System.out.println(xmlOutput.getWriter().toString());
精彩评论