aspose file tools*
The moose likes Web Services and the fly likes how to handle ampersand in web service request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "how to handle ampersand in web service request" Watch "how to handle ampersand in web service request" New topic
Author

how to handle ampersand in web service request

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
All,

Is there a way to enforce CDATA usage on a web service client.

What is the best way to handle to values in the web service client payloads which contain special characters. Is there a way we can achieve this in a generic manner and applies to all potential webservice clients.

Thanks In Advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

If you're using XML as the web service payload, then you'll certainly want to escape ampersands in text correctly. However it's unnecessary to use CDATA to do that, so there shouldn't be any reason to require the use of CDATA.

So in other words the generic thing to do is to produce well-formed XML. There isn't any problem with using ampersands in web services (it happens every day where I work).
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Ok. May be I am bit dense on this. What are the alternatives to CDATA approach
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

The alternative is to simply escape the ampersand correctly in an ordinary text node. Any competent piece of XML software will do that automatically when you serialize a document; did you write your own serializer?
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
I don't have control over the web service consumer application side. Some web service client harness are just stringing xml payloads.

But for the ones using web service toolkits for creating web service consumer apps what information can i provide to escape such characters while they generate such payloads.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

You're asking on behalf of your clients who send you malformed XML? The advice to them is the same as to you: Don't do that. Use competent XML-handling software. You can't repair malformed XML, if that's your question.
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
I interpreted your response on "did you write your own serializer" as client side activity to serialize java to xml

On the server side I use Apache CXF framework web services. I did not write any specific serializer.
I am not understanding where can I intersperse the check and fix to make the xml payload well-formed received as part of the request

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to handle ampersand in web service request