How to consume servlet ClientResource with URL parameters?

669 Views Asked by At

I have a restlet resource mapped as follows:

router.attach("/activities/{userid}/{criteria}/{value}", ActivitiesResource.class);

I am testing the resource from cmd line with curl and it works OK. Now I want to consume it from another resource. Looking at the documentation, I understand I should be able to do something like this:

// create client resource for the activities
ClientResource clientResource = new ClientResource("http://localhost:8888/myApp/activities/");

// wrap 
IActivitiesResource activitiesResource = clientResource.wrap(IActivitiesResource.class);

// invoke a given method
JsonRepresentation result = activitiesResource.getActivites();

My question (assuming the above looks OK): how do I pass the parameters mapped in the url (userid, criteria, value) to the client resource?

1

There are 1 best solutions below

0
On BEST ANSWER

Well you can add the parameters to the uri that you are passing to the ClientResource. for example:

 ClientResource clientResource = new ClientResource("http://localhost:8888/myApp/activities/123/weight/70");

Hope that helps.