Hi

On Thu, Apr 29, 2010 at 7:58 AM, Matthew Glubb <[email protected]> wrote:

> Hi All,
>
> I am having problems with a restful service that I have developed (CXF
> 2.2.7). I want to pass a List<String> value as a PathParam. I can get this
> working as a QueryParam:
>
> @WebService
> @Produces("application/json")
> @Consumes("application/json")
> public interface RestService {
>
>  @GET
>  @Path("/s")
>  Response doSomething(@QueryParam("strings") List<String> s);
> }
>
> using the (truncated) query: /s?strings=s1&strings=s2
>
> However, I'd like to use a PathParam for this. I have tried:
>
> @GET
> @Path("/s/{strings}")
> Response doSomething(@PathParam("strings") List<String> s);
>
> And also:
>
> @GET
> @Path("/s/{strings:.*}")
> Response doSomething(@PathParam("strings") List<String> s);
>
> With the query: /s/s1
>
> Which works fine, but:
>
> With the query: /s/s1;s2
>
> I am still only receive the list [s1] (size 1). I have tried other
> delimiters such as /s/s1+s2 but this results in the list being [s1+s2] (size
> 1).
>
> Does anyone know what I am doing wrong?
>
>
here '/s;s2' is a single 's' path segment, s2 is a matrix parameter.
'/s;s2=1;s2=2' is a single 's' path segment with two identically
named matrix parameters, so you can catch all the 's2' matrix parameters
using @MatrixParam("s2") List<String>, using @Path("/s1") only - is it what
you'd like to do ? Alernatively, you can try to use @PathSegment("s")
parameter and get all the matrix parameters from it, or you can have a
UriInfo context injected into your bean and then query UriInfo inside a
given method for the list of matrix parameters.

or do you have the case where you can have
/s/s1/s2
/s1/s1/s2/s3

etc ?



> Also, on a related note, how do I get my proxy client to submit the list in
> the correct format for the query? I have a Spring configured service and
> client running inside Jetty in my integration tests:
>
> <bean id="restService" class="x.y.z.service.RestServiceImpl" />
>
> <jaxrs:server id="restfulService" address="http://localhost:9002/";>
>  <jaxrs:serviceBeans>
>    <ref bean="restService" />
>  </jaxrs:serviceBeans>
>  <jaxrs:providers>
>    <ref bean="listParamHandler" />
>  </jaxrs:providers>
> </jaxrs:server>
>
> <bean id="restClientFactory"
> class="org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean">
>  <property name="serviceClass" value="x.y.z.service.RestServiceImpl" />
>  <property name="address" value="http://localhost:9002/"; />
> </bean>
>
> <bean id="restServiceClient" class="x.y.z.service.RestServiceImpl"
>  factory-bean="restClientFactory" factory-method="create" />
>
> However, calling:
>
> List<String> strings = new List<String>();
> strings.add("s1");
> strings.add("s2");
> restServiceClient.doSomething(strings);
>
> Results in a call to the server for the URL:
>
> /s/%5Bs1%2C%20s2%5D (/s/[s1, s2])
>
> This is obviously just the result of a List<String>.toString().
>
> So. I have two questions:
>
> 1. What is the correct way to submit a String List via a PathParam to a
> restful web service?
> 2. How can I ensure that my proxy based client conforms to this?
>
>
At the moment, proxy-based clients do not really understand well how to deal
with collections - some enhancements will need to be done. You may find it
easier for now to use WebClients. Altermatively, if what you'd actually like
to use is matrix parameters then you might want consider introducing some
MatrixBean with a List<String> s2 propert and use "@MatrixParam("")
MatrixBean" in your method signature, which will make it possible to use
proxies too



> I've looked into registering a ParameterHandler provider on the server side
> but it doesn't seem to be calling it's fromString method.
>
>
I think it won't do it for Lists given that support for
collections(lists/sets) of named (path/query/matrix) paramers is required by
the spec but I think if you had say List<Foo> and also registered
ParameterHandler<Foo> then you'd see it called...

thanks, Sergey


> Thanks very much for your time,
>
>
> Matt
>
>
> Matthew Glubb
> Technical Partner
>
> email: [email protected]
> phone: 44 (0) 7715 754017
> skype: mglubb
>
> Kite
> http://madebykite.com
>
> --
> GPG: 96FF DE0E 0B7B 37F0 7F8D C54C E285 3D8F 5625 9244
>
>

Reply via email to