~ubuntu-branches/ubuntu/trusty/httpcomponents-core/trusty

« back to all changes in this revision

Viewing changes to contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-06-12 08:37:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100612083734-1y8kp6qm4sjk60az
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java $
 
3
 * $Revision: 660237 $
 
4
 * $Date: 2008-05-26 19:25:36 +0200 (Mon, 26 May 2008) $
 
5
 *
 
6
 * ====================================================================
 
7
 * Licensed to the Apache Software Foundation (ASF) under one
 
8
 * or more contributor license agreements.  See the NOTICE file
 
9
 * distributed with this work for additional information
 
10
 * regarding copyright ownership.  The ASF licenses this file
 
11
 * to you under the Apache License, Version 2.0 (the
 
12
 * "License"); you may not use this file except in compliance
 
13
 * with the License.  You may obtain a copy of the License at
 
14
 *
 
15
 *   http://www.apache.org/licenses/LICENSE-2.0
 
16
 *
 
17
 * Unless required by applicable law or agreed to in writing,
 
18
 * software distributed under the License is distributed on an
 
19
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
20
 * KIND, either express or implied.  See the License for the
 
21
 * specific language governing permissions and limitations
 
22
 * under the License.
 
23
 * ====================================================================
 
24
 *
 
25
 * This software consists of voluntary contributions made by many
 
26
 * individuals on behalf of the Apache Software Foundation.  For more
 
27
 * information on the Apache Software Foundation, please see
 
28
 * <http://www.apache.org/>.
 
29
 *
 
30
 */
 
31
 
 
32
package org.apache.http.contrib.logging;
 
33
 
 
34
import java.io.IOException;
 
35
 
 
36
import org.apache.commons.logging.Log;
 
37
import org.apache.commons.logging.LogFactory;
 
38
import org.apache.http.Header;
 
39
import org.apache.http.HttpException;
 
40
import org.apache.http.HttpRequest;
 
41
import org.apache.http.HttpResponseFactory;
 
42
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 
43
import org.apache.http.nio.NHttpClientHandler;
 
44
import org.apache.http.nio.reactor.IOSession;
 
45
import org.apache.http.nio.util.ByteBufferAllocator;
 
46
import org.apache.http.params.HttpParams;
 
47
 
 
48
public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
 
49
 
 
50
    private final Log log;
 
51
    private final Log headerlog;
 
52
    
 
53
    public LoggingNHttpClientConnection(
 
54
        final IOSession session,
 
55
        final HttpResponseFactory responseFactory,
 
56
        final ByteBufferAllocator allocator,
 
57
        final HttpParams params) {
 
58
        super(session, responseFactory, allocator, params);
 
59
        this.log = LogFactory.getLog(getClass());
 
60
        this.headerlog = LogFactory.getLog("org.apache.http.headers");
 
61
    }
 
62
 
 
63
    public void close() throws IOException {
 
64
        this.log.debug("Close connection");        
 
65
        super.close();
 
66
    }
 
67
 
 
68
    public void shutdown() throws IOException {
 
69
        this.log.debug("Shutdown connection");        
 
70
        super.shutdown();
 
71
    }
 
72
 
 
73
    public void submitRequest(final HttpRequest request) throws IOException, HttpException {
 
74
        if (this.log.isDebugEnabled()) {
 
75
            this.log.debug("HTTP connection " + this + ": "  + request.getRequestLine().toString());
 
76
        }
 
77
        super.submitRequest(request);
 
78
        if (this.headerlog.isDebugEnabled()) {
 
79
            this.headerlog.debug(">> " + request.getRequestLine().toString());
 
80
            Header[] headers = request.getAllHeaders();
 
81
            for (int i = 0; i < headers.length; i++) {
 
82
                this.headerlog.debug(">> " + headers[i].toString());
 
83
            }
 
84
        }
 
85
    }
 
86
 
 
87
    public void consumeInput(final NHttpClientHandler handler) {
 
88
        this.log.debug("Consume input");        
 
89
        super.consumeInput(handler);
 
90
    }
 
91
 
 
92
    public void produceOutput(final NHttpClientHandler handler) {
 
93
        this.log.debug("Produce output");        
 
94
        super.produceOutput(handler);
 
95
    }
 
96
    
 
97
}
 
 
b'\\ No newline at end of file'