Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created April 3, 2016 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/3b00c611d41968b2dd3bebfe0ab6c1f8 to your computer and use it in GitHub Desktop.
Save abhirockzz/3b00c611d41968b2dd3bebfe0ab6c1f8 to your computer and use it in GitHub Desktop.
Synchronous invocation of a REST API using JAX-RS Client API
public Response test() throws Exception{
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("http://localhost:8080/jaxrs-async-service/async");
Invocation.Builder reqBuilder = target.request();
Response response = reqBuilder.get(); //this will block until server responds or triggers out (even if its aysnc)
String responseBody = response.readEntity(String.class);
return Response.status(response.getStatus()).entity(responseBody).build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment