users@jersey.java.net

Re: [Jersey] Problem for resource names conflicting with URI extensions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 31 Aug 2009 16:22:54 +0200

Hi Matteo,

Another developer recently found the same issue, see:

   https://jersey.dev.java.net/issues/show_bug.cgi?id=355

It is fixed in the 1.1.2-ea release:

   https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.1.2-ea/jersey/changes.txt

Paul.

On Aug 31, 2009, at 4:03 PM, matteo.cajani wrote:

> Hello to everyone, I'm an enthusiast user of Jersey and this is my
> first post in this mailing list. I would like to share with you a
> problem we recently faced when using URI extensions: the algorithm
> for the URI extension resolution (implemented in
> com.sun.jersey.server.impl.application.WebApplicationImpl) searches
> for URI extensions in the last part of the URI (ie after the last
> “/”) in the following way: public final class WebApplicationImpl
> implements WebApplication { … private void uriConneg(StringBuilder
> path, ContainerRequest request) { int si = path.lastIndexOf("/"); //
> Path ends in slash if (si == path.length() - 1) { // Find the next
> slash si = path.lastIndexOf("/", si - 1); } // If no slash that set
> to start of path if (si == -1) { si = 0; } MediaType accept = null;
> for (Map.Entry e : resourceConfig.getMediaTypeMappings().entrySet())
> { int i = path.indexOf(e.getKey(), si); if (i > 0 && (path.charAt(i
> - 1) == '.')) { int lengthWithExt = i + e.getKey().length(); if
> (lengthWithExt == path.length()) { accept = e.getValue();
> path.delete(i - 1, lengthWithExt); } else { char charAfterExt =
> path.charAt(lengthWithExt); if (('/' == charAfterExt) || ('.' ==
> charAfterExt)) { accept = e.getValue(); path.delete(i - 1,
> lengthWithExt); } } } } ... This algorithm can cause a problem if a
> resource name contains a sequence of characters that matches with
> some URI extensions, here it’s an example: Request: GET http://my.website.com/myjerseyapp/resources/user/ajsonbar.json
> Jersey method: @Path("user") public class UserResource { … @GET
> @Path("{userId}") public User
> getCurrentUserStatus(@PathParam("userId") final String _userId)
> { … //for the request http://my.website.com/myjerseyapp/resources/user/ajsonbar.json
> _userId will be “ajsonbar.json” and not “ajsonbar” because of the
> indexOf research } … } Is this a known issue? Will be fixed in
> future Jersey releases or can we contribute with a solution? Best
> regards, Matteo
> View this message in context: Problem for resource names conflicting
> with URI extensions
> Sent from the Jersey mailing list archive at Nabble.com.