Search in sources :

Example 1 with HttpMessage

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;
}
Also used : HttpClientTransport(com.adaptris.http.HttpClientTransport) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) HttpSession(com.adaptris.http.HttpSession) OutputStream(java.io.OutputStream) HttpException(com.adaptris.http.HttpException) IOException(java.io.IOException) HttpMessage(com.adaptris.http.HttpMessage) ProduceException(com.adaptris.core.ProduceException)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 CoreException (com.adaptris.core.CoreException)1 ProduceException (com.adaptris.core.ProduceException)1 HttpClientTransport (com.adaptris.http.HttpClientTransport)1 HttpException (com.adaptris.http.HttpException)1 HttpMessage (com.adaptris.http.HttpMessage)1 HttpSession (com.adaptris.http.HttpSession)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1