You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Vinay Cardoza <vi...@bt.com> on 2008/09/18 14:20:28 UTC

Problem in rendering CDATA tag.

Hi, 
    I am trying to send a SOAP request using Apache Axis 1.3. An element in
the SOAP body requires the text to be wrapped in CDATA element. 
  
The code snippet is as follows: 
  
String stringToBeWrapped = "<![CDATA[" + "A'B'C'D" +"]]>"; 
  
OMElement elementWhichNeedsCData = ....; 
  
TextImpl omText = (TextImpl)
bodyElement.getOMFactory().createOMText(stringToBeWrapped); 
omText.setType(XMLStreamConstants.CDATA); 
elementWhichNeedsCData.addChild(omText); 
  
The code compiles without any problems. However the SOAP request is as
follows: 
  
<soapenv:Body
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="Id-17777129"> 
    <s1:EdiCustomsDeclaration
xmlns:s1="http://www.examples.com/schemas/custom/edi/v1"> 
                &amp;lt;![CDATA[A'B'C'D]]&amp;gt; 
    </s1:EdiCustomsDeclaration> 
</soapenv:Body></soapenv:Envelope> 
  
The CDATA text element has &amp;gt; and &amp;lt; escape characters. 
  
When I print the omText value, I can see the CDATA construct intact. But the
SOAP message shows something else. 
  
The problem is replicated in Axis 1.3, 1.4 and 1.4.1.

How do I prevent escape characters from appearing in the CDATA construct?
Please help. 
  
Regards, 
Vinay Cardoza 


-- 
View this message in context: http://www.nabble.com/Problem-in-rendering-CDATA-tag.-tp19551580p19551580.html
Sent from the Axis - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Re: Problem in rendering CDATA tag.

Posted by Vinay Cardoza <vi...@bt.com>.
Hi,
 I managed to isolate the problem. The problem vanishes when Rampart module
is not engaged in axis2.xml. I can get the <![CDATA[ ]]> intact. 

However, when I engage the rampart module, the CDATA tag  is removed.

I have used Rampart 1.4 , example 04.

The steps to reproduce is shown below.

1. Download Rampart 1.4 from
http://mirrors.enquira.co.uk/apache/ws/rampart/1_4/rampart-dist-1.4-bin.zip. 
2. Extract it to d:\
3. Ensure AXIS2_HOME is set to Axis2 1.4. Mine is d:\axis2-1.4. Ensure
ANT_HOME and JAVA_HOME is set.
4. Open a command prompt. 

prompt> cd D:\rampart-1.4\samples\ 
prompt>ant 
-------------The above step will copy the rampart jars to AXIS2_HOME
installation.

prompt> cd D:\rampart-1.4\samples\basic
prompt> ant service.04

5. Edit
D:\rampart-1.4\samples\basic\sample04\src\org\apache\rampart\samples\sample04\Client.java
Add the imports.

import org.apache.axiom.om.impl.llom.OMTextImpl;
import javax.xml.stream.XMLStreamConstants;

In getPayload(), replace  

childElem.setText(value);

with 

OMTextImpl omText = (OMTextImpl)
childElem.getOMFactory().createOMText(childElem,value,XMLStreamConstants.CDATA);

Save the file.

6. Open another DOS prompt.
prompt>  cd D:\rampart-1.4\samples\basic
prompt> ant client.04

Observe the SOAP request using TCP Monitor. 

<soapenv:Body
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="id-22584918">
          <ns1:echo xmlns:ns1="http://sample04.samples.rampart.apache.org">
                    <param0>Hello world</param0>
          </ns1:echo>
</soapenv:Body>

The CDATA tag is not present.

7. Edit D:\rampart-1.4\samples\basic\sample04\client.axis2.xml. Remove the
line  <module ref="rampart" /> and save the file. 

8. Repeat step 6 and observe the SOAPBody in TCP Monitor.

<soapenv:Body><ns1:echo
xmlns:ns1="http://sample04.samples.rampart.apache.org">
           <param0><![CDATA[Hello world]]></param0>
</ns1:echo></soapenv:Body>

The CDATA tag is intact.

Please advice.

Regards,
Vinay Cardoza



Vinay Cardoza wrote:
> 
> Hi,
>  I tried the standard way which is as follows:
> OMTextImpl omText = (OMTextImpl)
> childElem.getOMFactory().createOMText(elementWhichNeedsCData,"A'B'C'D",XMLStreamConstants.CDATA);
> 
> When I do a omText.getText() or elementWhichNeedsCData.toString(), I can
> see the <![CDATA[ ]]> created automatically. However, <![CDATA[  ]]> is
> stripped when I see the SOAP request in the TCP Monitor as shown below.
> 
> <soapenv:Body
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
> wsu:Id="Id-17777129"> 
>     <s1:EdiCustomsDeclaration
> xmlns:s1="http://www.examples.com/schemas/custom/edi/v1"> 
>                 A'B'C'D 
>     </s1:EdiCustomsDeclaration> 
> </soapenv:Body></soapenv:Envelope> 
> 
> Regards,
> Vinay Cardoza
> 
> 
> 
> Vinay Cardoza wrote:
>> 
>> Hi, 
>>     I am trying to send a SOAP request using Apache Axis 1.3. An element
>> in the SOAP body requires the text to be wrapped in CDATA element. 
>>   
>> The code snippet is as follows: 
>>   
>> String stringToBeWrapped = "<![CDATA[" + "A'B'C'D" +"]]>"; 
>>   
>> OMElement elementWhichNeedsCData = ....; 
>>   
>> TextImpl omText = (TextImpl)
>> bodyElement.getOMFactory().createOMText(stringToBeWrapped); 
>> omText.setType(XMLStreamConstants.CDATA); 
>> elementWhichNeedsCData.addChild(omText); 
>>   
>> The code compiles without any problems. However the SOAP request is as
>> follows: 
>>   
>> <soapenv:Body
>> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
>> wsu:Id="Id-17777129"> 
>>     <s1:EdiCustomsDeclaration
>> xmlns:s1="http://www.examples.com/schemas/custom/edi/v1"> 
>>                 &amp;lt;![CDATA[A'B'C'D]]&amp;gt; 
>>     </s1:EdiCustomsDeclaration> 
>> </soapenv:Body></soapenv:Envelope> 
>>   
>> The CDATA text element has &amp;gt; and &amp;lt; escape characters. 
>>   
>> When I print the omText value, I can see the CDATA construct intact. But
>> the SOAP message shows something else. 
>>   
>> The problem is replicated in Axis 1.3, 1.4 and 1.4.1.
>> 
>> How do I prevent escape characters from appearing in the CDATA construct?
>> Please help. 
>>   
>> Regards, 
>> Vinay Cardoza 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-in-rendering-CDATA-tag.-tp19551580p19569367.html
Sent from the Axis - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Re: Problem in rendering CDATA tag.

Posted by Vinay Cardoza <vi...@bt.com>.
Hi,
 I tried the standard way which is as follows:
OMTextImpl omText = (OMTextImpl)
childElem.getOMFactory().createOMText(elementWhichNeedsCData,"A'B'C'D",XMLStreamConstants.CDATA);

When I do a omText.getText() or elementWhichNeedsCData.toString(), I can see
the <![CDATA[ ]]> created automatically. However, <![CDATA[  ]]> is stripped
when I see the SOAP request in the TCP Monitor as shown below.

<soapenv:Body
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="Id-17777129"> 
    <s1:EdiCustomsDeclaration
xmlns:s1="http://www.examples.com/schemas/custom/edi/v1"> 
                A'B'C'D 
    </s1:EdiCustomsDeclaration> 
</soapenv:Body></soapenv:Envelope> 

Regards,
Vinay Cardoza



Vinay Cardoza wrote:
> 
> Hi, 
>     I am trying to send a SOAP request using Apache Axis 1.3. An element
> in the SOAP body requires the text to be wrapped in CDATA element. 
>   
> The code snippet is as follows: 
>   
> String stringToBeWrapped = "<![CDATA[" + "A'B'C'D" +"]]>"; 
>   
> OMElement elementWhichNeedsCData = ....; 
>   
> TextImpl omText = (TextImpl)
> bodyElement.getOMFactory().createOMText(stringToBeWrapped); 
> omText.setType(XMLStreamConstants.CDATA); 
> elementWhichNeedsCData.addChild(omText); 
>   
> The code compiles without any problems. However the SOAP request is as
> follows: 
>   
> <soapenv:Body
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
> wsu:Id="Id-17777129"> 
>     <s1:EdiCustomsDeclaration
> xmlns:s1="http://www.examples.com/schemas/custom/edi/v1"> 
>                 &amp;lt;![CDATA[A'B'C'D]]&amp;gt; 
>     </s1:EdiCustomsDeclaration> 
> </soapenv:Body></soapenv:Envelope> 
>   
> The CDATA text element has &amp;gt; and &amp;lt; escape characters. 
>   
> When I print the omText value, I can see the CDATA construct intact. But
> the SOAP message shows something else. 
>   
> The problem is replicated in Axis 1.3, 1.4 and 1.4.1.
> 
> How do I prevent escape characters from appearing in the CDATA construct?
> Please help. 
>   
> Regards, 
> Vinay Cardoza 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-in-rendering-CDATA-tag.-tp19551580p19553595.html
Sent from the Axis - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org