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 2013/06/19 18:07:10 UTC
svn commit: r1494675 -
/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/
Author: olegk
Date: Wed Jun 19 16:07:10 2013
New Revision: 1494675
URL: http://svn.apache.org/r1494675
Log:
HTTPCLIENT-1374: Added public default ManagedHttpClientConnection impl
Added:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultManagedHttpClientConnection.java
- copied, changed from r1493402, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java (contents, props changed)
- copied, changed from r1493402, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java
Removed:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java
Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultManagedHttpClientConnection.java (from r1493402, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultManagedHttpClientConnection.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultManagedHttpClientConnection.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java&r1=1493402&r2=1494675&rev=1494675&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultManagedHttpClientConnection.java Wed Jun 19 16:07:10 2013
@@ -28,9 +28,7 @@
package org.apache.http.impl.conn;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InterruptedIOException;
-import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
@@ -40,8 +38,6 @@ import java.util.concurrent.ConcurrentHa
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
-import org.apache.commons.logging.Log;
-import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.config.MessageConstraints;
@@ -52,22 +48,19 @@ import org.apache.http.io.HttpMessagePar
import org.apache.http.io.HttpMessageWriterFactory;
import org.apache.http.protocol.HttpContext;
-class ManagedHttpClientConnectionImpl extends DefaultBHttpClientConnection
+/**
+ * @since 4.3
+ */
+public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnection
implements ManagedHttpClientConnection, HttpContext {
private final String id;
- private final Log log;
- private final Log headerlog;
- private final Wire wire;
private final Map<String, Object> attributes;
private volatile boolean shutdown;
- public ManagedHttpClientConnectionImpl(
+ public DefaultManagedHttpClientConnection(
final String id,
- final Log log,
- final Log headerlog,
- final Log wirelog,
final int buffersize,
final int fragmentSizeHint,
final CharsetDecoder chardecoder,
@@ -81,73 +74,25 @@ class ManagedHttpClientConnectionImpl ex
constraints, incomingContentStrategy, outgoingContentStrategy,
requestWriterFactory, responseParserFactory);
this.id = id;
- this.log = log;
- this.headerlog = headerlog;
- this.wire = new Wire(wirelog, this.id);
this.attributes = new ConcurrentHashMap<String, Object>();
}
- public String getId() {
- return this.id;
+ public DefaultManagedHttpClientConnection(
+ final String id,
+ final int buffersize) {
+ this(id, buffersize, 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();
+ public String getId() {
+ return this.id;
}
@Override
public void shutdown() throws IOException {
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + ": Shutdown connection");
- }
this.shutdown = true;
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());
- final Header[] headers = response.getAllHeaders();
- for (final Header header : headers) {
- this.headerlog.debug(this.id + " << " + header.toString());
- }
- }
- }
-
- @Override
- protected void onRequestSubmitted(final HttpRequest request) {
- if (request != null && this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(id + " >> " + request.getRequestLine().toString());
- final Header[] headers = request.getAllHeaders();
- for (final Header header : headers) {
- this.headerlog.debug(this.id + " >> " + header.toString());
- }
- }
- }
-
public Object getAttribute(final String id) {
return this.attributes.get(id);
}
Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java (from r1493402, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java&r1=1493402&r2=1494675&rev=1494675&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java Wed Jun 19 16:07:10 2013
@@ -27,19 +27,6 @@
package org.apache.http.impl.conn;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InterruptedIOException;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-
import org.apache.commons.logging.Log;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
@@ -52,18 +39,25 @@ import org.apache.http.io.HttpMessagePar
import org.apache.http.io.HttpMessageWriterFactory;
import org.apache.http.protocol.HttpContext;
-class ManagedHttpClientConnectionImpl extends DefaultBHttpClientConnection
- implements ManagedHttpClientConnection, HttpContext {
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+class LoggingManagedHttpClientConnection extends DefaultManagedHttpClientConnection {
- private final String id;
private final Log log;
private final Log headerlog;
private final Wire wire;
- private final Map<String, Object> attributes;
- private volatile boolean shutdown;
-
- public ManagedHttpClientConnectionImpl(
+ public LoggingManagedHttpClientConnection(
final String id,
final Log log,
final Log headerlog,
@@ -77,24 +71,18 @@ class ManagedHttpClientConnectionImpl ex
final ContentLengthStrategy outgoingContentStrategy,
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
- super(buffersize, fragmentSizeHint, chardecoder, charencoder,
+ super(id, buffersize, fragmentSizeHint, chardecoder, charencoder,
constraints, incomingContentStrategy, outgoingContentStrategy,
requestWriterFactory, responseParserFactory);
- this.id = id;
this.log = log;
this.headerlog = headerlog;
- this.wire = new Wire(wirelog, this.id);
- this.attributes = new ConcurrentHashMap<String, Object>();
- }
-
- public String getId() {
- return this.id;
+ this.wire = new Wire(wirelog, id);
}
@Override
public void close() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + ": Close connection");
+ this.log.debug(getId() + ": Close connection");
}
super.close();
}
@@ -102,9 +90,8 @@ class ManagedHttpClientConnectionImpl ex
@Override
public void shutdown() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + ": Shutdown connection");
+ this.log.debug(getId() + ": Shutdown connection");
}
- this.shutdown = true;
super.shutdown();
}
@@ -129,10 +116,10 @@ class ManagedHttpClientConnectionImpl ex
@Override
protected void onResponseReceived(final HttpResponse response) {
if (response != null && this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(this.id + " << " + response.getStatusLine().toString());
+ this.headerlog.debug(getId() + " << " + response.getStatusLine().toString());
final Header[] headers = response.getAllHeaders();
for (final Header header : headers) {
- this.headerlog.debug(this.id + " << " + header.toString());
+ this.headerlog.debug(getId() + " << " + header.toString());
}
}
}
@@ -140,48 +127,12 @@ class ManagedHttpClientConnectionImpl ex
@Override
protected void onRequestSubmitted(final HttpRequest request) {
if (request != null && this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(id + " >> " + request.getRequestLine().toString());
+ this.headerlog.debug(getId() + " >> " + request.getRequestLine().toString());
final Header[] headers = request.getAllHeaders();
for (final Header header : headers) {
- this.headerlog.debug(this.id + " >> " + header.toString());
+ this.headerlog.debug(getId() + " >> " + header.toString());
}
}
}
- public Object getAttribute(final String id) {
- return this.attributes.get(id);
- }
-
- public Object removeAttribute(final String id) {
- return this.attributes.remove(id);
- }
-
- public void setAttribute(final String id, final Object obj) {
- this.attributes.put(id, obj);
- }
-
- @Override
- public void bind(final Socket socket) throws IOException {
- if (this.shutdown) {
- socket.close(); // allow this to throw...
- // ...but if it doesn't, explicitly throw one ourselves.
- throw new InterruptedIOException("Connection already shutdown");
- }
- super.bind(socket);
- }
-
- @Override
- public Socket getSocket() {
- return super.getSocket();
- }
-
- public SSLSession getSSLSession() {
- final Socket socket = super.getSocket();
- if (socket instanceof SSLSocket) {
- return ((SSLSocket) socket).getSession();
- } else {
- return null;
- }
- }
-
}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/LoggingManagedHttpClientConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java?rev=1494675&r1=1494674&r2=1494675&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java Wed Jun 19 16:07:10 2013
@@ -57,7 +57,7 @@ public class ManagedHttpClientConnection
public static final ManagedHttpClientConnectionFactory INSTANCE = new ManagedHttpClientConnectionFactory();
- private final Log log = LogFactory.getLog(ManagedHttpClientConnectionImpl.class);
+ private final Log log = LogFactory.getLog(DefaultManagedHttpClientConnection.class);
private final Log headerlog = LogFactory.getLog("org.apache.http.headers");
private final Log wirelog = LogFactory.getLog("org.apache.http.wire");
@@ -101,7 +101,7 @@ public class ManagedHttpClientConnection
charencoder.onUnmappableCharacter(unmappableInputAction);
}
final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
- return new ManagedHttpClientConnectionImpl(
+ return new LoggingManagedHttpClientConnection(
id,
log,
headerlog,