dev@jersey.java.net

Fixed <was> Re: percent escapes in URI templates

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 21 Jun 2007 13:45:30 +0200

Hi Julian,

It is fixed in the latest build [1].

See here [2] for a unit test.

For the moment the URI template supports escaped and non-escaped
characters, via URLDecoder.decode(). (The validation code for the URI
template syntax is a bit weak and needs to be improved).

Paul.

[1]
https://jersey.dev.java.net/servlets/ProjectDocumentList?folderID=7653&expandFolder=7653&folderID=0
[2]
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/test/com/sun/ws/rest/impl/container/httpserver/EscapedURITest.java?rev=68&view=markup

Julian Reschke wrote:
> First!
>
> :-)
>
> Hi everybody, and thanks for making this available.
>
> Here's a simple question: I was trying to modify HelloWorldResource to
> put in a name extracted from the URI, such as in:
>
>
> import javax.ws.rs.*;
>
> // The Java class will be hosted at the URI path "/helloworld"
> @UriTemplate("/helloworld/{name}")
> public class HelloWorldResource {
>
> // The Java method will process HTTP GET requests
> @HttpMethod("GET")
> // The Java method will produce content identified by the MIME Media
> // type "text/plain"
> @ProduceMime("text/html")
> public String getClichedMessage(@UriParam("name") String name) {
> // Return some cliched textual content
> return "<i>Hello</i> "+name+"!";
> }
> }
>
> This works fine until I put an escaped space character in, such as in
> "/helloworld/x%20y", and then I get...:
>
> java.lang.IllegalArgumentException
> at java.net.URI.create(URI.java:842)
> at
> com.sun.ws.rest.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:205)
>
> at
> com.sun.ws.rest.impl.container.httpserver.HttpHandlerContainer.handle(HttpHandlerContainer.java:54)
>
> at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
> at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:65)
> at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:68)
> at
> sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:556)
>
> at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
> at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:528)
> at
> sun.net.httpserver.ServerImpl$DefaultExecutor.execute(ServerImpl.java:125)
> at sun.net.httpserver.ServerImpl$Dispatcher.handle(ServerImpl.java:353)
> at sun.net.httpserver.ServerImpl$Dispatcher.run(ServerImpl.java:327)
> at java.lang.Thread.run(Thread.java:595)
> Caused by: java.net.URISyntaxException: Illegal character in path at
> index 12: helloworld/x y
> at java.net.URI$Parser.fail(URI.java:2816)
> at java.net.URI$Parser.checkChars(URI.java:2989)
> at java.net.URI$Parser.parseHierarchical(URI.java:3073)
> at java.net.URI$Parser.parse(URI.java:3031)
> at java.net.URI.<init>(URI.java:578)
> at java.net.URI.create(URI.java:840)
> ... 12 more
>
>
> Bug?
>
> Best regards, Julian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109