Discussion:
How to enforce the clients to use CDATA for specific elements
hsemar
2010-11-24 15:39:26 UTC
Permalink
How do I handle the special characters in web service request

I have a web service method and here is the sample request

<request>
<id>1<id>
<desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
<category>2</category>
</request>

desc element type is string in my schema file.

When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.

But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.

So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?

Is there anyway that we can say this element should be wrapped with CDATA ?
I know it is not possible in the XSD schema. I'm mostly looking for a server
side (web service level not at the client level) solution

Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any idea?

I would like to get your valuable suggestions on this.
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html
Sent from the cxf-user mailing list archive at Nabble.com.
Schneider Christian
2010-11-24 15:48:32 UTC
Permalink
Hi,

the text inside an xml element always has to be encoded like you described (e.g. ;lt instead of <). Anything else is not a good idea. So your client should encode the contents of the desc element. You can not do this on the server in a reliable and xml compatible fashion.

For example how would you transfer the content
"test</desc>test2"

If you simply put it in the desc element it will break the xml:
<request>
<id>1<id>
<desc>test</desc>test2</desc>
<category>2</category>
</request>

Best regards

Christian



Christian Schneider
Informationsverarbeitung
Business Solutions
Handel und Dispatching

Tel : +49-(0)721-63-15482

EnBW Systeme Infrastruktur Support GmbH
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim ­ HRB 108550
Vorsitzender des Aufsichtsrats: Dr. Bernhard Beck
Geschäftsführer: Jochen Adenau, Hans-Günther Meier


-----Ursprüngliche Nachricht-----
Von: hsemar [mailto:rameshforu-***@public.gmane.org]
Gesendet: Mittwoch, 24. November 2010 16:39
An: users-qJ/***@public.gmane.org
Betreff: How to enforce the clients to use CDATA for specific elements


How do I handle the special characters in web service request

I have a web service method and here is the sample request

<request>
<id>1<id>
<desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
<category>2</category>
</request>

desc element type is string in my schema file.

When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.

But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.

So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?

Is there anyway that we can say this element should be wrapped with CDATA ?
I know it is not possible in the XSD schema. I'm mostly looking for a server
side (web service level not at the client level) solution

Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any idea?

I would like to get your valuable suggestions on this.
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html
Sent from the cxf-user mailing list archive at Nabble.com.
Schneider Christian
2010-11-24 15:50:51 UTC
Permalink
I just remembered there is one possible solution. You define desc as an xsd:any type.
So you can place valid xml in the element.

In cxf this will giver you a dom node for the element when you generate code.

Best regards

Christian





Christian Schneider
Informationsverarbeitung
Business Solutions
Handel und Dispatching

Tel : +49-(0)721-63-15482

EnBW Systeme Infrastruktur Support GmbH
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim ­ HRB 108550
Vorsitzender des Aufsichtsrats: Dr. Bernhard Beck
Geschäftsführer: Jochen Adenau, Hans-Günther Meier


-----Ursprüngliche Nachricht-----
Von: hsemar [mailto:rameshforu-***@public.gmane.org]
Gesendet: Mittwoch, 24. November 2010 16:39
An: users-qJ/***@public.gmane.org
Betreff: How to enforce the clients to use CDATA for specific elements


How do I handle the special characters in web service request

I have a web service method and here is the sample request

<request>
<id>1<id>
<desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
<category>2</category>
</request>

desc element type is string in my schema file.

When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.

But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.

So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?

Is there anyway that we can say this element should be wrapped with CDATA ?
I know it is not possible in the XSD schema. I'm mostly looking for a server
side (web service level not at the client level) solution

Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any idea?

I would like to get your valuable suggestions on this.
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html
Sent from the cxf-user mailing list archive at Nabble.com.
Benson Margulies
2010-11-24 16:12:40 UTC
Permalink
You can't do this easily.

CXF is based on XML, and, in XML, there is officially _no difference
at all_ between those characters escaped with ampersands and escaped
with cdata. Any program that behaves differently is, from an XML
standards point of view, broken.

If you need to deal with such a program, you need to learn how to make
an interceptor to do what you want. It might be possible to configure
Woodstox to do what you want and then to impose that configuration
into your stack.

--benson
Post by hsemar
How do I handle the special characters in web service request
I have a web service method and here is the sample request
<request>
    <id>1<id>
     <desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
      <category>2</category>
</request>
desc element type is string in my schema file.
When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.
But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.
So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?
Is there anyway that we can say this element should be wrapped with CDATA ?
I know it is not possible in the XSD schema. I'm mostly looking for a server
side (web service level not at the client level) solution
Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any idea?
I would like to get your valuable suggestions on this.
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html
Sent from the cxf-user mailing list archive at Nabble.com.
hsemar
2010-11-24 17:20:43 UTC
Permalink
Thanks Benson for your response, appreciate it.

I was thinking of writing a handler for soap request. What you are
suggesting is interceptor. Do you think I can create one custom interceptor
by extending AbstractPhaseInterceptor ?

In the handle method i can get th soap message and alter the message? Let me
know what do you think.

Also, I feel it might affect the performance of the web service if I
intercept each request and do the manipulation.

Thanks,
Ramesh

On Wed, Nov 24, 2010 at 9:43 PM, Benson Margulies [via CXF] <
Post by Benson Margulies
You can't do this easily.
CXF is based on XML, and, in XML, there is officially _no difference
at all_ between those characters escaped with ampersands and escaped
with cdata. Any program that behaves differently is, from an XML
standards point of view, broken.
If you need to deal with such a program, you need to learn how to make
an interceptor to do what you want. It might be possible to configure
Woodstox to do what you want and then to impose that configuration
into your stack.
--benson
On Wed, Nov 24, 2010 at 10:39 AM, hsemar <[hidden email]<http://user/SendEmail.jtp?type=node&node=3278635&i=0>>
Post by hsemar
How do I handle the special characters in web service request
I have a web service method and here is the sample request
<request>
<id>1<id>
<desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
<category>2</category>
</request>
desc element type is string in my schema file.
When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.
But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.
So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?
Is there anyway that we can say this element should be wrapped with CDATA
?
Post by hsemar
I know it is not possible in the XSD schema. I'm mostly looking for a
server
Post by hsemar
side (web service level not at the client level) solution
Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any
idea?
Post by hsemar
I would like to get your valuable suggestions on this.
--
http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html<http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278597.html?by-user=t>
Post by hsemar
Sent from the cxf-user mailing list archive at Nabble.com.
------------------------------
http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278635.html
To unsubscribe from How to enforce the clients to use CDATA for specific
elements, click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3278597&code=cmFtZXNoZm9ydUBnbWFpbC5jb218MzI3ODU5N3wxNzQzMjU0MTQ3>.
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-enforce-the-clients-to-use-CDATA-for-specific-elements-tp3278597p3278737.html
Sent from the cxf-user mailing list archive at Nabble.com.
Daniel Kulp
2010-11-29 16:48:29 UTC
Permalink
Post by hsemar
How do I handle the special characters in web service request
I have a web service method and here is the sample request
<request>
<id>1<id>
<desc>this is desc of
<itemid>1</itemid><itemname>ipod</itemname></desc>
<category>2</category>
</request>
desc element type is string in my schema file.
When I create client stub and test this, the < and > characters inside
<desc> element are converted into ;lt and ;gt respectively and everything
works fine.
But when I test this same service using SoapUI, the charatcters are not
being converted and I get unmarsshalling error which is fair.
So, now how do I make sure the data inside the <desc> element is not
processed ? Do I need to write a handler and acheive this in the server
side?
Is there anyway that we can say this element should be wrapped with CDATA ?
I know it is not possible in the XSD schema. I'm mostly looking for a
server side (web service level not at the client level) solution
Also, I would like to remove some set of special characters from the soap
request before the request is used inside the web service method..any idea?
I would like to get your valuable suggestions on this.
JAXB pretty much never writes out CDATA sections. The only way to really do
it is to write an interceptor that will take the XMLStreamWriter and wrapper
it with a new XMLStreamWriter that would do some processing in the
writeCharacters calls. It could delegate down into writeCDATA instead of
writeCharacters or similar.
--
Daniel Kulp
dkulp-1oDqGaOF3Lkdnm+***@public.gmane.org
http://dankulp.com/blog
Loading...