The web service returns a complete, correct answer, but the source of the response is empty

I use the send client to access the web service. All my parameters are correct, there are no errors and, examining the answer with Wireshark, I definitely see that the correct answer is received at the network level. But at the java application level, my answer source is empty.

public void testDispatch(QName serviceName, QName portName, String endpointAddress, 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 converting to DOMResult, the same, empty root root node. Any ideas?

+3
source share
2 answers

I would call the service using the Proxy API and then compare Soap messages.

There may be a difference in namespaces that prevents JAXB from untying correctly.

0
source

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());
0
source

Source: https://habr.com/ru/post/1743939/


All Articles