Search in sources :

Example 1 with ResponseLogMessageBuilder

use of com.ingenico.connect.gateway.sdk.java.logging.ResponseLogMessageBuilder in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnection method logResponse.

private void logResponse(final HttpResponse response, final String requestId, final long startTime, final CommunicatorLogger logger) {
    final long endTime = System.currentTimeMillis();
    final long duration = endTime - startTime;
    try {
        final int statusCode = response.getStatusLine().getStatusCode();
        final ResponseLogMessageBuilder logMessageBuilder = new ResponseLogMessageBuilder(requestId, statusCode, duration);
        addHeaders(logMessageBuilder, response.getAllHeaders());
        HttpEntity entity = response.getEntity();
        if (entity != null && !entity.isRepeatable()) {
            entity = new BufferedHttpEntity(entity);
            response.setEntity(entity);
        }
        setBody(logMessageBuilder, entity, response.getFirstHeader(HttpHeaders.CONTENT_TYPE));
        logger.log(logMessageBuilder.getMessage());
    } catch (Exception e) {
        logger.log(String.format("An error occurred trying to log response '%s'", requestId), e);
        return;
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) ResponseLogMessageBuilder(com.ingenico.connect.gateway.sdk.java.logging.ResponseLogMessageBuilder) CommunicationException(com.ingenico.connect.gateway.sdk.java.CommunicationException) HttpException(org.apache.http.HttpException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Aggregations

CommunicationException (com.ingenico.connect.gateway.sdk.java.CommunicationException)1 ResponseLogMessageBuilder (com.ingenico.connect.gateway.sdk.java.logging.ResponseLogMessageBuilder)1 IOException (java.io.IOException)1 HttpEntity (org.apache.http.HttpEntity)1 HttpException (org.apache.http.HttpException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)1