dev@jersey.java.net

percent escapes in URI templates

From: Julian Reschke <julian.reschke_at_gmx.de>
Date: Wed, 20 Jun 2007 16:06:48 +0200

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