Search code examples
springsoapspring-ws

SPRING WS misses "<?xml version="1.0" encoding="UTF-8"?>"


I use spring ws.

How could I add this <?xml version="1.0" encoding="UTF-8"?> to my first line in the response?

I tried this block of code but It doesn't work. Could anybody help me?

@Bean (name = "messageFactory")
public SaajSoapMessageFactory messageFactory () {
    Map<String, Object> props = new HashMap<>();
    props.put(SOAPMessage.WRITE_XML_DECLARATION, Boolean.TRUE);

    SaajSoapMessageFactory msgFactory = new SaajSoapMessageFactory();
    msgFactory.setMessageProperties(props);
    msgFactory.setSoapVersion(org.springframework.ws.soap.SoapVersion.SOAP_11);

    return msgFactory;
}

Solution

  • Well at least it worked for me, thanks a lot !

    I just changed the value from Boolean.TRUE to "true":

    @Bean (name = "messageFactory")
        public SaajSoapMessageFactory messageFactory () {
            Map<String, Object> props = new HashMap<>();
            props.put(SOAPMessage.WRITE_XML_DECLARATION, "true");
    
            SaajSoapMessageFactory msgFactory = new SaajSoapMessageFactory();
            msgFactory.setMessageProperties(props);
            msgFactory.setSoapVersion(org.springframework.ws.soap.SoapVersion.SOAP_11);
    
            return msgFactory;
        }