0

We are consumng soap service and it was worlking very well when we were using Java 8 and Spring boot 2.X When we are migrating to open Jdk 19 and Spring Boot 3.x which uses Jakarta It has exception when soap fault.

Not able to parse soap fault and some where seen in debug not able to type cast in jakarta.xml.node

Cannot find SOAP wrapper for element [soap:Fault: null]

Here is is our client code

final Marshaller marshaller = webServiceTemplateParam.getMarshaller();

Object ret = webServiceTemplateParam.sendAndReceive(request - > {
    if (requestPayload != null) {

        if (marshaller == null) {
            throw new IllegalStateException("No marshaller registered. Check configuration of WebServiceTemplate.");
        }
        MarshallingUtils.marshal(marshaller, requestPayload, request);

        Assert.isInstanceOf(SoapMessage.class, request);
        SoapMessage soapMessage = (SoapMessage) request;
        soapMessage.setSoapAction(soapAction);

    }
}, new WebServiceMessageExtractor < Object > () {

    @Override
    public Object extractData(final WebServiceMessage response) throws IOException {
        if (unmarshaller == null) {
            throw new IllegalStateException("No unmarshaller registered. Check configuration of WebServiceTemplate.");
        }
        if (hasFault(response)) {
            throw new SoapFaultClientException((SoapMessage) response);
        } else {
            return MarshallingUtils.unmarshal(unmarshaller, response);
        }
    }

    boolean hasFault(final WebServiceMessage response) {
        if (response instanceof FaultAwareWebServiceMessage) {
            FaultAwareWebServiceMessage faultMessage = (FaultAwareWebServiceMessage) response;
            return faultMessage.hasFault();
        }
        return false;
    }
});
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • Apart from your code feeling like you are doing things you shouldn't be doing (generally when seeing code like `WebServiceTemplate.getMarshaller` this means you are doing it wrong). Have you re-generated your classes with JAXB so it has the proper annotations? – M. Deinum Jun 27 '23 at 14:53
  • Thanks for your response , this code is fine if we use dont migrate to jakarta and Jdk 19. While debugging I can see it has error on below line – Jagannath Jha Jun 28 '23 at 10:16
  • We have bean of marsheller that we use to parse response. That is working but it only issue when server retunrs soap fault then it is not able to type cast with (SoapMessage) response , response is WebServiceMessage . Means it is not able to typecast internally with jakarta node perhaps. This might be bug with open jdk – Jagannath Jha Jun 28 '23 at 10:29
  • If you switch to jakarta you need to regenerate your XML classes else they are still using the old annotations. Next to that the marshaller is automatically used, you are basically doing what the `WebServiceTemplate` is already doing (so you are over complicating things). – M. Deinum Jun 28 '23 at 10:56
  • Beacuse it is not throwing soap fault exception with simple way , even tried with interceptor stil hasFault methid is not get called if server throws soapfault. Which XML clases you mean can you please explain.. Thanks – Jagannath Jha Jun 29 '23 at 09:16
  • I strongly get the feeling you have no idea how the frameworks/tools you are using work? The XML classes the classes that are generated from processing the WSDL/XSD you got with the JAXB plugin. That generates classes wit the proper annotations. If you upgrade java and Spring Boot you need to re-generate those as else it will not have the annotations. – M. Deinum Jun 29 '23 at 09:34
  • This is always geneated with new jdk , Ithink you are not looking what problem it is. It is working with success case how then It is working ? if server responding with proper response then no issue . Only issue when server returns soapfault and then It is having exception as explainf above . I had debug on api level and it having issue here below on com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl method find if (found == null && required) { throw new IllegalArgumentException(MessageFormat.format("Cannot find SOAP wrapper for element {0}", node)); – Jagannath Jha Jun 29 '23 at 10:32
  • What exception? Ther eis no exception in your problem description. Next to that again why aren't you using the tools as they should be used using `marshallSendAndReceive` you only need to set a soap action. IMHO part of the issue is what you are doing here. – M. Deinum Jun 29 '23 at 11:47
  • What you should be using is `webServiceTemplate.marshallSendAndRecieve(requestPayload, new SoapActionCallBack(soapAction));` and let the fault handling to the framework. Also JAXB isn't part of the JDK so if you haven't updated that or did not regenerate the classes they simply don't match. Anyway please update your code and please add your list of dependencies (your pom or build file) to your question. – M. Deinum Jun 29 '23 at 12:06
  • If we use default marshallSendAndReceive then It thriws "JAXB unmarshalling exception" but only when server throws soap fault and rest cases are fine. I will upate our build file and pom file – Jagannath Jha Jun 29 '23 at 13:26
  • Please include the stacktrace as well and the configuration you are using for the template. – M. Deinum Jun 29 '23 at 13:28

0 Answers0