Announcement Announcement Module
Collapse
No announcement yet.
XML entites automatically escaped, although in a CDATA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML entites automatically escaped, although in a CDATA

    Hi all,

    I'm facing a problem using Spring WS WebServiceTemplate to implement a WS client.
    Basically, I'm injecting some XML as a String in my request, it is enclosed in a CDATA tag (this is required by the remote service), but it's entities get escaped. I'm looking for a way to bypass this encoding (which I didn't expect, since CDATA content shouldn't be interpreted in any way, right ?).
    More details after the break

    I have to reach an external application using SOAP, with this kind of structure :

    Code:
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:abc="http://abc.remote.com">
      <soap:Header/>
      <soap:Body>
        <abc:action>
          <abc:params>
            <![CDATA[
              <subaction>
                <name>NAME</name>
                <infos>
                  <info1>INFO1</info1>
                  <info2>INFO2</info2>
                </infos>
              </subaction>
            ]]>
          </abc:params>
        </abc:action>
      </soap:Body>
    </soap:Envelope>
    When I use this markup with soapui, I get the correct answer.
    Using Wireshark, I see this exact markup being sent over the wire by soapui.
    However, when I use my WebServiceTemplate, I noticed that what is sent is this markup, but with XML entities escaped (&lt; etc.).
    The remote service then answers with an error (I absolutely don't know anything about nor can't do anything on the remote implementation).

    Relevant code example :

    Code:
    public SubactionResponseDocument subaction() {
      // build the XML to send with SOAP
      SubactionDocument request = buildRequest();
      SubactionResponseDocument answer = (SubactionResponseDocument)myWSTemplate.marshalSendAndReceive(request);
      return answer;
    }
    with the same XmlBeansMarshaller as marshaller and unmarshaller for myWSTemplate, and buildRequest() returning a markup like :

    Code:
    <abc:action>
      <abc:params>
        <![CDATA[
          <subaction>
            <name>NAME</name>
            <infos>
              <info1>INFO1</info1>
              <info2>INFO2</info2>
            </infos>
          </subaction>
        ]]>
      </abc:params>
    </abc:action>
    According to Wireshark, it results in this kind of markup being sent :

    Code:
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:abc="http://abc.remote.com">
      <soap:Header/>
      <soap:Body>
        <abc:action>
          <abc:params>
            <![CDATA[
              &lt;subaction&gt;
              etc.
            ]]>
          </abc:params>
        </abc:action>
      </soap:Body>
    </soap:Envelope>
    Digging through the huge actual function call hierarchy (Spring / DOM / SOAP / ...) with Eclipse hasn't led me to the place where this escaping happens

    However I can tell that :
    * when calling marshalSendAndReceive(request), request text is not escaped.
    * in XmlBeansMarshaller.marshalDomNode(Object graph, Node node), graph's text is still unescaped too

    I think I gave all what I thought relevant, of course feel free to ask any information I forgot

    Thanks in advance for any contribution !

  • #2
    did you find a solutions for this. I am facing same situation where I have xml string in CDATA but web serviceTemplate doesn't understand CDATA and keep treating as XML and boms out..

    Comment


    • #3
      In fact, after more digging and several tests, I understood that the documentation of the remote service was wrong so I was using it wrong. The problem wasn't about escaped-or-not XML in CDATA section... so I didn't continue looking for a way to customize this behavior... sorry

      Comment

      Working...
      X