users@jersey.java.net

[Jersey] Escaping & (ampersands) in an XML response for links

From: naresh <baliga_naresh_at_yahoo.com>
Date: Wed, 30 Mar 2016 14:24:11 -0700 (MST)

REST responses sometimes contain links or URIs that point a user to
sub-resources.

When query parameters are involved, and the response is XML, what should
happen to & (ampersand) characters that join the query params?

This is what the default encoding looks like:

<url>.../resource/subresource?param1=value1& amp ;param2=value2</url>

The & is escaped to & amp ; which is correct for an XML parser. Note, I've
deliberately inserted spaces so that the message shows up in the forum, as I
intended.

However when the same URL is submitted as a request, @QueryParam("param2")
does not work in capturing the value of the parameter.

Jersey finds that the 2nd parameter is amp;param2 and not param2.
So @QueryParam("amp;param2") will work is the user decides to pick up the
XML url as is and issue a GET.

Or, should the XML response be:
<url>.../resource/subresource?param1=value1 & param2=value2</url>

where the & is not escaped/encoded at all.






--
View this message in context: http://jersey.576304.n2.nabble.com/Escaping-ampersands-in-an-XML-response-for-links-tp7583676.html
Sent from the Jersey mailing list archive at Nabble.com.