Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created April 3, 2016 07:34
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/c670f09689229819f77058bbc53d4be5 to your computer and use it in GitHub Desktop.
Save abhirockzz/c670f09689229819f77058bbc53d4be5 to your computer and use it in GitHub Desktop.
Invoking a JAX-RS service in an asynchronous fashion
public Response test() throws Exception{
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("https://api.github.com/search/users?q=abhirockzz");
Invocation.Builder reqBuilder = target.request();
AsyncInvoker asyncInvoker = reqBuilder.async();
Future<Response> futureResp = asyncInvoker.get();
Response response = futureResp.get(); //blocks until client responds or times out
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