Last active
August 31, 2016 00:57
-
-
Save MaxDavila/11c2a71f8c1ff1c0417acf237d2dda3f to your computer and use it in GitHub Desktop.
Calling external service from qa and sbx
This file contains hidden or 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 TimedHttpResponse send(final HttpRequestBase request, Header ... additionalHeaders) throws TimedHttpCommunicationException { | |
String uriString = request.getURI().toString(); | |
//set additional headers if any | |
request.setHeader("Accept", "application/json"); | |
//let's run the actual http execution in another thread then wait for it | |
Future<HttpResponse> task = timeoutService.submit(new Callable<HttpResponse>() { | |
@Override | |
public HttpResponse call() throws Exception { | |
HttpResponse response = execute(request); | |
if (aborted.get()) { | |
//if we got aborted, we need to consume the response entity | |
//this will trigger a cleanup of the stream in addition to closing it | |
EntityUtils.consumeQuietly(response.getEntity()); | |
} | |
return response; | |
} | |
}); | |
HttpResponse httpResponse = task.get(timeoutMillis, TimeUnit.MILLISECONDS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment