cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jari Fredrisson <ja...@iki.fi>
Subject Is there an easy way to configure a CFX RESTful client with URL parameters.
Date Thu, 06 Nov 2014 11:10:21 GMT
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



Mime
View raw message