use of org.apache.http.impl.client.HttpRequestFutureTask in project cas by apereo.
the class SimpleHttpClient method sendMessageToEndPoint.
@Override
public boolean sendMessageToEndPoint(final HttpMessage message) {
Assert.notNull(this.httpClient);
try {
final HttpPost request = new HttpPost(message.getUrl().toURI());
request.addHeader("Content-Type", message.getContentType());
final StringEntity entity = new StringEntity(message.getMessage(), ContentType.create(message.getContentType()));
request.setEntity(entity);
final ResponseHandler<Boolean> handler = response -> response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
LOGGER.debug("Created HTTP post message payload [{}]", request);
final HttpRequestFutureTask<Boolean> task = this.requestExecutorService.execute(request, HttpClientContext.create(), handler);
if (message.isAsynchronous()) {
return true;
}
return task.get();
} catch (final RejectedExecutionException e) {
LOGGER.warn(e.getMessage(), e);
return false;
} catch (final Exception e) {
LOGGER.debug(e.getMessage(), e);
return false;
}
}
Aggregations