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: http://n2.nabble.com/Problem-for-resource-names-conflicting-with-URI-extensions-tp3553608p3553608.html
Sent from the Jersey mailing list archive at Nabble.com.