Created
April 3, 2016 07:34
-
-
Save abhirockzz/c670f09689229819f77058bbc53d4be5 to your computer and use it in GitHub Desktop.
Invoking a JAX-RS service in an asynchronous fashion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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