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 $
4
* $Date: 2008-05-26 19:25:36 +0200 (Mon, 26 May 2008) $
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
15
* http://www.apache.org/licenses/LICENSE-2.0
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
23
* ====================================================================
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/>.
32
package org.apache.http.contrib.logging;
34
import java.io.IOException;
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;
48
public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
50
private final Log log;
51
private final Log headerlog;
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");
63
public void close() throws IOException {
64
this.log.debug("Close connection");
68
public void shutdown() throws IOException {
69
this.log.debug("Shutdown connection");
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());
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());
87
public void consumeInput(final NHttpClientHandler handler) {
88
this.log.debug("Consume input");
89
super.consumeInput(handler);
92
public void produceOutput(final NHttpClientHandler handler) {
93
this.log.debug("Produce output");
94
super.produceOutput(handler);
b'\\ No newline at end of file'