Search in sources :

Example 1 with RequestLogMessageBuilder

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

the class DefaultConnection method logRequest.

// logging code
private void logRequest(final HttpRequest request, final String requestId, final CommunicatorLogger logger) {
    try {
        RequestLine requestLine = request.getRequestLine();
        String method = requestLine.getMethod();
        String uri = requestLine.getUri();
        final RequestLogMessageBuilder logMessageBuilder = new RequestLogMessageBuilder(requestId, method, uri);
        addHeaders(logMessageBuilder, request.getAllHeaders());
        if (request instanceof HttpEntityEnclosingRequest) {
            final HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) request;
            HttpEntity entity = entityEnclosingRequest.getEntity();
            if (entity != null && !entity.isRepeatable()) {
                entity = new BufferedHttpEntity(entity);
                entityEnclosingRequest.setEntity(entity);
            }
            setBody(logMessageBuilder, entity, request.getFirstHeader(HttpHeaders.CONTENT_TYPE));
        }
        logger.log(logMessageBuilder.getMessage());
    } catch (Exception e) {
        logger.log(String.format("An error occurred trying to log request '%s'", requestId), e);
        return;
    }
}
Also used : RequestLine(org.apache.http.RequestLine) HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) RequestLogMessageBuilder(com.ingenico.connect.gateway.sdk.java.logging.RequestLogMessageBuilder) 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 RequestLogMessageBuilder (com.ingenico.connect.gateway.sdk.java.logging.RequestLogMessageBuilder)1 IOException (java.io.IOException)1 HttpEntity (org.apache.http.HttpEntity)1 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)1 HttpException (org.apache.http.HttpException)1 RequestLine (org.apache.http.RequestLine)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)1