SOAP response body has plain text without any nodes

How to handle a SOAP response as shown below?

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:new="http://foo/bar"> <S:Header/> <S:Body>OK</S:Body> </S:Envelope> 

here are my definitions in WSDL:

 <wsdl:operation name="MyRequest"> <wsdl:input message="tns:MyRequest" name="MyRequest"> </wsdl:input> <wsdl:output message="tns:MyRequestResponse" name="MyRequestResponse"> </wsdl:output> </wsdl:operation> <xs:element name="MyRequestResponse" type="xs:string"/> 

Services:

  @WebMethod(operationName = "MyRequest") @WebResult(name = "MyRequestResponse", targetNamespace = "http://foo/bar", partName = "parameters") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) public String MyRequest( @WebParam(name = "MyRequest", targetNamespace = "http://foo/bar", partName = "parameters") MyRequest parameters); 

I tried using an interceptor and wrap the answer "OK" with the nodes. But, I wonder if there is any cleaner way to do this by working in the JAXB / WSDL layer itself.

+5
source share
2 answers

This is an invalid SOAP 1.1 Body item as per specification. Thus, this is, in fact, not a SOAP response.

Since this is not a valid SOAP response, and you are not sending any complex parameters, there is really little point in trying to call such a service using the SOAP structure.

It will make sense to consider it as a simple HTTP service with a proprietary format. Send an HTTP POST request and extract the “OK” part inside the body from the response. If the namespace prefix is ​​not changed, you can do this even without XML parsing.

Despite the fact that it looks like a “hacked” one, this is a much cleaner and more convenient approach than using non-obvious interceptors and an obscure setting to crack the frame and force it to do something outside the specification. Anyone who follows you through code research will have to spend time understanding all the mechanisms involved in processing this one-eyed SOAP.

If, however, sometimes there is an admissible complex SOAP body that meets the specification, and sometimes there is invalid arbitrary content such as OK, overriding the SOAP analysis is not justified, and interceptors are the way to put invalid messages on the line with the specification. In the mixed case, I believe that there is no simple, easy way to match using the SOAP / WSDL specification unless the messages are pre-processed and fixed by interceptors.

+3
source

If you look here , you can see the basic XSD format for the SOAP envelope. Therefore, if you take the string “OK” and add it to the string element in the body, which is a string tag, then you should be fine.

 <xs:element name="message" type="xs:string"/> 

As for XML:

 <message>OK</message> 

Your XML is currently invalid. Elements in the body and header must have a data type.

0
source

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


All Articles