On 6.11.2014 13:42, Sergey Beryozkin wrote:
> Hi
>
> When you have something like
>
> @GET
> @Path("UserInfo?top={top}")
> public SympaResponse<UserInfo> getUserInfo(@PathParam("top") int top) ;
>
> what does not work ?
>
> FYI, the above does support the query parameters, may be you did want
>
>
> @GET
> @Path("UserInfo")
> public SympaResponse<UserInfo> getUserInfo(@QueryParam("top") int top);
>
> Cheers, SErgey
>
> On 06/11/14 11:10, Jari Fredrisson wrote:
>> I have a client without parameters and it works.
>>
>> I have defined the service as
>>
>> package ...
>>
>> import javax.ws.rs.GET;
>> import javax.ws.rs.Path;
>> import javax.ws.rs.Produces;
>>
>> @Path("api")
>> @Produces("application/json")
>> public interface SympaService
>> {
>> @GET
>> @Path("UserInfo")
>> SympaResponse<UserInfo> getUserInfo() ;
>>
>> @GET
>> @Path("Absences")
>> SympaResponse<AbsenceInfo> getAbsenceInfo();
>> }
>>
>> I create a client for it like this.
>>
>> public static SympaService getClient(final String url, final
>> Connection conn) throws Exception
>> {
>> JAXRSClientFactoryBean sf = new JAXRSClientFactoryBean();
>> sf.setResourceClass(SympaService.class);
>> sf.setAddress(url);
>> sf.setUsername(SYMPA_USER.get(conn));
>> sf.setPassword(SYMPA_PASS.get(conn));
>>
>> List providers = new ArrayList(1);
>> providers.add(new JacksonJaxbJsonProvider());
>>
>> sf.setProviders(providers);
>>
>> BindingFactoryManager manager =
>> sf.getBus().getExtension(BindingFactoryManager.class);
>> JAXRSBindingFactory factory = new JAXRSBindingFactory();
>>
>> factory.setBus(sf.getBus());
>>
>>
>> manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID,
>> factory);
>> SympaService client = sf.create(SympaService.class);
>> ClientConfiguration config = WebClient.getConfig(client);
>> HTTPConduit conduit = config.getHttpConduit();
>>
>> conduit.getClient().setReceiveTimeout(SYMPA_TIMEOUT.get(conn));
>> return client;
>> }
>>
>> But now I need to add parameters to the service call.
>>
>> I tried
>> @GET
>> @Path("UserInfo?top={top}")
>> SympaResponse<UserInfo> getUserInfo(@PathParam("top") int top) ;
>>
>> call then calling client.getUserInfo(150);
>>
>> But it does not work.
>>
>> I know that I can write the client creation differently and create a
>> WebClient and add the parameters to the URI. But I really would like to
>> make as little as possible changes to the working code. Is anything like
>> what I tried possible?
>>
>> It's so elegant with the Service interface and data type defined and it
>> just runs. But with parameters, no?
>>
>> br. jarif
>>
>>
>
>
Indeed. I did what you suggested with QueryParam on my own, and it just
works.Thanks anyway, I would figured it out with your comment if not on my own. Happy camper!
signature.asc
Description: OpenPGP digital signature
