users@jsr311.java.net

How to handle encoded URIs (JAX-RS 0.8)

From: Sergey Beryozkin <sergey.beryozkin_at_progress.com>
Date: Fri, 17 Oct 2008 17:39:05 +0100

Hi

At the moment we have problems handling encoded URIs in CXF JAX-RS implementation, which for now depends on
0.8 api.

I'd like to clarify few things.

Consider this resource class :
@Path("/bookstore")
public class Bookstore {

 @GET
 @Path("/books/{URL}")
  public Book getBookByURL(@PathParam("URL") String url) {
       return getBook(url);
  }

}

Now consider this GET request :
http://localhost:9080/bookstore/books/http%3A%2F%2Fbooks.com%2Fid%2F123

Before a root resource class is resolved a fully decoded URI is returned by the underlying HTTP stack (Jetty in my example) :

/bookstore/books/http://books.com/id/123

According to the section 3.7.3 (June 2008 spec edition), the last template variable on the @Path("/books/{URL}") gets replaced by
"([^/]+?)" group expression.

As such, this pattern is used to find the method, after the root class has been resolved :

/bookurl/([^/]+?)(/.*)?

hence when applied, I have 2 groups as a result

first group : 'http:'
final group : '//books.com/id/123'

As the final group is neither null nor '/', the match can not be done

Can you please advise me on how this can be fixed or what I'm missing ? I know in the final api an arbitrary reg expression can be
specified. but there should be a simple way to do it right in 0.8 spec too ?

Thanks, Sergey