You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/11/28 14:35:03 UTC
svn commit: r1414672 - in
/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn:
ClientConnectionImpl.java DefaultClientConnection.java
LoggingInputStream.java LoggingOutputStream.java
LoggingSessionInputBuffer.java Wire.java
Author: olegk
Date: Wed Nov 28 13:35:01 2012
New Revision: 1414672
URL: http://svn.apache.org/viewvc?rev=1414672&view=rev
Log:
DefaultClientConnection deprecated in favor of package private ClientConnectionImpl
Added:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java (with props)
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java?rev=1414672&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java Wed Nov 28 13:35:01 2012
@@ -0,0 +1,136 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.config.MessageConstraints;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.impl.DefaultBHttpClientConnection;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.HttpMessageWriterFactory;
+
+class ClientConnectionImpl extends DefaultBHttpClientConnection {
+
+ private static final AtomicLong COUNT = new AtomicLong();
+
+ private final String id;
+ private final Log log;
+ private final Log headerlog;
+ private final Wire wire;
+
+ public ClientConnectionImpl(
+ int buffersize,
+ final CharsetDecoder chardecoder,
+ final CharsetEncoder charencoder,
+ final MessageConstraints constraints,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
+ final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
+ super(buffersize, chardecoder, charencoder,
+ constraints, incomingContentStrategy, outgoingContentStrategy,
+ requestWriterFactory, responseParserFactory);
+ this.id = "http-outgoing-" + COUNT.incrementAndGet();
+ this.log = LogFactory.getLog(getClass());
+ this.headerlog = LogFactory.getLog("org.apache.http.headers");
+ this.wire = new Wire(LogFactory.getLog("org.apache.http.wire"), this.id);
+ }
+
+ public ClientConnectionImpl(int buffersize) {
+ this(buffersize, null, null, null, null, null, null, null);
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + ": Close connection");
+ }
+ super.close();
+ }
+
+ @Override
+ public void shutdown() throws IOException {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + ": Shutdown connection");
+ }
+ super.shutdown();
+ }
+
+ @Override
+ protected InputStream getSocketInputStream(final Socket socket) throws IOException {
+ InputStream in = super.getSocketInputStream(socket);
+ if (this.wire.enabled()) {
+ in = new LoggingInputStream(in, this.wire);
+ }
+ return in;
+ }
+
+ @Override
+ protected OutputStream getSocketOutputStream(final Socket socket) throws IOException {
+ OutputStream out = super.getSocketOutputStream(socket);
+ if (this.wire.enabled()) {
+ out = new LoggingOutputStream(out, this.wire);
+ }
+ return out;
+ }
+
+ @Override
+ protected void onResponseReceived(final HttpResponse response) {
+ if (response != null && this.headerlog.isDebugEnabled()) {
+ this.headerlog.debug(this.id + " << " + response.getStatusLine().toString());
+ Header[] headers = response.getAllHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ this.headerlog.debug(this.id + " << " + headers[i].toString());
+ }
+ }
+ }
+
+ @Override
+ protected void onRequestSubmitted(final HttpRequest request) {
+ if (request != null && this.headerlog.isDebugEnabled()) {
+ this.headerlog.debug(id + " >> " + request.getRequestLine().toString());
+ Header[] headers = request.getAllHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ this.headerlog.debug(this.id + " >> " + headers[i].toString());
+ }
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ClientConnectionImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java?rev=1414672&r1=1414671&r2=1414672&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java Wed Nov 28 13:35:01 2012
@@ -59,21 +59,14 @@ import org.apache.http.conn.OperatedClie
/**
* Default implementation of an operated client connection.
- * <p>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- * <li>{@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}</li>
- * <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
- * <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- * <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- * <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- * </ul>
*
* @since 4.0
+ *
+ * @deprecated (4.3) deprecated in favor of {@link ClientConnectionImpl}.
*/
@SuppressWarnings("deprecation")
@NotThreadSafe // connSecure, targetHost
+@Deprecated
public class DefaultClientConnection extends SocketHttpClientConnection
implements OperatedClientConnection, HttpSSLConnection, HttpContext {
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java?rev=1414672&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java Wed Nov 28 13:35:01 2012
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @since 4.3
+ */
+public class LoggingInputStream extends InputStream {
+
+ private final InputStream in;
+ private final Wire wire;
+
+ public LoggingInputStream(final InputStream in, final Wire wire) {
+ super();
+ this.in = in;
+ this.wire = wire;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int b = in.read();
+ if (b != -1) {
+ wire.input(b);
+ }
+ return b;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ int bytesRead = in.read(b);
+ if (bytesRead != -1) {
+ wire.input(b, 0, bytesRead);
+ }
+ return bytesRead;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int bytesRead = in.read(b, off, len);
+ if (bytesRead != -1) {
+ wire.input(b, off, bytesRead);
+ }
+ return bytesRead;
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ return super.skip(n);
+ }
+
+ @Override
+ public int available() throws IOException {
+ return in.available();
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ super.mark(readlimit);
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ super.reset();
+ }
+
+ @Override
+ public boolean markSupported() {
+ return false;
+ }
+
+ @Override
+ public void close() throws IOException {
+ in.close();
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java?rev=1414672&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java Wed Nov 28 13:35:01 2012
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * @since 4.3
+ */
+public class LoggingOutputStream extends OutputStream {
+
+ private final OutputStream out;
+ private final Wire wire;
+
+ public LoggingOutputStream(final OutputStream out, final Wire wire) {
+ super();
+ this.out = out;
+ this.wire = wire;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ wire.output(b);
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException {
+ wire.output(b);
+ out.write(b);
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ wire.output(b, off, len);
+ out.write(b, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java?rev=1414672&r1=1414671&r2=1414672&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java Wed Nov 28 13:35:01 2012
@@ -39,10 +39,12 @@ import org.apache.http.util.CharArrayBuf
/**
* Logs all data read to the wire LOG.
*
- *
* @since 4.0
+ *
+ * @deprecated (4.3) no longer used.
*/
@Immutable
+@Deprecated
public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor {
/** Original session input buffer. */
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java?rev=1414672&r1=1414671&r2=1414672&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/Wire.java Wed Nov 28 13:35:01 2012
@@ -36,7 +36,7 @@ import org.apache.commons.logging.Log;
/**
* Logs data to the wire LOG.
- *
+ * TODO: make package private. Should not be part of the public API.
*
* @since 4.0
*/
@@ -44,9 +44,18 @@ import org.apache.commons.logging.Log;
public class Wire {
private final Log log;
+ private final String id;
- public Wire(Log log) {
+ /**
+ * @since 4.3
+ */
+ public Wire(Log log, String id) {
this.log = log;
+ this.id = id;
+ }
+
+ public Wire(Log log) {
+ this(log, "");
}
private void wire(String header, InputStream instream)
@@ -60,7 +69,7 @@ public class Wire {
buffer.append("[\\n]\"");
buffer.insert(0, "\"");
buffer.insert(0, header);
- log.debug(buffer.toString());
+ log.debug(id + " " + buffer.toString());
buffer.setLength(0);
} else if ((ch < 32) || (ch > 127)) {
buffer.append("[0x");
@@ -74,7 +83,7 @@ public class Wire {
buffer.append('\"');
buffer.insert(0, '\"');
buffer.insert(0, header);
- log.debug(buffer.toString());
+ log.debug(id + " " + buffer.toString());
}
}