enzo 660 wrote:
> Hi,
> I've been trying to use the @Encoded annotation in a resource.
>
> -----------------------------------------------------------------------------------------------------------------
> @Path("/helloworld")
> public class HelloWorldResource {
>
> @GET
> @ProduceMime("text/plain")
> @Path("/encode")
> @Encoded
> public String encodedEcho(@QueryParam("str")String retStr){
> return retStr;
> }
> }
> -----------------------------------------------------------------------------------------------------------------
>
> If I deploy the application in a container (Tomcat) and access the URL
> http://localhost:8888/hello/helloworld/encode?str=af,yt!6%20p#4
> this is what I get af,yt!6%20p.
> I was expecting it to percent encode the special characters. Am I
> missing something here?
>
It is working correctly.
This is the ABNF for the query component:
query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
(The "#4" at the end is the fragment component of the URI and is not
part of the query component.)
But i think there could be a benign encoding issue using the UriBuilder:
System.out.println(
UriBuilder.fromUri("
http://host/").
queryParam("str", "af,yt!6 p#4").build());
prints out:
http://host/?str=af%2Cyt%216+p%234
This is because i am using:
java.net.URLEncoder.encode
that encodes a string to the to the application/x-www-form-urlencoded
MIME format.
Paul.
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109