Skip to main content

@Path + trailing slashes

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
mirswith
Offline
Joined: 2011-01-13

Hi, first post here. I am not sure if this is a GlassFish question or not but I need to start somewhere.
I have a REST class, something along these lines:
@Path("test")
public class Test{
@GET
@Path("{id:[0-9]*}/partX")
@Produces("application/json")
public String someFunc1(@PathParam("id")long id){ ... do something ..}
@GET
@Path("{id:[0-9]*}/partX/{id2:[0-9]*}")
public String someFunc2(@PathParam("id")long id, @PathParam("id2")long id2){ ... do something ...}
}
Problem is a url with an ending slash on partX without an ID does not match to any function and results in a 404. For example these work:
http://localhost:8080/jaxrs/test/1/partX
http://localhost:8080/jaxrs/test/1/partX/2
But this one does not:
http://localhost:8080/jaxrs/test/1/partX/
Ideally I would like for this last case to be matched to "someFunc1".
Thanks.

-=ben

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mirswith
Offline
Joined: 2011-01-13

Solved it. Just had to fix my regular expressions, I had to change the * to a + since I wanted at least 1 digit for it to be valid.
Thanks for looking.
-=ben