2 years ago

#26616

test-img

İlkay Gunel

How to not escaping characters in Spring Boot SOAP Connector?

I have a SOAP connector in my Spring Boot project. I need to send a String as SOAP body in my SOAP request but Spring escapes <,> etc. characters. But I need to prevent it.

This is my JaxbMarshaller creation, I added com.sun.xml.bind.marshaller.CharacterEscapeHandler property with NoEscapeHandler class but it doesn't help:

private Jaxb2Marshaller getJaxb2Marshaller() {
        Map<String, Object> marshallerProperties = new HashMap<>();
        Map<String, Object> unMarshallerProperties = new HashMap<>();
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        CharacterEscapeHandler escapeHandler = NoEscapeHandler.theInstance;

        marshallerProperties.put("com.sun.xml.bind.characterEscapeHandler", escapeHandler);
        marshallerProperties.put("com.sun.xml.bind.marshaller.CharacterEscapeHandler", escapeHandler);
        marshallerProperties.put(Marshaller.JAXB_ENCODING, "utf-8");

        jaxb2Marshaller.setMarshallerProperties(marshallerProperties);
        jaxb2Marshaller.setUnmarshallerProperties(unMarshallerProperties);

        return jaxb2Marshaller;
    }

This is my SOAPConnector creation:

@Bean
public SOAPConnector soapConnector() throws IOException {
    SOAPConnector client = new SOAPConnector();
    client.setDefaultUri("http://localhost:8080/service/student-details");
    client.setMarshaller(getJaxb2Marshaller());
    client.setUnmarshaller(getJaxb2Marshaller());

    return client;
}

This is how I'm calling SAOP service:

JAXBElement<String> jaxbElement = new JAXBElement(new QName(operationType), String.class, "<![CDATA[" + template + "]]");
String response = (String) soapConnector.callWebService(soapRequestURL, jaxbElement);

How can I send my request without character escaping?

spring

spring-boot

jax-ws

ws

0 Answers

Your Answer

Accepted video resources