Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

how to handle ampersand in web service request

 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 27276
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. May be I am bit dense on this. What are the alternatives to CDATA approach
 
Paul Clapham
Marshal
Posts: 27276
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 27276
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
reply
    Bookmark Topic Watch Topic
  • New Topic