0

I have an issue with spring boot soap xml unmarshaling.
currently, I am consuming a soap service and everything is working fine except sometimes I am receiving an exception, because of the special characters.

Exception Example for receiving "&#x1A" is an invalid XML character:

020-01-27T22:37:08,175 ERROR [http-nio-8135-exec-2] || o.a.j.l.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [/application-test] threw exception [Request processing failed; nested exception is org.springframework.ws.InvalidXmlException: Could not parse XML; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 416; Character reference "&#x1A" is an invalid XML character.] with root cause
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 416; Character reference "&#x1A" is an invalid XML character.
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1243)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
    at java.xml/org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
    at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:687)
    at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:774)
    at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:370)
    at com.sun.xml.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(EfficientStreamingTransformer.java:396)
    at com.sun.xml.messaging.saaj.soap.EnvelopeFactory.parseEnvelopeSax(EnvelopeFactory.java:173)
    at com.sun.xml.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:92)
    at com.sun.xml.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:55)
    at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:142)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:191)
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:62)

AppConfig class code:


@Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.application.test");
        return marshaller;
    }

    @Bean
    public CallerClient callerClient(Jaxb2Marshaller marshaller) {
        CallerClient client = new CallerClient ();
        client.setDefaultUri("service url");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        client.setMessageSender(webServiceMessageSender());
        ClientInterceptor[] interceptors = { callerInterceptor };
        client.setInterceptors(interceptors);
        return client;
    }

    @Bean
    public WebServiceMessageSender webServiceMessageSender() {
        HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();
        httpComponentsMessageSender.setConnectionTimeout(3000);
        httpComponentsMessageSender.setReadTimeout(3000);
        return httpComponentsMessageSender;
    }

is there a way to receive the response without any issue by accepting the special characters or removing them.

mzaje18
  • 1
  • 1
  • 3
  • Check out https://stackoverflow.com/a/4457559/1496080 it's for marshalling but might still be the trick – damian Jan 27 '20 at 19:54
  • 1
    The character you have provided is an illegal character in XML 1.0. It wouldn't be possible to really accept them with XML 1.0, and if the data you're provided is malformed, it's technically the provider's responsibility to fix it. – Compass Jan 27 '20 at 19:56
  • Does this answer your question? [Invalid XML Character During Unmarshall](https://stackoverflow.com/questions/5815134/invalid-xml-character-during-unmarshall) – Mehrdad HosseinNejad Yami Jan 27 '20 at 19:57
  • @damian actually I am using org.springframework.oxm.jaxb.Jaxb2Marshaller and I have tried below code with no luck marshaller.setMarshallerProperties(new HashMap() { private static final long serialVersionUID = 1L;{ put("jaxb.encoding", "Unicode"); }}); – mzaje18 Jan 27 '20 at 20:01
  • @Compass so I have to delete the illegal characters in order to parse the response correctly – mzaje18 Jan 27 '20 at 20:06

0 Answers0