5

How to handle SOAP message response like 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"/>

Service:

 @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 did tried to use interceptor and wrap the response 'OK' with nodes. But, wondering if there is any cleaner way of doing it by handling in JAXB/WSDL layer itself.

jai
  • 21,519
  • 31
  • 89
  • 120
  • Are you trying to produce or consume the OK response? – approxiblue Dec 01 '16 at 05:28
  • I am trying to consume it from Mule ESB. – jai Dec 01 '16 at 05:39
  • This SOAP response is **not valid** according to your WSDL. You should have something like: OK Did you actually use a JAX-WS implementation to generate this response? – cdan Dec 03 '16 at 15:31
  • @Cyril: I don't have control on the response. I am just consuming it. Could you please help on framing the WSDL for the given SOAP response?Thanks. – jai Dec 03 '16 at 15:41
  • Could you show the full original WSDL from the service provider (the one giving you this response) ? Did you generate your client code from it directly? Are you using Apache CXF as JAX-WS implementation for the client (I don't know Mule ESB but from the doc it seems to be CXF)? What error do you get when consuming the response? – cdan Dec 04 '16 at 02:09

2 Answers2

3

This is not a valid SOAP 1.1 Body element according to the specification. So it is, in fact, not a SOAP response.

Because it is not a valid SOAP response and you don't send any complex parameters, it really has little value trying to invoke such a service using a SOAP framework.

It will make more sense to treat it as a plain HTTP service with a proprietary format. Send HTTP POST request and extract the "OK" part inside the body from the response. If the namespace prefix is not expected to change, you can do it even without parsing XML.

Despite looking like a "hack", it is a much more clean and maintainable approach than going with non-obvious interceptors and an obscure setup to hack the framework and force it to do things outside of the specification. Anybody coming after you, examining the code, will have to spend time understanding all the gears behind handling this one-eyed SOAP.

If, however, there IS sometimes a valid complex SOAP body conforming to the spec, and sometimes there is invalid arbitrary content like OK, reimplementing SOAP parsing is not justified and interceptors are the way to go, to bring invalid messages inline with the spec. In the mixed case I think there is no simple clean way to map using the SOAP/WSDL specification, unless messages are pre-processed and fixed by interceptors.

Fedor Losev
  • 3,244
  • 15
  • 13
0

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

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

And as for the XML:

<message>OK</message>

As of now your XML is not valid. Elements in the body and header must have a datatype.

entpnerd
  • 10,049
  • 8
  • 47
  • 68
  • HanuAthena already explained in comments that there is no control over received response. What you wrote here was already proposed two days before. – Fedor Losev Dec 06 '16 at 10:26
  • Ah did not see that - its a comment not an answer. – Nikolaj Hansen Dec 07 '16 at 13:09
  • Anyways - you cannot expect to run a soap endpoint, that accepts invalid xml as an input – Nikolaj Hansen Dec 07 '16 at 13:09
  • Yup, you need either to intercept and correct invalid response before message processing (if there _may be_ complex messages hard to parse) - that is already done - or, if responses are simple, skip SOAP bloatware altogether, use plain HTTP and extract the desired content yourself. – Fedor Losev Dec 07 '16 at 13:19
  • A hack could be to intercept the input with a Servlet Filter and correct the input as per what I wrote above. – Nikolaj Hansen Dec 07 '16 at 13:29
  • 1
    If I understand the question correctly, similar hack is already done, the question was not how to hack but if there is a standard, _cleaner_ way to accomplish that with WSDL. The answer is no (per my knowledge). From the question: "I did tried to use interceptor and wrap the response 'OK' with nodes. But, wondering if there is any cleaner way..." – Fedor Losev Dec 07 '16 at 13:38