cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID (ATTSI)" <dk0...@att.com>
Subject RE: JAX-RS variable length parameters
Date Tue, 05 Jul 2011 19:28:04 GMT
> -----Original Message-----
> From: AgentSmith [mailto:mydevac@gmail.com]
> Sent: Tuesday, July 05, 2011 11:36 AM
> To: users@cxf.apache.org
> 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&param2=5 - 404
> requested resource () is not available
> etc
> 
> ----------------------------------
> @Path("foo")
> @GET
> public String foo(@Context UriInfo ui){
>   MultivaluedMap&lt;String, String&gt; queryParams =
> ui.getQueryParameters();
>   MultivaluedMap&lt;String, String&gt; 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.


Mime
View raw message