> -----Original Message-----
> From: AgentSmith [mailto:[email protected]]
> Sent: Tuesday, July 05, 2011 11:36 AM
> To: [email protected]
> Subject: JAX-RS variable length parameters
>
> How do I define @Path to except variable length parameters as part of
> my
> end-point. For example, I would like to be able to make the following
> requests for the same end-points:
>
> http://whatever.com/MyWS/mywebservices/foo - works
> http://whatever.com/MyWS/mywebservices/foo/1 - 404 requested resource
> () is
> not available
> http://whatever.com/MyWS/mywebservices/foo/1/2 - 404 requested
> resource ()
> is not available
> http://whatever.com/MyWS/mywebservices/foo/1/2/3 - 404 requested
> resource
> () is not available
> http://whatever.com/MyWS/mywebservices/foo?param1=10 - works
> http://whatever.com/MyWS/mywebservices/foo/1/2?param1=20¶m2=5 - 404
> requested resource () is not available
> etc
>
> ----------------------------------
> @Path("foo")
> @GET
> public String foo(@Context UriInfo ui){
> MultivaluedMap<String, String> queryParams =
> ui.getQueryParameters();
> MultivaluedMap<String, String> pathParams =
> ui.getPathParameters();
>
> return "foo(): " + queryParams.size() + ", " + pathParams.size();
> }
Your first problem is getting the Path expression to match your URI. As far as
I know, the only practical way to do this is to specify a "catch-all
expression" in the URI.
For instance, the following:
@Path("{id:.*}")
Will provide the "id" parameter with the entire path info. The drawback is
that you may have to manually parse the data you have.