You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Ramya K Grama <ra...@gmail.com> on 2009/12/07 20:45:00 UTC

Axis2 1.4 not preserving CDATA

Hello,
We have been having issues with CDATA not being preserved by Axis2.
In the response xml, the '<' are escaped to '&lt;'
So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
<someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.

Reading this
http://people.apache.org/~veithen/synapse/faq.html#cdata
suggestion, we tried creating XMLInputFactory.properties file
containing this single line - javax.xml.stream.isCoalescing=false
 and placed the file under WEB-INF/classes and retried, again the same result.

We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.

The other idea was to programatically replace the escape characters
using regular expressions - which I think is really not needed.

Any help is highly appreciated.

Re: Axis2 1.4 not preserving CDATA

Posted by pchandr <pr...@yahoo.com>.
This is a known problem with xmlbeans and axis2. Since Axis2 uses AXIOM to
convert the XML Bean Object, conversion has to happen in 2 places. The First
Place itself is when using XMLBeans

XMLBeans:

In XMLBeans there are 2 settings that have to happen they are 

XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSaveCDataEntityCountThreshold(-1);
xmlOptions.setSaveCDataLengthThreshold(3);

xmlOptions.setSaveCDataLengthThreshold(3) --> make sure that the value set
here is a value which is less than the length of your cdata string (say is
your string has 10 chars at a min make sure that you set this value to 3 or
5

The next important step is you have to make sure that this options is passed
to the xmlText method , make sure that your XML Beans Object say for ex if
your response document is
com.samplecdataservice.cdataservice._2011.CdataResponseDocument when you
invoke the xmlText on this object the xmlOptions has to be passed, otherwise
it will not work

The next step is Axiom which again converts the CDATA to encode it , in
order to fix that i had to change the in-out class which is generated by
Axis to take this implementation

private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
			org.apache.axiom.soap.SOAPFactory factory,
			com.samplecdataservice.cdataservice._2011.CdataResponseDocument param,
			boolean optimizeContent) throws org.apache.axis2.AxisFault {
		org.apache.axiom.soap.SOAPEnvelope envelope = factory
				.getDefaultEnvelope();
		if (param != null) {
			//envelope.getBody().addChild(toOM(param, optimizeContent));
			XmlOptions xmlOptions = new XmlOptions();
			xmlOptions.setSaveCDataEntityCountThreshold(-1);
			xmlOptions.setSaveCDataLengthThreshold(3);
			ByteArrayInputStream bais = new
ByteArrayInputStream(param.xmlText(xmlOptions).getBytes());	
			XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();			
			xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING,
Boolean.FALSE);
			try {
				StAXOMBuilder omBuilder = new
StAXOMBuilder(xmlInputFactory.createXMLStreamReader(bais));
				envelope.getBody().addChild(omBuilder.getDocumentElement());
			} catch (XMLStreamException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				createAxisFault(e);
			}	
			//XMLInputFactory inputFactory = XMLInputFactory.newInstance();
			
			//inputFactory.c
		
//envelope.getBody().addChild((org.apache.axiom.om.OMElement)param.getDomNode());
		}
		return envelope;
	}

The line

xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
is very important because Stax parser is defaulted to using COALESCING which
will remove the CDATA sections, in order to preserve it you need to set it
to false as shown above

Thanks





Andreas Veithen-2 wrote:
> 
> On Mon, Dec 7, 2009 at 23:43, Ramya K Grama <ra...@gmail.com> wrote:
>> I dont understand.
>> It is a simple case where a Axis2 webservice, implemented with
>> XMLBeans databinding, needs to send CDATA out in the response XML,
>> preserved/intact - without characters being escaped.
> 
> This is not supported since in the context of a Web service, since
> this is not a valid requirement (because the consumer must not make a
> difference between a CDATA section and an equivalent text node). If
> you have a consumer of your service that requires a CDATA section, you
> should challenge that requirement.
> 
>> And from what I understood from your previous reply is that this can
>> be done by using AXIOM APIs to set the contentType to CDATA.
>> Which makes sense to me, but need some help with the API - how could
>> one get hold of the underlying AXIOM element from XMLBeans inorder to
>> set the contenttype to CDATA.
> 
> You will have to inspect the generated code to see if it is possible
> to get hold of the OMElement produced from the bean.
> 
>>
>>
>> On Mon, Dec 7, 2009 at 5:09 PM, Andreas Veithen
>> <an...@gmail.com> wrote:
>>> I'm not aware of any XML data binding framework that would allow you
>>> to control whether something is serialized as a text node or a CDATA
>>> section. This is by design, because the difference between a text node
>>> and a CDATA section is only syntactic, but has no semantic meaning.
>>> This implies that any system that processes a CDATA section
>>> differently from an equivalent text node should be considered as
>>> broken. At least that is the what most people in the industry believe.
>>>
>>> Andreas
>>>
>>> On Mon, Dec 7, 2009 at 21:49, Ramya K Grama <ra...@gmail.com>
>>> wrote:
>>>> Thanks for the quick reply!
>>>> I am using XMLBeans 2.3.0.  I am not using AXIOM APIs directly to
>>>> create the response elements.
>>>> Hence, I am not using OMText directly.
>>>> From the XMLBean api, I am able to use only setText and have not found
>>>> a way to passin the CDATA type (neither in an overloaded setText nor
>>>> in a setType).
>>>>
>>>> Could you please share a code snippet showing how to pass the CDATA
>>>> type using XMLBeans or how to get the OMText node from the XMLBean
>>>> object.
>>>> With XMLBeans I have <operationName>Document object. How do I get an
>>>> OMText out of it to be able to set the Type.
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, Dec 7, 2009 at 3:39 PM, Andreas Veithen
>>>> <an...@gmail.com> wrote:
>>>>> XMLInputFactory.properties can be used to preserve CDATA sections when
>>>>> using Axiom to _parse_ an XML document (By default CDATA sections are
>>>>> transformed to text nodes and coalesced with adjacent text nodes). On
>>>>> the other hand, creating CDATA sections in output documents is
>>>>> something that Axiom has always supported.
>>>>>
>>>>> Probably what you are doing is to create an OMText node with type TEXT
>>>>> and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
>>>>> of course escaped. What you need to do instead is to create an OMText
>>>>> node with type CDATA and content "ROSEANNA".
>>>>>
>>>>> Andreas
>>>>>
>>>>> On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com>
>>>>> wrote:
>>>>>> Hello,
>>>>>> We have been having issues with CDATA not being preserved by Axis2.
>>>>>> In the response xml, the '<' are escaped to '&lt;'
>>>>>> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
>>>>>> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the
>>>>>> response.
>>>>>>
>>>>>> Reading this
>>>>>> http://people.apache.org/~veithen/synapse/faq.html#cdata
>>>>>> suggestion, we tried creating XMLInputFactory.properties file
>>>>>> containing this single line - javax.xml.stream.isCoalescing=false
>>>>>>  and placed the file under WEB-INF/classes and retried, again the
>>>>>> same result.
>>>>>>
>>>>>> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>>>>>>
>>>>>> The other idea was to programatically replace the escape characters
>>>>>> using regular expressions - which I think is really not needed.
>>>>>>
>>>>>> Any help is highly appreciated.
>>>>>>
>>>>>
>>>>
>>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Axis2-1.4-not-preserving-CDATA-tp26682937p31939416.html
Sent from the Axis - User mailing list archive at Nabble.com.


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


Re: Axis2 1.4 not preserving CDATA

Posted by Andreas Veithen <an...@gmail.com>.
On Mon, Dec 7, 2009 at 23:43, Ramya K Grama <ra...@gmail.com> wrote:
> I dont understand.
> It is a simple case where a Axis2 webservice, implemented with
> XMLBeans databinding, needs to send CDATA out in the response XML,
> preserved/intact - without characters being escaped.

This is not supported since in the context of a Web service, since
this is not a valid requirement (because the consumer must not make a
difference between a CDATA section and an equivalent text node). If
you have a consumer of your service that requires a CDATA section, you
should challenge that requirement.

> And from what I understood from your previous reply is that this can
> be done by using AXIOM APIs to set the contentType to CDATA.
> Which makes sense to me, but need some help with the API - how could
> one get hold of the underlying AXIOM element from XMLBeans inorder to
> set the contenttype to CDATA.

You will have to inspect the generated code to see if it is possible
to get hold of the OMElement produced from the bean.

>
>
> On Mon, Dec 7, 2009 at 5:09 PM, Andreas Veithen
> <an...@gmail.com> wrote:
>> I'm not aware of any XML data binding framework that would allow you
>> to control whether something is serialized as a text node or a CDATA
>> section. This is by design, because the difference between a text node
>> and a CDATA section is only syntactic, but has no semantic meaning.
>> This implies that any system that processes a CDATA section
>> differently from an equivalent text node should be considered as
>> broken. At least that is the what most people in the industry believe.
>>
>> Andreas
>>
>> On Mon, Dec 7, 2009 at 21:49, Ramya K Grama <ra...@gmail.com> wrote:
>>> Thanks for the quick reply!
>>> I am using XMLBeans 2.3.0.  I am not using AXIOM APIs directly to
>>> create the response elements.
>>> Hence, I am not using OMText directly.
>>> From the XMLBean api, I am able to use only setText and have not found
>>> a way to passin the CDATA type (neither in an overloaded setText nor
>>> in a setType).
>>>
>>> Could you please share a code snippet showing how to pass the CDATA
>>> type using XMLBeans or how to get the OMText node from the XMLBean
>>> object.
>>> With XMLBeans I have <operationName>Document object. How do I get an
>>> OMText out of it to be able to set the Type.
>>>
>>>
>>>
>>>
>>> On Mon, Dec 7, 2009 at 3:39 PM, Andreas Veithen
>>> <an...@gmail.com> wrote:
>>>> XMLInputFactory.properties can be used to preserve CDATA sections when
>>>> using Axiom to _parse_ an XML document (By default CDATA sections are
>>>> transformed to text nodes and coalesced with adjacent text nodes). On
>>>> the other hand, creating CDATA sections in output documents is
>>>> something that Axiom has always supported.
>>>>
>>>> Probably what you are doing is to create an OMText node with type TEXT
>>>> and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
>>>> of course escaped. What you need to do instead is to create an OMText
>>>> node with type CDATA and content "ROSEANNA".
>>>>
>>>> Andreas
>>>>
>>>> On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com> wrote:
>>>>> Hello,
>>>>> We have been having issues with CDATA not being preserved by Axis2.
>>>>> In the response xml, the '<' are escaped to '&lt;'
>>>>> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
>>>>> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.
>>>>>
>>>>> Reading this
>>>>> http://people.apache.org/~veithen/synapse/faq.html#cdata
>>>>> suggestion, we tried creating XMLInputFactory.properties file
>>>>> containing this single line - javax.xml.stream.isCoalescing=false
>>>>>  and placed the file under WEB-INF/classes and retried, again the same result.
>>>>>
>>>>> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>>>>>
>>>>> The other idea was to programatically replace the escape characters
>>>>> using regular expressions - which I think is really not needed.
>>>>>
>>>>> Any help is highly appreciated.
>>>>>
>>>>
>>>
>>
>

Re: Axis2 1.4 not preserving CDATA

Posted by Ramya K Grama <ra...@gmail.com>.
I dont understand.
It is a simple case where a Axis2 webservice, implemented with
XMLBeans databinding, needs to send CDATA out in the response XML,
preserved/intact - without characters being escaped.
And from what I understood from your previous reply is that this can
be done by using AXIOM APIs to set the contentType to CDATA.
Which makes sense to me, but need some help with the API - how could
one get hold of the underlying AXIOM element from XMLBeans inorder to
set the contenttype to CDATA.


On Mon, Dec 7, 2009 at 5:09 PM, Andreas Veithen
<an...@gmail.com> wrote:
> I'm not aware of any XML data binding framework that would allow you
> to control whether something is serialized as a text node or a CDATA
> section. This is by design, because the difference between a text node
> and a CDATA section is only syntactic, but has no semantic meaning.
> This implies that any system that processes a CDATA section
> differently from an equivalent text node should be considered as
> broken. At least that is the what most people in the industry believe.
>
> Andreas
>
> On Mon, Dec 7, 2009 at 21:49, Ramya K Grama <ra...@gmail.com> wrote:
>> Thanks for the quick reply!
>> I am using XMLBeans 2.3.0.  I am not using AXIOM APIs directly to
>> create the response elements.
>> Hence, I am not using OMText directly.
>> From the XMLBean api, I am able to use only setText and have not found
>> a way to passin the CDATA type (neither in an overloaded setText nor
>> in a setType).
>>
>> Could you please share a code snippet showing how to pass the CDATA
>> type using XMLBeans or how to get the OMText node from the XMLBean
>> object.
>> With XMLBeans I have <operationName>Document object. How do I get an
>> OMText out of it to be able to set the Type.
>>
>>
>>
>>
>> On Mon, Dec 7, 2009 at 3:39 PM, Andreas Veithen
>> <an...@gmail.com> wrote:
>>> XMLInputFactory.properties can be used to preserve CDATA sections when
>>> using Axiom to _parse_ an XML document (By default CDATA sections are
>>> transformed to text nodes and coalesced with adjacent text nodes). On
>>> the other hand, creating CDATA sections in output documents is
>>> something that Axiom has always supported.
>>>
>>> Probably what you are doing is to create an OMText node with type TEXT
>>> and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
>>> of course escaped. What you need to do instead is to create an OMText
>>> node with type CDATA and content "ROSEANNA".
>>>
>>> Andreas
>>>
>>> On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com> wrote:
>>>> Hello,
>>>> We have been having issues with CDATA not being preserved by Axis2.
>>>> In the response xml, the '<' are escaped to '&lt;'
>>>> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
>>>> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.
>>>>
>>>> Reading this
>>>> http://people.apache.org/~veithen/synapse/faq.html#cdata
>>>> suggestion, we tried creating XMLInputFactory.properties file
>>>> containing this single line - javax.xml.stream.isCoalescing=false
>>>>  and placed the file under WEB-INF/classes and retried, again the same result.
>>>>
>>>> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>>>>
>>>> The other idea was to programatically replace the escape characters
>>>> using regular expressions - which I think is really not needed.
>>>>
>>>> Any help is highly appreciated.
>>>>
>>>
>>
>

Re: Axis2 1.4 not preserving CDATA

Posted by Andreas Veithen <an...@gmail.com>.
I'm not aware of any XML data binding framework that would allow you
to control whether something is serialized as a text node or a CDATA
section. This is by design, because the difference between a text node
and a CDATA section is only syntactic, but has no semantic meaning.
This implies that any system that processes a CDATA section
differently from an equivalent text node should be considered as
broken. At least that is the what most people in the industry believe.

Andreas

On Mon, Dec 7, 2009 at 21:49, Ramya K Grama <ra...@gmail.com> wrote:
> Thanks for the quick reply!
> I am using XMLBeans 2.3.0.  I am not using AXIOM APIs directly to
> create the response elements.
> Hence, I am not using OMText directly.
> From the XMLBean api, I am able to use only setText and have not found
> a way to passin the CDATA type (neither in an overloaded setText nor
> in a setType).
>
> Could you please share a code snippet showing how to pass the CDATA
> type using XMLBeans or how to get the OMText node from the XMLBean
> object.
> With XMLBeans I have <operationName>Document object. How do I get an
> OMText out of it to be able to set the Type.
>
>
>
>
> On Mon, Dec 7, 2009 at 3:39 PM, Andreas Veithen
> <an...@gmail.com> wrote:
>> XMLInputFactory.properties can be used to preserve CDATA sections when
>> using Axiom to _parse_ an XML document (By default CDATA sections are
>> transformed to text nodes and coalesced with adjacent text nodes). On
>> the other hand, creating CDATA sections in output documents is
>> something that Axiom has always supported.
>>
>> Probably what you are doing is to create an OMText node with type TEXT
>> and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
>> of course escaped. What you need to do instead is to create an OMText
>> node with type CDATA and content "ROSEANNA".
>>
>> Andreas
>>
>> On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com> wrote:
>>> Hello,
>>> We have been having issues with CDATA not being preserved by Axis2.
>>> In the response xml, the '<' are escaped to '&lt;'
>>> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
>>> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.
>>>
>>> Reading this
>>> http://people.apache.org/~veithen/synapse/faq.html#cdata
>>> suggestion, we tried creating XMLInputFactory.properties file
>>> containing this single line - javax.xml.stream.isCoalescing=false
>>>  and placed the file under WEB-INF/classes and retried, again the same result.
>>>
>>> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>>>
>>> The other idea was to programatically replace the escape characters
>>> using regular expressions - which I think is really not needed.
>>>
>>> Any help is highly appreciated.
>>>
>>
>

Re: Axis2 1.4 not preserving CDATA

Posted by Ramya K Grama <ra...@gmail.com>.
Thanks for the quick reply!
I am using XMLBeans 2.3.0.  I am not using AXIOM APIs directly to
create the response elements.
Hence, I am not using OMText directly.
>From the XMLBean api, I am able to use only setText and have not found
a way to passin the CDATA type (neither in an overloaded setText nor
in a setType).

Could you please share a code snippet showing how to pass the CDATA
type using XMLBeans or how to get the OMText node from the XMLBean
object.
With XMLBeans I have <operationName>Document object. How do I get an
OMText out of it to be able to set the Type.




On Mon, Dec 7, 2009 at 3:39 PM, Andreas Veithen
<an...@gmail.com> wrote:
> XMLInputFactory.properties can be used to preserve CDATA sections when
> using Axiom to _parse_ an XML document (By default CDATA sections are
> transformed to text nodes and coalesced with adjacent text nodes). On
> the other hand, creating CDATA sections in output documents is
> something that Axiom has always supported.
>
> Probably what you are doing is to create an OMText node with type TEXT
> and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
> of course escaped. What you need to do instead is to create an OMText
> node with type CDATA and content "ROSEANNA".
>
> Andreas
>
> On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com> wrote:
>> Hello,
>> We have been having issues with CDATA not being preserved by Axis2.
>> In the response xml, the '<' are escaped to '&lt;'
>> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
>> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.
>>
>> Reading this
>> http://people.apache.org/~veithen/synapse/faq.html#cdata
>> suggestion, we tried creating XMLInputFactory.properties file
>> containing this single line - javax.xml.stream.isCoalescing=false
>>  and placed the file under WEB-INF/classes and retried, again the same result.
>>
>> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>>
>> The other idea was to programatically replace the escape characters
>> using regular expressions - which I think is really not needed.
>>
>> Any help is highly appreciated.
>>
>

Re: Axis2 1.4 not preserving CDATA

Posted by Andreas Veithen <an...@gmail.com>.
XMLInputFactory.properties can be used to preserve CDATA sections when
using Axiom to _parse_ an XML document (By default CDATA sections are
transformed to text nodes and coalesced with adjacent text nodes). On
the other hand, creating CDATA sections in output documents is
something that Axiom has always supported.

Probably what you are doing is to create an OMText node with type TEXT
and content "<![CDATA[ROSEANNA]]>". In the output document, this gets
of course escaped. What you need to do instead is to create an OMText
node with type CDATA and content "ROSEANNA".

Andreas

On Mon, Dec 7, 2009 at 20:45, Ramya K Grama <ra...@gmail.com> wrote:
> Hello,
> We have been having issues with CDATA not being preserved by Axis2.
> In the response xml, the '<' are escaped to '&lt;'
> So instead of <someTagName><![CDATA[ROSEANNA]]></someTagName> we get
> <someTagName>&lt;![CDATA[ROSEANNA]]&gt;</someTagName> in the response.
>
> Reading this
> http://people.apache.org/~veithen/synapse/faq.html#cdata
> suggestion, we tried creating XMLInputFactory.properties file
> containing this single line - javax.xml.stream.isCoalescing=false
>  and placed the file under WEB-INF/classes and retried, again the same result.
>
> We are using Axis21.4, XMLBeans 2.3.0, Tomcat 6.
>
> The other idea was to programatically replace the escape characters
> using regular expressions - which I think is really not needed.
>
> Any help is highly appreciated.
>