use of com.adaptris.http.HttpMessage in project interlok by adaptris.
the class SimpleHttpProducer method doRequest.
@Override
protected AdaptrisMessage doRequest(AdaptrisMessage msg, String destination, long timeout) throws ProduceException {
AdaptrisMessage reply = defaultIfNull(getMessageFactory()).newMessage();
OutputStream out = null;
try {
HttpClientConnection c = retrieveConnection(HttpClientConnection.class);
HttpClientTransport client = c.initialiseClient(destination);
client.setMethod(getMethod());
HttpMessage m = HttpMessageFactory.getDefaultInstance().create();
applyHeaders(getAdditionalHeaders(msg), m);
if (getContentTypeKey() != null && msg.containsKey(getContentTypeKey())) {
m.getHeaders().put(Http.CONTENT_TYPE, msg.getMetadataValue(getContentTypeKey()));
}
if (getAuthorisation() != null) {
m.getHeaders().put(Http.AUTHORIZATION, getAuthorisation());
}
if (getEncoder() != null) {
getEncoder().writeMessage(msg, m);
} else {
out = m.getOutputStream();
out.write(msg.getPayload());
out.flush();
}
HttpSession httpSession = client.send(m, new Long(timeout).intValue(), handleRedirection());
readResponse(httpSession, reply);
httpSession.close();
} catch (HttpException e) {
throw new ProduceException(e);
} catch (IOException e) {
throw new ProduceException(e);
} catch (CoreException e) {
throw new ProduceException(e);
}
return reply;
}
Aggregations