Search in sources :

Example 1 with InputStreamWithEncoding

use of com.adaptris.core.common.InputStreamWithEncoding in project interlok by adaptris.

the class StandardHttpProducer method handleResponse.

private void handleResponse(HttpURLConnection http, AdaptrisMessage reply) throws IOException, InterlokException {
    int responseCode = http.getResponseCode();
    logHeaders("Response Information", http.getResponseMessage(), http.getHeaderFields().entrySet());
    log.trace("Content-Length is " + http.getContentLength());
    if (responseCode < 200 || responseCode > 299) {
        if (ignoreServerResponseCode()) {
            log.trace("Ignoring HTTP Reponse code {}", responseCode);
            responseBody().insert(new InputStreamWithEncoding(http.getErrorStream(), getContentEncoding(http)), reply);
        } else {
            fail(responseCode, new InputStreamWithEncoding(http.getErrorStream(), getContentEncoding(http)));
        }
    } else {
        if (getEncoder() != null) {
            AdaptrisMessage decodedReply = getEncoder().readMessage(http);
            AdaptrisMessageImp.copyPayload(decodedReply, reply);
            reply.getObjectHeaders().putAll(decodedReply.getObjectHeaders());
            reply.setMetadata(decodedReply.getMetadata());
        } else {
            responseBody().insert(new InputStreamWithEncoding(http.getInputStream(), getContentEncoding(http)), reply);
        }
    }
    getResponseHeaderHandler().handle(http, reply);
    reply.addMetadata(new MetadataElement(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE, String.valueOf(http.getResponseCode())));
    reply.addObjectHeader(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE, Integer.valueOf(http.getResponseCode()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStreamWithEncoding(com.adaptris.core.common.InputStreamWithEncoding) MetadataElement(com.adaptris.core.MetadataElement)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 MetadataElement (com.adaptris.core.MetadataElement)1 InputStreamWithEncoding (com.adaptris.core.common.InputStreamWithEncoding)1