3

I am building a Web service using Java and Spring-ws. It is working fine, except for one thing.

When I assembly the payload to be put inside the SOAP Body, I want to include CDATA escaped strings. This is how I want the result to look like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_0="http://example.com/ns">
<soapenv:Header/>
<soapenv:Body>
 <_0:Message>
    <_0:StringPayload><![CDATA[<myxml>stuff</myxml>]]></_0:StringPayload>
 </_0:Message>
</soapenv:Body>
</soapenv:Envelope>

However, Spring-WS seems to tamper with the payload when it adds the SOAP envelope. This is the result I get:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:_0="http://example.com/ns">
<soapenv:Header/>
<soapenv:Body>
 <_0:Message>
    <_0:StringPayload>&lt;myxml>stuff&lt;/myxml></StringPayload>
 </_0:Message>
</soapenv:Body>
</soapenv:Envelope>

Is there a way to make sure Spring WS does not escape XML characters and respect the CDATA tag?

I am using Spring WS together with Apache Camel, so a solution where I do not have to alter/extend the spring-ws classes would be prefered.

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • What implementation of `org.springframework.ws.soap.SoapMessageFactory` do you use (axiom? saaj?)? What `org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler` do you use (marshalling, jaxb, castor, `AbstractPayloadSourceMethodProcessor`)? – Grzegorz Grzybek Apr 13 '12 at 08:23
  • 1
    Why? For a xml parser and web service stack these two are equivalent. – Jörn Horstmann Apr 13 '12 at 08:38
  • @GrzegorzGrzybek The message is of type SAAJ. I am not sure which MethodReturnValueHandler is beeing used, but I think that will be JAXB. – Petter Nordlander Apr 13 '12 at 09:37
  • @JörnHorstmann Thanks for mentioning that. The content is, however, a lot more human readable with CData section rather than escaped characters. In this case, the human readable factor is quite large. All business data will be inside that tag. It will be bundled XML in XML. – Petter Nordlander Apr 13 '12 at 09:40
  • See [this](http://stackoverflow.com/q/7536973/250517) and [this](http://stackoverflow.com/q/3136375/250517) question. If you're using JAXB-ri you have to use some tricks with `ContextHandler`. With MOXy you could use `@XmlCDATA` extension. – Grzegorz Grzybek Apr 13 '12 at 10:16

1 Answers1

3

I have used MOXy and @XmlCDATA annotation to generate CDATA content, and experiments have shown that AxiomSoapMessageFactory reaplces it with escaped XML content (although Jaxb2Marshaller seems to produce correct CDATA stuff).

However, it works just fine with SaajSoapMessageFactory.