How to perform HTTP-GET from wink client, using path parameter?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to perform HTTP-GET from wink client, using path parameter?

Chris Wolf
I've seen plenty examples of performing an HTTP GET via Wink client,
but no example using a path parameter.  I cannot get this to work. The
documentation only shows the server-side code, not client:
http://wink.apache.org/1.0/html/JAX-RS%20Parameters.html

The only thing I could come up with is recreating the Resource, for
each unique parameter value, e.g.

Resource resource =
client.resource("http://localhost:9080/ws/api/getuserbyid/0123456789abcdef");

ClientResponse response = resource
   .contentType("application/json")
   .accept("application/json")
   .get();
    og.info(response.getEntity(String.class));

Isn't there some way to parameterize the last path component?

Thanks,

Chris Wolf
Reply | Threaded
Open this post in threaded view
|

Re: How to perform HTTP-GET from wink client, using path parameter?

Brian Laskey
Hello Chris,

I know this may not be elegant, but the simple solution our team uses, is that we simply construct the String argument for the client.resource() method on the fly for each request.

E.g.
client.resource("http://server/path/to/resource/"+someId);

This has worked for us in wide variety of test code and client code for our API.

Regards,
Brian

On Fri, Feb 20, 2015 at 11:00 AM, Chris Wolf <[hidden email]> wrote:
I've seen plenty examples of performing an HTTP GET via Wink client,
but no example using a path parameter.  I cannot get this to work. The
documentation only shows the server-side code, not client:
http://wink.apache.org/1.0/html/JAX-RS%20Parameters.html

The only thing I could come up with is recreating the Resource, for
each unique parameter value, e.g.

Resource resource =
client.resource("http://localhost:9080/ws/api/getuserbyid/0123456789abcdef");

ClientResponse response = resource
   .contentType("application/json")
   .accept("application/json")
   .get();
    og.info(response.getEntity(String.class));

Isn't there some way to parameterize the last path component?

Thanks,

Chris Wolf

Reply | Threaded
Open this post in threaded view
|

Re: How to perform HTTP-GET from wink client, using path parameter?

Antonio Alves
In reply to this post by Chris Wolf
If you can use UriBuilder (http://docs.oracle.com/javaee/6/api/index.html?javax/ws/rs/core/UriBuilder.html ) depending of you wink version,

you write :
UriBuilder builder = UriBuilder.fromUri("http://localhost:9080/ws/api")
.path("getuserbyid")
.path("{userId}");
RestClient client = new RestClient();
Resource res = client.resource( builder.build("0123456789abcdef") );


On Fri, Feb 20, 2015 at 5:00 PM, Chris Wolf <[hidden email]> wrote:
I've seen plenty examples of performing an HTTP GET via Wink client,
but no example using a path parameter.  I cannot get this to work. The
documentation only shows the server-side code, not client:
http://wink.apache.org/1.0/html/JAX-RS%20Parameters.html

The only thing I could come up with is recreating the Resource, for
each unique parameter value, e.g.

Resource resource =
client.resource("http://localhost:9080/ws/api/getuserbyid/0123456789abcdef");

ClientResponse response = resource
   .contentType("application/json")
   .accept("application/json")
   .get();
    og.info(response.getEntity(String.class));

Isn't there some way to parameterize the last path component?

Thanks,

Chris Wolf