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 2017/09/01 18:15:30 UTC
[6/6] httpcomponents-client git commit: Logging improvements
Logging improvements
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/e8f72b7c
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/e8f72b7c
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/e8f72b7c
Branch: refs/heads/master
Commit: e8f72b7c57e353b7fb1cc164f6f5c8e8bc8cbf28
Parents: 1eb2218
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Sep 1 20:11:04 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Sep 1 20:11:04 2017 +0200
----------------------------------------------------------------------
.../hc/client5/http/impl/ConnPoolSupport.java | 2 +
.../org/apache/hc/client5/http/impl/Wire.java | 177 ++++++++++++
.../HttpAsyncClientEventHandlerFactory.java | 2 -
.../impl/async/InternalHttpAsyncClient.java | 2 +-
.../client5/http/impl/async/LogAppendable.java | 78 ++++++
.../http/impl/async/LoggingIOSession.java | 270 +++++++++++++++++++
.../io/DefaultManagedHttpClientConnection.java | 1 -
.../http/impl/io/LoggingInputStream.java | 139 ++++++++++
.../http/impl/io/LoggingOutputStream.java | 104 +++++++
.../http/impl/io/LoggingSocketHolder.java | 57 ++++
.../io/PoolingHttpClientConnectionManager.java | 13 +-
...olingHttpClientConnectionManagerBuilder.java | 12 -
.../http/impl/logging/LogAppendable.java | 78 ------
.../http/impl/logging/LoggingIOSession.java | 269 ------------------
.../http/impl/logging/LoggingInputStream.java | 137 ----------
.../http/impl/logging/LoggingOutputStream.java | 102 -------
.../http/impl/logging/LoggingSocketHolder.java | 56 ----
.../hc/client5/http/impl/logging/Wire.java | 175 ------------
.../PoolingAsyncClientConnectionManager.java | 8 +-
...lingAsyncClientConnectionManagerBuilder.java | 14 +-
20 files changed, 837 insertions(+), 859 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
index e6650a4..3de413c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
@@ -27,10 +27,12 @@
package org.apache.hc.client5.http.impl;
import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.pool.ConnPoolControl;
import org.apache.hc.core5.pool.PoolStats;
import org.apache.hc.core5.util.Identifiable;
+@Internal
public final class ConnPoolSupport {
public static String getId(final Object object) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
new file mode 100644
index 0000000..fd48ebd
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
@@ -0,0 +1,177 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl;
+
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.annotation.Internal;
+import org.apache.hc.core5.util.Args;
+import org.apache.logging.log4j.Logger;
+
+@Internal
+public class Wire {
+
+ private static final int MAX_STRING_BUILDER_SIZE = 2048;
+
+ private static final ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
+
+ /**
+ * Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
+ *
+ * @return a {@code StringBuilder}
+ */
+ private static StringBuilder getStringBuilder() {
+ StringBuilder result = threadLocal.get();
+ if (result == null) {
+ result = new StringBuilder(MAX_STRING_BUILDER_SIZE);
+ threadLocal.set(result);
+ }
+ // TODO Delegate to Log4j's 2.9 StringBuilds.trimToMaxSize() when it is released.
+ trimToMaxSize(result, MAX_STRING_BUILDER_SIZE);
+ result.setLength(0);
+ return result;
+ }
+
+ /**
+ * Ensures that the char[] array of the specified StringBuilder does not exceed the specified number of characters.
+ * This method is useful to ensure that excessively long char[] arrays are not kept in memory forever.
+ *
+ * @param stringBuilder the StringBuilder to check
+ * @param maxSize the maximum number of characters the StringBuilder is allowed to have
+ */
+ // TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
+ private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) {
+ if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
+ stringBuilder.setLength(maxSize);
+ stringBuilder.trimToSize();
+ }
+ }
+
+ private final Logger log;
+ private final String id;
+
+ public Wire(final Logger log, final String id) {
+ super();
+ this.log = log;
+ this.id = id;
+ }
+
+ private void wire(final String header, final byte[] b, final int pos, final int off) {
+ final StringBuilder buffer = getStringBuilder();
+ for (int i = 0; i < off; i++) {
+ final int ch = b[pos + i];
+ if (ch == 13) {
+ buffer.append("[\\r]");
+ } else if (ch == 10) {
+ buffer.append("[\\n]\"");
+ buffer.insert(0, "\"");
+ buffer.insert(0, header);
+ this.log.debug(this.id + " " + buffer.toString());
+ buffer.setLength(0);
+ } else if ((ch < 32) || (ch > 127)) {
+ buffer.append("[0x");
+ buffer.append(Integer.toHexString(ch));
+ buffer.append("]");
+ } else {
+ buffer.append((char) ch);
+ }
+ }
+ if (buffer.length() > 0) {
+ buffer.append('\"');
+ buffer.insert(0, '\"');
+ buffer.insert(0, header);
+ this.log.debug(this.id + " " + buffer.toString());
+ }
+ }
+
+
+ public boolean isEnabled() {
+ return this.log.isDebugEnabled();
+ }
+
+ public void output(final byte[] b, final int pos, final int off) {
+ Args.notNull(b, "Output");
+ wire(">> ", b, pos, off);
+ }
+
+ public void input(final byte[] b, final int pos, final int off) {
+ Args.notNull(b, "Input");
+ wire("<< ", b, pos, off);
+ }
+
+ public void output(final byte[] b) {
+ Args.notNull(b, "Output");
+ output(b, 0, b.length);
+ }
+
+ public void input(final byte[] b) {
+ Args.notNull(b, "Input");
+ input(b, 0, b.length);
+ }
+
+ public void output(final int b) {
+ output(new byte[] {(byte) b});
+ }
+
+ public void input(final int b) {
+ input(new byte[] {(byte) b});
+ }
+
+ public void output(final String s) {
+ Args.notNull(s, "Output");
+ output(s.getBytes());
+ }
+
+ public void input(final String s) {
+ Args.notNull(s, "Input");
+ input(s.getBytes());
+ }
+
+ public void output(final ByteBuffer b) {
+ Args.notNull(b, "Output");
+ if (b.hasArray()) {
+ output(b.array(), b.arrayOffset() + b.position(), b.remaining());
+ } else {
+ final byte[] tmp = new byte[b.remaining()];
+ b.get(tmp);
+ output(tmp);
+ }
+ }
+
+ public void input(final ByteBuffer b) {
+ Args.notNull(b, "Input");
+ if (b.hasArray()) {
+ input(b.array(), b.arrayOffset() + b.position(), b.remaining());
+ } else {
+ final byte[] tmp = new byte[b.remaining()];
+ b.get(tmp);
+ input(tmp);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
index 1419b44..95d9267 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
@@ -32,8 +32,6 @@ import java.util.Iterator;
import java.util.List;
import org.apache.hc.client5.http.impl.ConnPoolSupport;
-import org.apache.hc.client5.http.impl.logging.LogAppendable;
-import org.apache.hc.client5.http.impl.logging.LoggingIOSession;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
index d001458..c6f0d93 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
@@ -248,7 +248,7 @@ class InternalHttpAsyncClient extends AbstractHttpAsyncClientBase {
final HttpHost target = routePlanner.determineTargetHost(request, clientContext);
final HttpRoute route = routePlanner.determineRoute(target, clientContext);
- final String exchangeId = "ex-" + Long.toHexString(ExecSupport.getNextExecNumber());
+ final String exchangeId = String.format("ex-%08X", ExecSupport.getNextExecNumber());
final AsyncExecRuntime execRuntime = new AsyncExecRuntimeImpl(log, connmgr, getConnectionInitiator(), versionPolicy);
executeChain(exchangeId, execChain, route, request, entityDetails, exchangeHandler, clientContext, execRuntime);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java
new file mode 100644
index 0000000..5d5070d
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java
@@ -0,0 +1,78 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl.async;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.Logger;
+
+public final class LogAppendable implements Appendable {
+
+ private final Logger log;
+ private final String prefix;
+ private final StringBuilder buffer;
+
+ public LogAppendable(final Logger log, final String prefix) {
+ this.log = log;
+ this.prefix = prefix;
+ this.buffer = new StringBuilder();
+ }
+
+
+ @Override
+ public Appendable append(final CharSequence text) throws IOException {
+ return append(text, 0, text.length());
+ }
+
+ @Override
+ public Appendable append(final CharSequence text, final int start, final int end) throws IOException {
+ for (int i = start; i < end; i++) {
+ append(text.charAt(i));
+ }
+ return this;
+ }
+
+ @Override
+ public Appendable append(final char ch) throws IOException {
+ if (ch == '\n') {
+ log.debug(prefix + " " + buffer.toString());
+ buffer.setLength(0);
+ } else if (ch != '\r') {
+ buffer.append(ch);
+ }
+ return this;
+ }
+
+ public void flush() {
+ if (buffer.length() > 0) {
+ log.debug(prefix + " " + buffer.toString());
+ buffer.setLength(0);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java
new file mode 100644
index 0000000..fad7f1e
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java
@@ -0,0 +1,270 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl.async;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.ByteChannel;
+import java.nio.channels.SelectionKey;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.client5.http.impl.Wire;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.reactor.Command;
+import org.apache.hc.core5.reactor.IOEventHandler;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
+import org.apache.logging.log4j.Logger;
+
+class LoggingIOSession implements TlsCapableIOSession {
+
+ private final Logger log;
+ private final Wire wirelog;
+ private final String id;
+ private final TlsCapableIOSession session;
+ private final ByteChannel channel;
+
+ public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wirelog) {
+ super();
+ this.session = session;
+ this.id = id;
+ this.log = log;
+ this.wirelog = new Wire(wirelog, this.id);
+ this.channel = new LoggingByteChannel();
+ }
+
+ public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log) {
+ this(session, id, log, null);
+ }
+
+ @Override
+ public String getId() {
+ return session.getId();
+ }
+
+ @Override
+ public void addLast(final Command command) {
+ this.session.addLast(command);
+ }
+
+ @Override
+ public void addFirst(final Command command) {
+ this.session.addFirst(command);
+ }
+
+ @Override
+ public Command getCommand() {
+ return this.session.getCommand();
+ }
+
+ @Override
+ public ByteChannel channel() {
+ return this.channel;
+ }
+
+ @Override
+ public SocketAddress getLocalAddress() {
+ return this.session.getLocalAddress();
+ }
+
+ @Override
+ public SocketAddress getRemoteAddress() {
+ return this.session.getRemoteAddress();
+ }
+
+ @Override
+ public int getEventMask() {
+ return this.session.getEventMask();
+ }
+
+ private static String formatOps(final int ops) {
+ final StringBuilder buffer = new StringBuilder(6);
+ buffer.append('[');
+ if ((ops & SelectionKey.OP_READ) > 0) {
+ buffer.append('r');
+ }
+ if ((ops & SelectionKey.OP_WRITE) > 0) {
+ buffer.append('w');
+ }
+ if ((ops & SelectionKey.OP_ACCEPT) > 0) {
+ buffer.append('a');
+ }
+ if ((ops & SelectionKey.OP_CONNECT) > 0) {
+ buffer.append('c');
+ }
+ buffer.append(']');
+ return buffer.toString();
+ }
+
+ @Override
+ public void setEventMask(final int ops) {
+ this.session.setEventMask(ops);
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Event mask set " + formatOps(ops));
+ }
+ }
+
+ @Override
+ public void setEvent(final int op) {
+ this.session.setEvent(op);
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Event set " + formatOps(op));
+ }
+ }
+
+ @Override
+ public void clearEvent(final int op) {
+ this.session.clearEvent(op);
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Event cleared " + formatOps(op));
+ }
+ }
+
+ @Override
+ public void close() {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Close");
+ }
+ this.session.close();
+ }
+
+ @Override
+ public int getStatus() {
+ return this.session.getStatus();
+ }
+
+ @Override
+ public boolean isClosed() {
+ return this.session.isClosed();
+ }
+
+ @Override
+ public void shutdown(final ShutdownType shutdownType) {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Shutdown " + shutdownType);
+ }
+ this.session.shutdown(shutdownType);
+ }
+
+ @Override
+ public int getSocketTimeout() {
+ return this.session.getSocketTimeout();
+ }
+
+ @Override
+ public void setSocketTimeout(final int timeout) {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(this.id + " " + this.session + ": Set timeout " + timeout);
+ }
+ this.session.setSocketTimeout(timeout);
+ }
+
+ @Override
+ public IOEventHandler getHandler() {
+ return this.session.getHandler();
+ }
+
+ @Override
+ public void setHandler(final IOEventHandler handler) {
+ this.session.setHandler(handler);
+ }
+
+ @Override
+ public void startTls(
+ final SSLContext sslContext,
+ final SSLBufferManagement sslBufferManagement,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) throws UnsupportedOperationException {
+ session.startTls(sslContext, sslBufferManagement, initializer, verifier);
+ }
+
+ @Override
+ public TlsDetails getTlsDetails() {
+ return session.getTlsDetails();
+ }
+
+ @Override
+ public String toString() {
+ return this.id + " " + this.session.toString();
+ }
+
+ class LoggingByteChannel implements ByteChannel {
+
+ @Override
+ public int read(final ByteBuffer dst) throws IOException {
+ final int bytesRead = session.channel().read(dst);
+ if (log.isDebugEnabled()) {
+ log.debug(id + " " + session + ": " + bytesRead + " bytes read");
+ }
+ if (bytesRead > 0 && wirelog.isEnabled()) {
+ final ByteBuffer b = dst.duplicate();
+ final int p = b.position();
+ b.limit(p);
+ b.position(p - bytesRead);
+ wirelog.input(b);
+ }
+ return bytesRead;
+ }
+
+ @Override
+ public int write(final ByteBuffer src) throws IOException {
+ final int byteWritten = session.channel().write(src);
+ if (log.isDebugEnabled()) {
+ log.debug(id + " " + session + ": " + byteWritten + " bytes written");
+ }
+ if (byteWritten > 0 && wirelog.isEnabled()) {
+ final ByteBuffer b = src.duplicate();
+ final int p = b.position();
+ b.limit(p);
+ b.position(p - byteWritten);
+ wirelog.output(b);
+ }
+ return byteWritten;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug(id + " " + session + ": Channel close");
+ }
+ session.channel().close();
+ }
+
+ @Override
+ public boolean isOpen() {
+ return session.channel().isOpen();
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
index ac412ff..52dea86 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
@@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
-import org.apache.hc.client5.http.impl.logging.LoggingSocketHolder;
import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
new file mode 100644
index 0000000..69aded2
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
@@ -0,0 +1,139 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.hc.client5.http.impl.Wire;
+
+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 {
+ try {
+ final int b = in.read();
+ if (b == -1) {
+ wire.input("end of stream");
+ } else {
+ wire.input(b);
+ }
+ return b;
+ } catch (final IOException ex) {
+ wire.input("[read] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public int read(final byte[] b) throws IOException {
+ try {
+ final int bytesRead = in.read(b);
+ if (bytesRead == -1) {
+ wire.input("end of stream");
+ } else if (bytesRead > 0) {
+ wire.input(b, 0, bytesRead);
+ }
+ return bytesRead;
+ } catch (final IOException ex) {
+ wire.input("[read] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ try {
+ final int bytesRead = in.read(b, off, len);
+ if (bytesRead == -1) {
+ wire.input("end of stream");
+ } else if (bytesRead > 0) {
+ wire.input(b, off, bytesRead);
+ }
+ return bytesRead;
+ } catch (final IOException ex) {
+ wire.input("[read] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public long skip(final long n) throws IOException {
+ try {
+ return super.skip(n);
+ } catch (final IOException ex) {
+ wire.input("[skip] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public int available() throws IOException {
+ try {
+ return in.available();
+ } catch (final IOException ex) {
+ wire.input("[available] I/O error : " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public void mark(final int readlimit) {
+ super.mark(readlimit);
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ }
+
+ @Override
+ public boolean markSupported() {
+ return false;
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ in.close();
+ } catch (final IOException ex) {
+ wire.input("[close] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
new file mode 100644
index 0000000..7484ee3
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
@@ -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.hc.client5.http.impl.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.hc.client5.http.impl.Wire;
+
+/**
+ * Internal class.
+ *
+ * @since 4.3
+ */
+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(final int b) throws IOException {
+ try {
+ out.write(b);
+ wire.output(b);
+ } catch (final IOException ex) {
+ wire.output("[write] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public void write(final byte[] b) throws IOException {
+ try {
+ wire.output(b);
+ out.write(b);
+ } catch (final IOException ex) {
+ wire.output("[write] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public void write(final byte[] b, final int off, final int len) throws IOException {
+ try {
+ wire.output(b, off, len);
+ out.write(b, off, len);
+ } catch (final IOException ex) {
+ wire.output("[write] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ try {
+ out.flush();
+ } catch (final IOException ex) {
+ wire.output("[flush] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ out.close();
+ } catch (final IOException ex) {
+ wire.output("[close] I/O error: " + ex.getMessage());
+ throw ex;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
new file mode 100644
index 0000000..b7aae76
--- /dev/null
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
@@ -0,0 +1,57 @@
+/*
+ * ====================================================================
+ * 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.hc.client5.http.impl.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+import org.apache.hc.client5.http.impl.Wire;
+import org.apache.hc.core5.http.impl.io.SocketHolder;
+import org.apache.logging.log4j.Logger;
+
+class LoggingSocketHolder extends SocketHolder {
+
+ private final Wire wire;
+
+ public LoggingSocketHolder(final Socket socket, final String id, final Logger log) {
+ super(socket);
+ this.wire = new Wire(log, id);
+ }
+
+ @Override
+ protected InputStream getInputStream(final Socket socket) throws IOException {
+ return new LoggingInputStream(super.getInputStream(socket), wire);
+ }
+
+ @Override
+ protected OutputStream getOutputStream(final Socket socket) throws IOException {
+ return new LoggingOutputStream(super.getOutputStream(socket), wire);
+ }
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
index 4dca6a7..ecb237e 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
@@ -64,7 +64,6 @@ import org.apache.hc.core5.http.io.HttpConnectionFactory;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.pool.ConnPoolControl;
-import org.apache.hc.core5.pool.ConnPoolListener;
import org.apache.hc.core5.pool.PoolEntry;
import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.pool.PoolStats;
@@ -128,7 +127,7 @@ public class PoolingHttpClientConnectionManager
}
public PoolingHttpClientConnectionManager(final TimeValue timeToLive) {
- this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, null, timeToLive);
+ this(getDefaultRegistry(), null, null ,null, PoolReusePolicy.LIFO, timeToLive);
}
public PoolingHttpClientConnectionManager(
@@ -157,7 +156,7 @@ public class PoolingHttpClientConnectionManager
final Registry<ConnectionSocketFactory> socketFactoryRegistry,
final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
final DnsResolver dnsResolver) {
- this(socketFactoryRegistry, connFactory, null, dnsResolver, PoolReusePolicy.LIFO, null, TimeValue.NEG_ONE_MILLISECONDS);
+ this(socketFactoryRegistry, connFactory, null, dnsResolver, PoolReusePolicy.LIFO, TimeValue.NEG_ONE_MILLISECONDS);
}
public PoolingHttpClientConnectionManager(
@@ -166,23 +165,21 @@ public class PoolingHttpClientConnectionManager
final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver,
final PoolReusePolicy poolReusePolicy,
- final ConnPoolListener<HttpRoute> connPoolListener,
final TimeValue timeToLive) {
this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
- connFactory, poolReusePolicy, connPoolListener, timeToLive);
+ connFactory, poolReusePolicy, timeToLive);
}
public PoolingHttpClientConnectionManager(
final HttpClientConnectionOperator httpClientConnectionOperator,
final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
final PoolReusePolicy poolReusePolicy,
- final ConnPoolListener<HttpRoute> connPoolListener,
final TimeValue timeToLive) {
super();
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
- this.pool = new StrictConnPool<>(
- DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, poolReusePolicy, connPoolListener);
+ this.pool = new StrictConnPool<>(DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive,
+ poolReusePolicy, null);
this.closed = new AtomicBoolean(false);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
index 76c36b3..0e3b553 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
@@ -28,7 +28,6 @@
package org.apache.hc.client5.http.impl.io;
import org.apache.hc.client5.http.DnsResolver;
-import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
@@ -38,7 +37,6 @@ import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.config.SocketConfig;
import org.apache.hc.core5.http.io.HttpConnectionFactory;
-import org.apache.hc.core5.pool.ConnPoolListener;
import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.util.TimeValue;
@@ -75,7 +73,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
private SchemePortResolver schemePortResolver;
private DnsResolver dnsResolver;
private PoolReusePolicy poolReusePolicy;
- private ConnPoolListener<HttpRoute> connPoolListener;
private SocketConfig defaultSocketConfig;
private boolean systemProperties;
@@ -137,14 +134,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
}
/**
- * Assigns {@link ConnPoolListener} instance.
- */
- public final PoolingHttpClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
- this.connPoolListener = connPoolListener;
- return this;
- }
-
- /**
* Assigns maximum total connection value.
*/
public final PoolingHttpClientConnectionManagerBuilder setMaxConnTotal(final int maxConnTotal) {
@@ -210,7 +199,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
schemePortResolver,
dnsResolver,
poolReusePolicy,
- connPoolListener,
timeToLive != null ? timeToLive : TimeValue.NEG_ONE_MILLISECONDS);
poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
if (defaultSocketConfig != null) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java
deleted file mode 100644
index 181bb95..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LogAppendable.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.io.IOException;
-
-import org.apache.logging.log4j.Logger;
-
-public final class LogAppendable implements Appendable {
-
- private final Logger log;
- private final String prefix;
- private final StringBuilder buffer;
-
- public LogAppendable(final Logger log, final String prefix) {
- this.log = log;
- this.prefix = prefix;
- this.buffer = new StringBuilder();
- }
-
-
- @Override
- public Appendable append(final CharSequence text) throws IOException {
- return append(text, 0, text.length());
- }
-
- @Override
- public Appendable append(final CharSequence text, final int start, final int end) throws IOException {
- for (int i = start; i < end; i++) {
- append(text.charAt(i));
- }
- return this;
- }
-
- @Override
- public Appendable append(final char ch) throws IOException {
- if (ch == '\n') {
- log.debug(prefix + " " + buffer.toString());
- buffer.setLength(0);
- } else if (ch != '\r') {
- buffer.append(ch);
- }
- return this;
- }
-
- public void flush() {
- if (buffer.length() > 0) {
- log.debug(prefix + " " + buffer.toString());
- buffer.setLength(0);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java
deleted file mode 100644
index c750f7a..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.ByteChannel;
-import java.nio.channels.SelectionKey;
-
-import javax.net.ssl.SSLContext;
-
-import org.apache.hc.core5.io.ShutdownType;
-import org.apache.hc.core5.reactor.Command;
-import org.apache.hc.core5.reactor.IOEventHandler;
-import org.apache.hc.core5.reactor.TlsCapableIOSession;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
-import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
-import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
-import org.apache.hc.core5.reactor.ssl.TlsDetails;
-import org.apache.logging.log4j.Logger;
-
-public class LoggingIOSession implements TlsCapableIOSession {
-
- private final Logger log;
- private final Wire wirelog;
- private final String id;
- private final TlsCapableIOSession session;
- private final ByteChannel channel;
-
- public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wirelog) {
- super();
- this.session = session;
- this.id = id;
- this.log = log;
- this.wirelog = new Wire(wirelog, this.id);
- this.channel = new LoggingByteChannel();
- }
-
- public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log) {
- this(session, id, log, null);
- }
-
- @Override
- public String getId() {
- return session.getId();
- }
-
- @Override
- public void addLast(final Command command) {
- this.session.addLast(command);
- }
-
- @Override
- public void addFirst(final Command command) {
- this.session.addFirst(command);
- }
-
- @Override
- public Command getCommand() {
- return this.session.getCommand();
- }
-
- @Override
- public ByteChannel channel() {
- return this.channel;
- }
-
- @Override
- public SocketAddress getLocalAddress() {
- return this.session.getLocalAddress();
- }
-
- @Override
- public SocketAddress getRemoteAddress() {
- return this.session.getRemoteAddress();
- }
-
- @Override
- public int getEventMask() {
- return this.session.getEventMask();
- }
-
- private static String formatOps(final int ops) {
- final StringBuilder buffer = new StringBuilder(6);
- buffer.append('[');
- if ((ops & SelectionKey.OP_READ) > 0) {
- buffer.append('r');
- }
- if ((ops & SelectionKey.OP_WRITE) > 0) {
- buffer.append('w');
- }
- if ((ops & SelectionKey.OP_ACCEPT) > 0) {
- buffer.append('a');
- }
- if ((ops & SelectionKey.OP_CONNECT) > 0) {
- buffer.append('c');
- }
- buffer.append(']');
- return buffer.toString();
- }
-
- @Override
- public void setEventMask(final int ops) {
- this.session.setEventMask(ops);
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Event mask set " + formatOps(ops));
- }
- }
-
- @Override
- public void setEvent(final int op) {
- this.session.setEvent(op);
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Event set " + formatOps(op));
- }
- }
-
- @Override
- public void clearEvent(final int op) {
- this.session.clearEvent(op);
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Event cleared " + formatOps(op));
- }
- }
-
- @Override
- public void close() {
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Close");
- }
- this.session.close();
- }
-
- @Override
- public int getStatus() {
- return this.session.getStatus();
- }
-
- @Override
- public boolean isClosed() {
- return this.session.isClosed();
- }
-
- @Override
- public void shutdown(final ShutdownType shutdownType) {
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Shutdown " + shutdownType);
- }
- this.session.shutdown(shutdownType);
- }
-
- @Override
- public int getSocketTimeout() {
- return this.session.getSocketTimeout();
- }
-
- @Override
- public void setSocketTimeout(final int timeout) {
- if (this.log.isDebugEnabled()) {
- this.log.debug(this.id + " " + this.session + ": Set timeout " + timeout);
- }
- this.session.setSocketTimeout(timeout);
- }
-
- @Override
- public IOEventHandler getHandler() {
- return this.session.getHandler();
- }
-
- @Override
- public void setHandler(final IOEventHandler handler) {
- this.session.setHandler(handler);
- }
-
- @Override
- public void startTls(
- final SSLContext sslContext,
- final SSLBufferManagement sslBufferManagement,
- final SSLSessionInitializer initializer,
- final SSLSessionVerifier verifier) throws UnsupportedOperationException {
- session.startTls(sslContext, sslBufferManagement, initializer, verifier);
- }
-
- @Override
- public TlsDetails getTlsDetails() {
- return session.getTlsDetails();
- }
-
- @Override
- public String toString() {
- return this.id + " " + this.session.toString();
- }
-
- class LoggingByteChannel implements ByteChannel {
-
- @Override
- public int read(final ByteBuffer dst) throws IOException {
- final int bytesRead = session.channel().read(dst);
- if (log.isDebugEnabled()) {
- log.debug(id + " " + session + ": " + bytesRead + " bytes read");
- }
- if (bytesRead > 0 && wirelog.isEnabled()) {
- final ByteBuffer b = dst.duplicate();
- final int p = b.position();
- b.limit(p);
- b.position(p - bytesRead);
- wirelog.input(b);
- }
- return bytesRead;
- }
-
- @Override
- public int write(final ByteBuffer src) throws IOException {
- final int byteWritten = session.channel().write(src);
- if (log.isDebugEnabled()) {
- log.debug(id + " " + session + ": " + byteWritten + " bytes written");
- }
- if (byteWritten > 0 && wirelog.isEnabled()) {
- final ByteBuffer b = src.duplicate();
- final int p = b.position();
- b.limit(p);
- b.position(p - byteWritten);
- wirelog.output(b);
- }
- return byteWritten;
- }
-
- @Override
- public void close() throws IOException {
- if (log.isDebugEnabled()) {
- log.debug(id + " " + session + ": Channel close");
- }
- session.channel().close();
- }
-
- @Override
- public boolean isOpen() {
- return session.channel().isOpen();
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java
deleted file mode 100644
index 018fae6..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-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 {
- try {
- final int b = in.read();
- if (b == -1) {
- wire.input("end of stream");
- } else {
- wire.input(b);
- }
- return b;
- } catch (final IOException ex) {
- wire.input("[read] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public int read(final byte[] b) throws IOException {
- try {
- final int bytesRead = in.read(b);
- if (bytesRead == -1) {
- wire.input("end of stream");
- } else if (bytesRead > 0) {
- wire.input(b, 0, bytesRead);
- }
- return bytesRead;
- } catch (final IOException ex) {
- wire.input("[read] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public int read(final byte[] b, final int off, final int len) throws IOException {
- try {
- final int bytesRead = in.read(b, off, len);
- if (bytesRead == -1) {
- wire.input("end of stream");
- } else if (bytesRead > 0) {
- wire.input(b, off, bytesRead);
- }
- return bytesRead;
- } catch (final IOException ex) {
- wire.input("[read] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public long skip(final long n) throws IOException {
- try {
- return super.skip(n);
- } catch (final IOException ex) {
- wire.input("[skip] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public int available() throws IOException {
- try {
- return in.available();
- } catch (final IOException ex) {
- wire.input("[available] I/O error : " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public void mark(final int readlimit) {
- super.mark(readlimit);
- }
-
- @Override
- public void reset() throws IOException {
- super.reset();
- }
-
- @Override
- public boolean markSupported() {
- return false;
- }
-
- @Override
- public void close() throws IOException {
- try {
- in.close();
- } catch (final IOException ex) {
- wire.input("[close] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java
deleted file mode 100644
index ec82d1f..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * Internal class.
- *
- * @since 4.3
- */
-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(final int b) throws IOException {
- try {
- out.write(b);
- wire.output(b);
- } catch (final IOException ex) {
- wire.output("[write] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public void write(final byte[] b) throws IOException {
- try {
- wire.output(b);
- out.write(b);
- } catch (final IOException ex) {
- wire.output("[write] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public void write(final byte[] b, final int off, final int len) throws IOException {
- try {
- wire.output(b, off, len);
- out.write(b, off, len);
- } catch (final IOException ex) {
- wire.output("[write] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public void flush() throws IOException {
- try {
- out.flush();
- } catch (final IOException ex) {
- wire.output("[flush] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
- @Override
- public void close() throws IOException {
- try {
- out.close();
- } catch (final IOException ex) {
- wire.output("[close] I/O error: " + ex.getMessage());
- throw ex;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java
deleted file mode 100644
index ddde402..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-
-import org.apache.hc.core5.http.impl.io.SocketHolder;
-import org.apache.logging.log4j.Logger;
-
-public class LoggingSocketHolder extends SocketHolder {
-
- private final Wire wire;
-
- public LoggingSocketHolder(final Socket socket, final String id, final Logger log) {
- super(socket);
- this.wire = new Wire(log, id);
- }
-
- @Override
- protected InputStream getInputStream(final Socket socket) throws IOException {
- return new LoggingInputStream(super.getInputStream(socket), wire);
- }
-
- @Override
- protected OutputStream getOutputStream(final Socket socket) throws IOException {
- return new LoggingOutputStream(super.getOutputStream(socket), wire);
- }
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java
deleted file mode 100644
index 8bd9e4f..0000000
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.logging;
-
-import java.nio.ByteBuffer;
-
-import org.apache.hc.core5.util.Args;
-import org.apache.logging.log4j.Logger;
-
-class Wire {
-
- private static final int MAX_STRING_BUILDER_SIZE = 2048;
-
- private static final ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
-
- /**
- * Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
- *
- * @return a {@code StringBuilder}
- */
- private static StringBuilder getStringBuilder() {
- StringBuilder result = threadLocal.get();
- if (result == null) {
- result = new StringBuilder(MAX_STRING_BUILDER_SIZE);
- threadLocal.set(result);
- }
- // TODO Delegate to Log4j's 2.9 StringBuilds.trimToMaxSize() when it is released.
- trimToMaxSize(result, MAX_STRING_BUILDER_SIZE);
- result.setLength(0);
- return result;
- }
-
- /**
- * Ensures that the char[] array of the specified StringBuilder does not exceed the specified number of characters.
- * This method is useful to ensure that excessively long char[] arrays are not kept in memory forever.
- *
- * @param stringBuilder the StringBuilder to check
- * @param maxSize the maximum number of characters the StringBuilder is allowed to have
- */
- // TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
- private static void trimToMaxSize(final StringBuilder stringBuilder, final int maxSize) {
- if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
- stringBuilder.setLength(maxSize);
- stringBuilder.trimToSize();
- }
- }
-
- private final Logger log;
- private final String id;
-
- Wire(final Logger log, final String id) {
- super();
- this.log = log;
- this.id = id;
- }
-
- private void wire(final String header, final byte[] b, final int pos, final int off) {
- final StringBuilder buffer = getStringBuilder();
- for (int i = 0; i < off; i++) {
- final int ch = b[pos + i];
- if (ch == 13) {
- buffer.append("[\\r]");
- } else if (ch == 10) {
- buffer.append("[\\n]\"");
- buffer.insert(0, "\"");
- buffer.insert(0, header);
- this.log.debug(this.id + " " + buffer.toString());
- buffer.setLength(0);
- } else if ((ch < 32) || (ch > 127)) {
- buffer.append("[0x");
- buffer.append(Integer.toHexString(ch));
- buffer.append("]");
- } else {
- buffer.append((char) ch);
- }
- }
- if (buffer.length() > 0) {
- buffer.append('\"');
- buffer.insert(0, '\"');
- buffer.insert(0, header);
- this.log.debug(this.id + " " + buffer.toString());
- }
- }
-
-
- public boolean isEnabled() {
- return this.log.isDebugEnabled();
- }
-
- public void output(final byte[] b, final int pos, final int off) {
- Args.notNull(b, "Output");
- wire(">> ", b, pos, off);
- }
-
- public void input(final byte[] b, final int pos, final int off) {
- Args.notNull(b, "Input");
- wire("<< ", b, pos, off);
- }
-
- public void output(final byte[] b) {
- Args.notNull(b, "Output");
- output(b, 0, b.length);
- }
-
- public void input(final byte[] b) {
- Args.notNull(b, "Input");
- input(b, 0, b.length);
- }
-
- public void output(final int b) {
- output(new byte[] {(byte) b});
- }
-
- public void input(final int b) {
- input(new byte[] {(byte) b});
- }
-
- public void output(final String s) {
- Args.notNull(s, "Output");
- output(s.getBytes());
- }
-
- public void input(final String s) {
- Args.notNull(s, "Input");
- input(s.getBytes());
- }
-
- public void output(final ByteBuffer b) {
- Args.notNull(b, "Output");
- if (b.hasArray()) {
- output(b.array(), b.arrayOffset() + b.position(), b.remaining());
- } else {
- final byte[] tmp = new byte[b.remaining()];
- b.get(tmp);
- output(tmp);
- }
- }
-
- public void input(final ByteBuffer b) {
- Args.notNull(b, "Input");
- if (b.hasArray()) {
- input(b.array(), b.arrayOffset() + b.position(), b.remaining());
- } else {
- final byte[] tmp = new byte[b.remaining()];
- b.get(tmp);
- input(tmp);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
index 59d37bb..93ce8eb 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
@@ -58,7 +58,6 @@ import org.apache.hc.core5.http2.nio.command.PingCommand;
import org.apache.hc.core5.http2.nio.support.BasicPingHandler;
import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.pool.ConnPoolControl;
-import org.apache.hc.core5.pool.ConnPoolListener;
import org.apache.hc.core5.pool.PoolEntry;
import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.pool.PoolStats;
@@ -106,10 +105,9 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
final SchemePortResolver schemePortResolver,
final DnsResolver dnsResolver,
final TimeValue timeToLive,
- final PoolReusePolicy poolReusePolicy,
- final ConnPoolListener<HttpRoute> connPoolListener) {
+ final PoolReusePolicy poolReusePolicy) {
this.connectionOperator = new AsyncClientConnectionOperator(schemePortResolver, dnsResolver, tlsStrategyLookup);
- this.pool = new StrictConnPool<>(20, 50, timeToLive, poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO, connPoolListener);
+ this.pool = new StrictConnPool<>(20, 50, timeToLive, poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO, null);
this.closed = new AtomicBoolean(false);
}
@@ -400,7 +398,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
InternalConnectionEndpoint(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
this.poolEntryRef = new AtomicReference<>(poolEntry);
- this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet());
+ this.id = String.format("ep-%08X", COUNT.getAndIncrement());
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/e8f72b7c/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
index 9a840ad..ed2e42d 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
@@ -31,12 +31,10 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import org.apache.hc.client5.http.DnsResolver;
-import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.ssl.H2TlsStrategy;
import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.pool.ConnPoolListener;
import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.util.TimeValue;
@@ -72,7 +70,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
private SchemePortResolver schemePortResolver;
private DnsResolver dnsResolver;
private PoolReusePolicy poolReusePolicy;
- private ConnPoolListener<HttpRoute> connPoolListener;
private boolean systemProperties;
@@ -124,14 +121,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
}
/**
- * Assigns {@link ConnPoolListener} instance.
- */
- public final PoolingAsyncClientConnectionManagerBuilder setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
- this.connPoolListener = connPoolListener;
- return this;
- }
-
- /**
* Assigns maximum total connection value.
*/
public final PoolingAsyncClientConnectionManagerBuilder setMaxConnTotal(final int maxConnTotal) {
@@ -184,8 +173,7 @@ public class PoolingAsyncClientConnectionManagerBuilder {
schemePortResolver,
dnsResolver,
timeToLive,
- poolReusePolicy,
- connPoolListener);
+ poolReusePolicy);
poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
if (maxConnTotal > 0) {
poolingmgr.setMaxTotal(maxConnTotal);
Fwd: [6/6] httpcomponents-client git commit: Logging improvements
Posted by Gary Gregory <ga...@gmail.com>.
I see a TODO I left in there for when we release Log4j 2.9.0, and we just
did. I can do that over the weekend unless someone else gets to it first.
Gary
---------- Forwarded message ----------
From: <ol...@apache.org>
Date: Sep 1, 2017 12:15
Subject: [6/6] httpcomponents-client git commit: Logging improvements
To: <co...@hc.apache.org>
Cc:
Logging improvements
>
>
> Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
> Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/commit/e8f72b7c
> Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/tree/e8f72b7c
> Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/diff/e8f72b7c
>
> Branch: refs/heads/master
> Commit: e8f72b7c57e353b7fb1cc164f6f5c8e8bc8cbf28
> Parents: 1eb2218
> Author: Oleg Kalnichevski <ol...@apache.org>
> Authored: Fri Sep 1 20:11:04 2017 +0200
> Committer: Oleg Kalnichevski <ol...@apache.org>
> Committed: Fri Sep 1 20:11:04 2017 +0200
>
> ----------------------------------------------------------------------
> .../hc/client5/http/impl/ConnPoolSupport.java | 2 +
> .../org/apache/hc/client5/http/impl/Wire.java | 177 ++++++++++++
> .../HttpAsyncClientEventHandlerFactory.java | 2 -
> .../impl/async/InternalHttpAsyncClient.java | 2 +-
> .../client5/http/impl/async/LogAppendable.java | 78 ++++++
> .../http/impl/async/LoggingIOSession.java | 270 +++++++++++++++++++
> .../io/DefaultManagedHttpClientConnection.java | 1 -
> .../http/impl/io/LoggingInputStream.java | 139 ++++++++++
> .../http/impl/io/LoggingOutputStream.java | 104 +++++++
> .../http/impl/io/LoggingSocketHolder.java | 57 ++++
> .../io/PoolingHttpClientConnectionManager.java | 13 +-
> ...olingHttpClientConnectionManagerBuilder.java | 12 -
> .../http/impl/logging/LogAppendable.java | 78 ------
> .../http/impl/logging/LoggingIOSession.java | 269 ------------------
> .../http/impl/logging/LoggingInputStream.java | 137 ----------
> .../http/impl/logging/LoggingOutputStream.java | 102 -------
> .../http/impl/logging/LoggingSocketHolder.java | 56 ----
> .../hc/client5/http/impl/logging/Wire.java | 175 ------------
> .../PoolingAsyncClientConnectionManager.java | 8 +-
> ...lingAsyncClientConnectionManagerBuilder.java | 14 +-
> 20 files changed, 837 insertions(+), 859 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/ConnPoolSupport.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/ConnPoolSupport.java
> index e6650a4..3de413c 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/ConnPoolSupport.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/ConnPoolSupport.java
> @@ -27,10 +27,12 @@
> package org.apache.hc.client5.http.impl;
>
> import org.apache.hc.client5.http.HttpRoute;
> +import org.apache.hc.core5.annotation.Internal;
> import org.apache.hc.core5.pool.ConnPoolControl;
> import org.apache.hc.core5.pool.PoolStats;
> import org.apache.hc.core5.util.Identifiable;
>
> +@Internal
> public final class ConnPoolSupport {
>
> public static String getId(final Object object) {
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/Wire.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
> new file mode 100644
> index 0000000..fd48ebd
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/Wire.java
> @@ -0,0 +1,177 @@
> +/*
> + * ====================================================================
> + * 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.hc.client5.http.impl;
> +
> +import java.nio.ByteBuffer;
> +
> +import org.apache.hc.core5.annotation.Internal;
> +import org.apache.hc.core5.util.Args;
> +import org.apache.logging.log4j.Logger;
> +
> +@Internal
> +public class Wire {
> +
> + private static final int MAX_STRING_BUILDER_SIZE = 2048;
> +
> + private static final ThreadLocal<StringBuilder> threadLocal = new
> ThreadLocal<>();
> +
> + /**
> + * Returns a {@code StringBuilder} that this Layout implementation
> can use to write the formatted log event to.
> + *
> + * @return a {@code StringBuilder}
> + */
> + private static StringBuilder getStringBuilder() {
> + StringBuilder result = threadLocal.get();
> + if (result == null) {
> + result = new StringBuilder(MAX_STRING_BUILDER_SIZE);
> + threadLocal.set(result);
> + }
> + // TODO Delegate to Log4j's 2.9 StringBuilds.trimToMaxSize() when
> it is released.
> + trimToMaxSize(result, MAX_STRING_BUILDER_SIZE);
> + result.setLength(0);
> + return result;
> + }
> +
> + /**
> + * Ensures that the char[] array of the specified StringBuilder does
> not exceed the specified number of characters.
> + * This method is useful to ensure that excessively long char[]
> arrays are not kept in memory forever.
> + *
> + * @param stringBuilder the StringBuilder to check
> + * @param maxSize the maximum number of characters the StringBuilder
> is allowed to have
> + */
> + // TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
> + private static void trimToMaxSize(final StringBuilder stringBuilder,
> final int maxSize) {
> + if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
> + stringBuilder.setLength(maxSize);
> + stringBuilder.trimToSize();
> + }
> + }
> +
> + private final Logger log;
> + private final String id;
> +
> + public Wire(final Logger log, final String id) {
> + super();
> + this.log = log;
> + this.id = id;
> + }
> +
> + private void wire(final String header, final byte[] b, final int pos,
> final int off) {
> + final StringBuilder buffer = getStringBuilder();
> + for (int i = 0; i < off; i++) {
> + final int ch = b[pos + i];
> + if (ch == 13) {
> + buffer.append("[\\r]");
> + } else if (ch == 10) {
> + buffer.append("[\\n]\"");
> + buffer.insert(0, "\"");
> + buffer.insert(0, header);
> + this.log.debug(this.id + " " + buffer.toString());
> + buffer.setLength(0);
> + } else if ((ch < 32) || (ch > 127)) {
> + buffer.append("[0x");
> + buffer.append(Integer.toHexString(ch));
> + buffer.append("]");
> + } else {
> + buffer.append((char) ch);
> + }
> + }
> + if (buffer.length() > 0) {
> + buffer.append('\"');
> + buffer.insert(0, '\"');
> + buffer.insert(0, header);
> + this.log.debug(this.id + " " + buffer.toString());
> + }
> + }
> +
> +
> + public boolean isEnabled() {
> + return this.log.isDebugEnabled();
> + }
> +
> + public void output(final byte[] b, final int pos, final int off) {
> + Args.notNull(b, "Output");
> + wire(">> ", b, pos, off);
> + }
> +
> + public void input(final byte[] b, final int pos, final int off) {
> + Args.notNull(b, "Input");
> + wire("<< ", b, pos, off);
> + }
> +
> + public void output(final byte[] b) {
> + Args.notNull(b, "Output");
> + output(b, 0, b.length);
> + }
> +
> + public void input(final byte[] b) {
> + Args.notNull(b, "Input");
> + input(b, 0, b.length);
> + }
> +
> + public void output(final int b) {
> + output(new byte[] {(byte) b});
> + }
> +
> + public void input(final int b) {
> + input(new byte[] {(byte) b});
> + }
> +
> + public void output(final String s) {
> + Args.notNull(s, "Output");
> + output(s.getBytes());
> + }
> +
> + public void input(final String s) {
> + Args.notNull(s, "Input");
> + input(s.getBytes());
> + }
> +
> + public void output(final ByteBuffer b) {
> + Args.notNull(b, "Output");
> + if (b.hasArray()) {
> + output(b.array(), b.arrayOffset() + b.position(),
> b.remaining());
> + } else {
> + final byte[] tmp = new byte[b.remaining()];
> + b.get(tmp);
> + output(tmp);
> + }
> + }
> +
> + public void input(final ByteBuffer b) {
> + Args.notNull(b, "Input");
> + if (b.hasArray()) {
> + input(b.array(), b.arrayOffset() + b.position(),
> b.remaining());
> + } else {
> + final byte[] tmp = new byte[b.remaining()];
> + b.get(tmp);
> + input(tmp);
> + }
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/HttpAsyncClientEventHandlerFactory.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/
> HttpAsyncClientEventHandlerFactory.java
> index 1419b44..95d9267 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/
> HttpAsyncClientEventHandlerFactory.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/
> HttpAsyncClientEventHandlerFactory.java
> @@ -32,8 +32,6 @@ import java.util.Iterator;
> import java.util.List;
>
> import org.apache.hc.client5.http.impl.ConnPoolSupport;
> -import org.apache.hc.client5.http.impl.logging.LogAppendable;
> -import org.apache.hc.client5.http.impl.logging.LoggingIOSession;
> import org.apache.hc.core5.annotation.Contract;
> import org.apache.hc.core5.annotation.ThreadingBehavior;
> import org.apache.hc.core5.http.ConnectionReuseStrategy;
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
> index d001458..c6f0d93 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/
> InternalHttpAsyncClient.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/
> InternalHttpAsyncClient.java
> @@ -248,7 +248,7 @@ class InternalHttpAsyncClient extends
> AbstractHttpAsyncClientBase {
>
> final HttpHost target = routePlanner.determineTargetHost(request,
> clientContext);
> final HttpRoute route = routePlanner.determineRoute(target,
> clientContext);
> - final String exchangeId = "ex-" +
> Long.toHexString(ExecSupport.getNextExecNumber());
> + final String exchangeId = String.format("ex-%08X",
> ExecSupport.getNextExecNumber());
> final AsyncExecRuntime execRuntime = new
> AsyncExecRuntimeImpl(log, connmgr, getConnectionInitiator(), versionPolicy);
> executeChain(exchangeId, execChain, route, request,
> entityDetails, exchangeHandler, clientContext, execRuntime);
> }
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/async/LogAppendable.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LogAppendable.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/LogAppendable.java
> new file mode 100644
> index 0000000..5d5070d
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/LogAppendable.java
> @@ -0,0 +1,78 @@
> +/*
> + * ====================================================================
> + * 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.hc.client5.http.impl.async;
> +
> +import java.io.IOException;
> +
> +import org.apache.logging.log4j.Logger;
> +
> +public final class LogAppendable implements Appendable {
> +
> + private final Logger log;
> + private final String prefix;
> + private final StringBuilder buffer;
> +
> + public LogAppendable(final Logger log, final String prefix) {
> + this.log = log;
> + this.prefix = prefix;
> + this.buffer = new StringBuilder();
> + }
> +
> +
> + @Override
> + public Appendable append(final CharSequence text) throws IOException {
> + return append(text, 0, text.length());
> + }
> +
> + @Override
> + public Appendable append(final CharSequence text, final int start,
> final int end) throws IOException {
> + for (int i = start; i < end; i++) {
> + append(text.charAt(i));
> + }
> + return this;
> + }
> +
> + @Override
> + public Appendable append(final char ch) throws IOException {
> + if (ch == '\n') {
> + log.debug(prefix + " " + buffer.toString());
> + buffer.setLength(0);
> + } else if (ch != '\r') {
> + buffer.append(ch);
> + }
> + return this;
> + }
> +
> + public void flush() {
> + if (buffer.length() > 0) {
> + log.debug(prefix + " " + buffer.toString());
> + buffer.setLength(0);
> + }
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/async/LoggingIOSession.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/LoggingIOSession.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/async/LoggingIOSession.java
> new file mode 100644
> index 0000000..fad7f1e
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/async/LoggingIOSession.java
> @@ -0,0 +1,270 @@
> +/*
> + * ====================================================================
> + * 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.hc.client5.http.impl.async;
> +
> +import java.io.IOException;
> +import java.net.SocketAddress;
> +import java.nio.ByteBuffer;
> +import java.nio.channels.ByteChannel;
> +import java.nio.channels.SelectionKey;
> +
> +import javax.net.ssl.SSLContext;
> +
> +import org.apache.hc.client5.http.impl.Wire;
> +import org.apache.hc.core5.io.ShutdownType;
> +import org.apache.hc.core5.reactor.Command;
> +import org.apache.hc.core5.reactor.IOEventHandler;
> +import org.apache.hc.core5.reactor.TlsCapableIOSession;
> +import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
> +import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
> +import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
> +import org.apache.hc.core5.reactor.ssl.TlsDetails;
> +import org.apache.logging.log4j.Logger;
> +
> +class LoggingIOSession implements TlsCapableIOSession {
> +
> + private final Logger log;
> + private final Wire wirelog;
> + private final String id;
> + private final TlsCapableIOSession session;
> + private final ByteChannel channel;
> +
> + public LoggingIOSession(final TlsCapableIOSession session, final
> String id, final Logger log, final Logger wirelog) {
> + super();
> + this.session = session;
> + this.id = id;
> + this.log = log;
> + this.wirelog = new Wire(wirelog, this.id);
> + this.channel = new LoggingByteChannel();
> + }
> +
> + public LoggingIOSession(final TlsCapableIOSession session, final
> String id, final Logger log) {
> + this(session, id, log, null);
> + }
> +
> + @Override
> + public String getId() {
> + return session.getId();
> + }
> +
> + @Override
> + public void addLast(final Command command) {
> + this.session.addLast(command);
> + }
> +
> + @Override
> + public void addFirst(final Command command) {
> + this.session.addFirst(command);
> + }
> +
> + @Override
> + public Command getCommand() {
> + return this.session.getCommand();
> + }
> +
> + @Override
> + public ByteChannel channel() {
> + return this.channel;
> + }
> +
> + @Override
> + public SocketAddress getLocalAddress() {
> + return this.session.getLocalAddress();
> + }
> +
> + @Override
> + public SocketAddress getRemoteAddress() {
> + return this.session.getRemoteAddress();
> + }
> +
> + @Override
> + public int getEventMask() {
> + return this.session.getEventMask();
> + }
> +
> + private static String formatOps(final int ops) {
> + final StringBuilder buffer = new StringBuilder(6);
> + buffer.append('[');
> + if ((ops & SelectionKey.OP_READ) > 0) {
> + buffer.append('r');
> + }
> + if ((ops & SelectionKey.OP_WRITE) > 0) {
> + buffer.append('w');
> + }
> + if ((ops & SelectionKey.OP_ACCEPT) > 0) {
> + buffer.append('a');
> + }
> + if ((ops & SelectionKey.OP_CONNECT) > 0) {
> + buffer.append('c');
> + }
> + buffer.append(']');
> + return buffer.toString();
> + }
> +
> + @Override
> + public void setEventMask(final int ops) {
> + this.session.setEventMask(ops);
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Event mask
> set " + formatOps(ops));
> + }
> + }
> +
> + @Override
> + public void setEvent(final int op) {
> + this.session.setEvent(op);
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Event set "
> + formatOps(op));
> + }
> + }
> +
> + @Override
> + public void clearEvent(final int op) {
> + this.session.clearEvent(op);
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Event
> cleared " + formatOps(op));
> + }
> + }
> +
> + @Override
> + public void close() {
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Close");
> + }
> + this.session.close();
> + }
> +
> + @Override
> + public int getStatus() {
> + return this.session.getStatus();
> + }
> +
> + @Override
> + public boolean isClosed() {
> + return this.session.isClosed();
> + }
> +
> + @Override
> + public void shutdown(final ShutdownType shutdownType) {
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Shutdown "
> + shutdownType);
> + }
> + this.session.shutdown(shutdownType);
> + }
> +
> + @Override
> + public int getSocketTimeout() {
> + return this.session.getSocketTimeout();
> + }
> +
> + @Override
> + public void setSocketTimeout(final int timeout) {
> + if (this.log.isDebugEnabled()) {
> + this.log.debug(this.id + " " + this.session + ": Set timeout
> " + timeout);
> + }
> + this.session.setSocketTimeout(timeout);
> + }
> +
> + @Override
> + public IOEventHandler getHandler() {
> + return this.session.getHandler();
> + }
> +
> + @Override
> + public void setHandler(final IOEventHandler handler) {
> + this.session.setHandler(handler);
> + }
> +
> + @Override
> + public void startTls(
> + final SSLContext sslContext,
> + final SSLBufferManagement sslBufferManagement,
> + final SSLSessionInitializer initializer,
> + final SSLSessionVerifier verifier) throws
> UnsupportedOperationException {
> + session.startTls(sslContext, sslBufferManagement, initializer,
> verifier);
> + }
> +
> + @Override
> + public TlsDetails getTlsDetails() {
> + return session.getTlsDetails();
> + }
> +
> + @Override
> + public String toString() {
> + return this.id + " " + this.session.toString();
> + }
> +
> + class LoggingByteChannel implements ByteChannel {
> +
> + @Override
> + public int read(final ByteBuffer dst) throws IOException {
> + final int bytesRead = session.channel().read(dst);
> + if (log.isDebugEnabled()) {
> + log.debug(id + " " + session + ": " + bytesRead + " bytes
> read");
> + }
> + if (bytesRead > 0 && wirelog.isEnabled()) {
> + final ByteBuffer b = dst.duplicate();
> + final int p = b.position();
> + b.limit(p);
> + b.position(p - bytesRead);
> + wirelog.input(b);
> + }
> + return bytesRead;
> + }
> +
> + @Override
> + public int write(final ByteBuffer src) throws IOException {
> + final int byteWritten = session.channel().write(src);
> + if (log.isDebugEnabled()) {
> + log.debug(id + " " + session + ": " + byteWritten + "
> bytes written");
> + }
> + if (byteWritten > 0 && wirelog.isEnabled()) {
> + final ByteBuffer b = src.duplicate();
> + final int p = b.position();
> + b.limit(p);
> + b.position(p - byteWritten);
> + wirelog.output(b);
> + }
> + return byteWritten;
> + }
> +
> + @Override
> + public void close() throws IOException {
> + if (log.isDebugEnabled()) {
> + log.debug(id + " " + session + ": Channel close");
> + }
> + session.channel().close();
> + }
> +
> + @Override
> + public boolean isOpen() {
> + return session.channel().isOpen();
> + }
> +
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> DefaultManagedHttpClientConnection.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
> index ac412ff..52dea86 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> DefaultManagedHttpClientConnection.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> DefaultManagedHttpClientConnection.java
> @@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
> import javax.net.ssl.SSLSession;
> import javax.net.ssl.SSLSocket;
>
> -import org.apache.hc.client5.http.impl.logging.LoggingSocketHolder;
> import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
> import org.apache.hc.core5.http.ClassicHttpRequest;
> import org.apache.hc.core5.http.ClassicHttpResponse;
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/LoggingInputStream.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingInputStream.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/io/LoggingInputStream.java
> new file mode 100644
> index 0000000..69aded2
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingInputStream.java
> @@ -0,0 +1,139 @@
> +/*
> + * ====================================================================
> + * 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.hc.client5.http.impl.io;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +
> +import org.apache.hc.client5.http.impl.Wire;
> +
> +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 {
> + try {
> + final int b = in.read();
> + if (b == -1) {
> + wire.input("end of stream");
> + } else {
> + wire.input(b);
> + }
> + return b;
> + } catch (final IOException ex) {
> + wire.input("[read] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public int read(final byte[] b) throws IOException {
> + try {
> + final int bytesRead = in.read(b);
> + if (bytesRead == -1) {
> + wire.input("end of stream");
> + } else if (bytesRead > 0) {
> + wire.input(b, 0, bytesRead);
> + }
> + return bytesRead;
> + } catch (final IOException ex) {
> + wire.input("[read] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public int read(final byte[] b, final int off, final int len) throws
> IOException {
> + try {
> + final int bytesRead = in.read(b, off, len);
> + if (bytesRead == -1) {
> + wire.input("end of stream");
> + } else if (bytesRead > 0) {
> + wire.input(b, off, bytesRead);
> + }
> + return bytesRead;
> + } catch (final IOException ex) {
> + wire.input("[read] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public long skip(final long n) throws IOException {
> + try {
> + return super.skip(n);
> + } catch (final IOException ex) {
> + wire.input("[skip] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public int available() throws IOException {
> + try {
> + return in.available();
> + } catch (final IOException ex) {
> + wire.input("[available] I/O error : " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public void mark(final int readlimit) {
> + super.mark(readlimit);
> + }
> +
> + @Override
> + public void reset() throws IOException {
> + super.reset();
> + }
> +
> + @Override
> + public boolean markSupported() {
> + return false;
> + }
> +
> + @Override
> + public void close() throws IOException {
> + try {
> + in.close();
> + } catch (final IOException ex) {
> + wire.input("[close] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/LoggingOutputStream.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingOutputStream.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
> new file mode 100644
> index 0000000..7484ee3
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingOutputStream.java
> @@ -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.hc.client5.http.impl.io;
> +
> +import java.io.IOException;
> +import java.io.OutputStream;
> +
> +import org.apache.hc.client5.http.impl.Wire;
> +
> +/**
> + * Internal class.
> + *
> + * @since 4.3
> + */
> +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(final int b) throws IOException {
> + try {
> + out.write(b);
> + wire.output(b);
> + } catch (final IOException ex) {
> + wire.output("[write] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public void write(final byte[] b) throws IOException {
> + try {
> + wire.output(b);
> + out.write(b);
> + } catch (final IOException ex) {
> + wire.output("[write] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public void write(final byte[] b, final int off, final int len)
> throws IOException {
> + try {
> + wire.output(b, off, len);
> + out.write(b, off, len);
> + } catch (final IOException ex) {
> + wire.output("[write] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public void flush() throws IOException {
> + try {
> + out.flush();
> + } catch (final IOException ex) {
> + wire.output("[flush] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> + @Override
> + public void close() throws IOException {
> + try {
> + out.close();
> + } catch (final IOException ex) {
> + wire.output("[close] I/O error: " + ex.getMessage());
> + throw ex;
> + }
> + }
> +
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/LoggingSocketHolder.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingSocketHolder.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
> new file mode 100644
> index 0000000..b7aae76
> --- /dev/null
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/io/LoggingSocketHolder.java
> @@ -0,0 +1,57 @@
> +/*
> + * ====================================================================
> + * 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.hc.client5.http.impl.io;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.OutputStream;
> +import java.net.Socket;
> +
> +import org.apache.hc.client5.http.impl.Wire;
> +import org.apache.hc.core5.http.impl.io.SocketHolder;
> +import org.apache.logging.log4j.Logger;
> +
> +class LoggingSocketHolder extends SocketHolder {
> +
> + private final Wire wire;
> +
> + public LoggingSocketHolder(final Socket socket, final String id,
> final Logger log) {
> + super(socket);
> + this.wire = new Wire(log, id);
> + }
> +
> + @Override
> + protected InputStream getInputStream(final Socket socket) throws
> IOException {
> + return new LoggingInputStream(super.getInputStream(socket),
> wire);
> + }
> +
> + @Override
> + protected OutputStream getOutputStream(final Socket socket) throws
> IOException {
> + return new LoggingOutputStream(super.getOutputStream(socket),
> wire);
> + }
> +}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
> index 4dca6a7..ecb237e 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManager.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManager.java
> @@ -64,7 +64,6 @@ import org.apache.hc.core5.http.io.
> HttpConnectionFactory;
> import org.apache.hc.core5.http.protocol.HttpContext;
> import org.apache.hc.core5.io.ShutdownType;
> import org.apache.hc.core5.pool.ConnPoolControl;
> -import org.apache.hc.core5.pool.ConnPoolListener;
> import org.apache.hc.core5.pool.PoolEntry;
> import org.apache.hc.core5.pool.PoolReusePolicy;
> import org.apache.hc.core5.pool.PoolStats;
> @@ -128,7 +127,7 @@ public class PoolingHttpClientConnectionManager
> }
>
> public PoolingHttpClientConnectionManager(final TimeValue
> timeToLive) {
> - this(getDefaultRegistry(), null, null ,null,
> PoolReusePolicy.LIFO, null, timeToLive);
> + this(getDefaultRegistry(), null, null ,null,
> PoolReusePolicy.LIFO, timeToLive);
> }
>
> public PoolingHttpClientConnectionManager(
> @@ -157,7 +156,7 @@ public class PoolingHttpClientConnectionManager
> final Registry<ConnectionSocketFactory>
> socketFactoryRegistry,
> final HttpConnectionFactory<ManagedHttpClientConnection>
> connFactory,
> final DnsResolver dnsResolver) {
> - this(socketFactoryRegistry, connFactory, null, dnsResolver,
> PoolReusePolicy.LIFO, null, TimeValue.NEG_ONE_MILLISECONDS);
> + this(socketFactoryRegistry, connFactory, null, dnsResolver,
> PoolReusePolicy.LIFO, TimeValue.NEG_ONE_MILLISECONDS);
> }
>
> public PoolingHttpClientConnectionManager(
> @@ -166,23 +165,21 @@ public class PoolingHttpClientConnectionManager
> final SchemePortResolver schemePortResolver,
> final DnsResolver dnsResolver,
> final PoolReusePolicy poolReusePolicy,
> - final ConnPoolListener<HttpRoute> connPoolListener,
> final TimeValue timeToLive) {
> this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry,
> schemePortResolver, dnsResolver),
> - connFactory, poolReusePolicy, connPoolListener, timeToLive);
> + connFactory, poolReusePolicy, timeToLive);
> }
>
> public PoolingHttpClientConnectionManager(
> final HttpClientConnectionOperator
> httpClientConnectionOperator,
> final HttpConnectionFactory<ManagedHttpClientConnection>
> connFactory,
> final PoolReusePolicy poolReusePolicy,
> - final ConnPoolListener<HttpRoute> connPoolListener,
> final TimeValue timeToLive) {
> super();
> this.connectionOperator = Args.notNull(httpClientConnectionOperator,
> "Connection operator");
> this.connFactory = connFactory != null ? connFactory :
> ManagedHttpClientConnectionFactory.INSTANCE;
> - this.pool = new StrictConnPool<>(
> - DEFAULT_MAX_CONNECTIONS_PER_ROUTE,
> DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, poolReusePolicy,
> connPoolListener);
> + this.pool = new StrictConnPool<>(DEFAULT_MAX_CONNECTIONS_PER_ROUTE,
> DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive,
> + poolReusePolicy, null);
> this.closed = new AtomicBoolean(false);
> }
>
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/io/PoolingHttpClientConnectionMan
> agerBuilder.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManagerBuilder.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManagerBuilder.java
> index 76c36b3..0e3b553 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManagerBuilder.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/
> PoolingHttpClientConnectionManagerBuilder.java
> @@ -28,7 +28,6 @@
> package org.apache.hc.client5.http.impl.io;
>
> import org.apache.hc.client5.http.DnsResolver;
> -import org.apache.hc.client5.http.HttpRoute;
> import org.apache.hc.client5.http.SchemePortResolver;
> import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
> import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
> @@ -38,7 +37,6 @@ import org.apache.hc.client5.http.ssl.
> SSLConnectionSocketFactory;
> import org.apache.hc.core5.http.config.RegistryBuilder;
> import org.apache.hc.core5.http.config.SocketConfig;
> import org.apache.hc.core5.http.io.HttpConnectionFactory;
> -import org.apache.hc.core5.pool.ConnPoolListener;
> import org.apache.hc.core5.pool.PoolReusePolicy;
> import org.apache.hc.core5.util.TimeValue;
>
> @@ -75,7 +73,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
> private SchemePortResolver schemePortResolver;
> private DnsResolver dnsResolver;
> private PoolReusePolicy poolReusePolicy;
> - private ConnPoolListener<HttpRoute> connPoolListener;
> private SocketConfig defaultSocketConfig;
>
> private boolean systemProperties;
> @@ -137,14 +134,6 @@ public class PoolingHttpClientConnectionManagerBuilder
> {
> }
>
> /**
> - * Assigns {@link ConnPoolListener} instance.
> - */
> - public final PoolingHttpClientConnectionManagerBuilder
> setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
> - this.connPoolListener = connPoolListener;
> - return this;
> - }
> -
> - /**
> * Assigns maximum total connection value.
> */
> public final PoolingHttpClientConnectionManagerBuilder
> setMaxConnTotal(final int maxConnTotal) {
> @@ -210,7 +199,6 @@ public class PoolingHttpClientConnectionManagerBuilder
> {
> schemePortResolver,
> dnsResolver,
> poolReusePolicy,
> - connPoolListener,
> timeToLive != null ? timeToLive : TimeValue.NEG_ONE_
> MILLISECONDS);
> poolingmgr.setValidateAfterInactivity(
> this.validateAfterInactivity);
> if (defaultSocketConfig != null) {
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/LogAppendable.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LogAppendable.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/logging/LogAppendable.java
> deleted file mode 100644
> index 181bb95..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LogAppendable.java
> +++ /dev/null
> @@ -1,78 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.io.IOException;
> -
> -import org.apache.logging.log4j.Logger;
> -
> -public final class LogAppendable implements Appendable {
> -
> - private final Logger log;
> - private final String prefix;
> - private final StringBuilder buffer;
> -
> - public LogAppendable(final Logger log, final String prefix) {
> - this.log = log;
> - this.prefix = prefix;
> - this.buffer = new StringBuilder();
> - }
> -
> -
> - @Override
> - public Appendable append(final CharSequence text) throws IOException {
> - return append(text, 0, text.length());
> - }
> -
> - @Override
> - public Appendable append(final CharSequence text, final int start,
> final int end) throws IOException {
> - for (int i = start; i < end; i++) {
> - append(text.charAt(i));
> - }
> - return this;
> - }
> -
> - @Override
> - public Appendable append(final char ch) throws IOException {
> - if (ch == '\n') {
> - log.debug(prefix + " " + buffer.toString());
> - buffer.setLength(0);
> - } else if (ch != '\r') {
> - buffer.append(ch);
> - }
> - return this;
> - }
> -
> - public void flush() {
> - if (buffer.length() > 0) {
> - log.debug(prefix + " " + buffer.toString());
> - buffer.setLength(0);
> - }
> - }
> -
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/LoggingIOSession.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LoggingIOSession.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/logging/LoggingIOSession.java
> deleted file mode 100644
> index c750f7a..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LoggingIOSession.java
> +++ /dev/null
> @@ -1,269 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.io.IOException;
> -import java.net.SocketAddress;
> -import java.nio.ByteBuffer;
> -import java.nio.channels.ByteChannel;
> -import java.nio.channels.SelectionKey;
> -
> -import javax.net.ssl.SSLContext;
> -
> -import org.apache.hc.core5.io.ShutdownType;
> -import org.apache.hc.core5.reactor.Command;
> -import org.apache.hc.core5.reactor.IOEventHandler;
> -import org.apache.hc.core5.reactor.TlsCapableIOSession;
> -import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
> -import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
> -import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
> -import org.apache.hc.core5.reactor.ssl.TlsDetails;
> -import org.apache.logging.log4j.Logger;
> -
> -public class LoggingIOSession implements TlsCapableIOSession {
> -
> - private final Logger log;
> - private final Wire wirelog;
> - private final String id;
> - private final TlsCapableIOSession session;
> - private final ByteChannel channel;
> -
> - public LoggingIOSession(final TlsCapableIOSession session, final
> String id, final Logger log, final Logger wirelog) {
> - super();
> - this.session = session;
> - this.id = id;
> - this.log = log;
> - this.wirelog = new Wire(wirelog, this.id);
> - this.channel = new LoggingByteChannel();
> - }
> -
> - public LoggingIOSession(final TlsCapableIOSession session, final
> String id, final Logger log) {
> - this(session, id, log, null);
> - }
> -
> - @Override
> - public String getId() {
> - return session.getId();
> - }
> -
> - @Override
> - public void addLast(final Command command) {
> - this.session.addLast(command);
> - }
> -
> - @Override
> - public void addFirst(final Command command) {
> - this.session.addFirst(command);
> - }
> -
> - @Override
> - public Command getCommand() {
> - return this.session.getCommand();
> - }
> -
> - @Override
> - public ByteChannel channel() {
> - return this.channel;
> - }
> -
> - @Override
> - public SocketAddress getLocalAddress() {
> - return this.session.getLocalAddress();
> - }
> -
> - @Override
> - public SocketAddress getRemoteAddress() {
> - return this.session.getRemoteAddress();
> - }
> -
> - @Override
> - public int getEventMask() {
> - return this.session.getEventMask();
> - }
> -
> - private static String formatOps(final int ops) {
> - final StringBuilder buffer = new StringBuilder(6);
> - buffer.append('[');
> - if ((ops & SelectionKey.OP_READ) > 0) {
> - buffer.append('r');
> - }
> - if ((ops & SelectionKey.OP_WRITE) > 0) {
> - buffer.append('w');
> - }
> - if ((ops & SelectionKey.OP_ACCEPT) > 0) {
> - buffer.append('a');
> - }
> - if ((ops & SelectionKey.OP_CONNECT) > 0) {
> - buffer.append('c');
> - }
> - buffer.append(']');
> - return buffer.toString();
> - }
> -
> - @Override
> - public void setEventMask(final int ops) {
> - this.session.setEventMask(ops);
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Event mask
> set " + formatOps(ops));
> - }
> - }
> -
> - @Override
> - public void setEvent(final int op) {
> - this.session.setEvent(op);
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Event set "
> + formatOps(op));
> - }
> - }
> -
> - @Override
> - public void clearEvent(final int op) {
> - this.session.clearEvent(op);
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Event
> cleared " + formatOps(op));
> - }
> - }
> -
> - @Override
> - public void close() {
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Close");
> - }
> - this.session.close();
> - }
> -
> - @Override
> - public int getStatus() {
> - return this.session.getStatus();
> - }
> -
> - @Override
> - public boolean isClosed() {
> - return this.session.isClosed();
> - }
> -
> - @Override
> - public void shutdown(final ShutdownType shutdownType) {
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Shutdown "
> + shutdownType);
> - }
> - this.session.shutdown(shutdownType);
> - }
> -
> - @Override
> - public int getSocketTimeout() {
> - return this.session.getSocketTimeout();
> - }
> -
> - @Override
> - public void setSocketTimeout(final int timeout) {
> - if (this.log.isDebugEnabled()) {
> - this.log.debug(this.id + " " + this.session + ": Set timeout
> " + timeout);
> - }
> - this.session.setSocketTimeout(timeout);
> - }
> -
> - @Override
> - public IOEventHandler getHandler() {
> - return this.session.getHandler();
> - }
> -
> - @Override
> - public void setHandler(final IOEventHandler handler) {
> - this.session.setHandler(handler);
> - }
> -
> - @Override
> - public void startTls(
> - final SSLContext sslContext,
> - final SSLBufferManagement sslBufferManagement,
> - final SSLSessionInitializer initializer,
> - final SSLSessionVerifier verifier) throws
> UnsupportedOperationException {
> - session.startTls(sslContext, sslBufferManagement, initializer,
> verifier);
> - }
> -
> - @Override
> - public TlsDetails getTlsDetails() {
> - return session.getTlsDetails();
> - }
> -
> - @Override
> - public String toString() {
> - return this.id + " " + this.session.toString();
> - }
> -
> - class LoggingByteChannel implements ByteChannel {
> -
> - @Override
> - public int read(final ByteBuffer dst) throws IOException {
> - final int bytesRead = session.channel().read(dst);
> - if (log.isDebugEnabled()) {
> - log.debug(id + " " + session + ": " + bytesRead + " bytes
> read");
> - }
> - if (bytesRead > 0 && wirelog.isEnabled()) {
> - final ByteBuffer b = dst.duplicate();
> - final int p = b.position();
> - b.limit(p);
> - b.position(p - bytesRead);
> - wirelog.input(b);
> - }
> - return bytesRead;
> - }
> -
> - @Override
> - public int write(final ByteBuffer src) throws IOException {
> - final int byteWritten = session.channel().write(src);
> - if (log.isDebugEnabled()) {
> - log.debug(id + " " + session + ": " + byteWritten + "
> bytes written");
> - }
> - if (byteWritten > 0 && wirelog.isEnabled()) {
> - final ByteBuffer b = src.duplicate();
> - final int p = b.position();
> - b.limit(p);
> - b.position(p - byteWritten);
> - wirelog.output(b);
> - }
> - return byteWritten;
> - }
> -
> - @Override
> - public void close() throws IOException {
> - if (log.isDebugEnabled()) {
> - log.debug(id + " " + session + ": Channel close");
> - }
> - session.channel().close();
> - }
> -
> - @Override
> - public boolean isOpen() {
> - return session.channel().isOpen();
> - }
> -
> - }
> -
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/LoggingInputStream.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LoggingInputStream.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/logging/LoggingInputStream.java
> deleted file mode 100644
> index 018fae6..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/
> LoggingInputStream.java
> +++ /dev/null
> @@ -1,137 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.io.IOException;
> -import java.io.InputStream;
> -
> -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 {
> - try {
> - final int b = in.read();
> - if (b == -1) {
> - wire.input("end of stream");
> - } else {
> - wire.input(b);
> - }
> - return b;
> - } catch (final IOException ex) {
> - wire.input("[read] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public int read(final byte[] b) throws IOException {
> - try {
> - final int bytesRead = in.read(b);
> - if (bytesRead == -1) {
> - wire.input("end of stream");
> - } else if (bytesRead > 0) {
> - wire.input(b, 0, bytesRead);
> - }
> - return bytesRead;
> - } catch (final IOException ex) {
> - wire.input("[read] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public int read(final byte[] b, final int off, final int len) throws
> IOException {
> - try {
> - final int bytesRead = in.read(b, off, len);
> - if (bytesRead == -1) {
> - wire.input("end of stream");
> - } else if (bytesRead > 0) {
> - wire.input(b, off, bytesRead);
> - }
> - return bytesRead;
> - } catch (final IOException ex) {
> - wire.input("[read] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public long skip(final long n) throws IOException {
> - try {
> - return super.skip(n);
> - } catch (final IOException ex) {
> - wire.input("[skip] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public int available() throws IOException {
> - try {
> - return in.available();
> - } catch (final IOException ex) {
> - wire.input("[available] I/O error : " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public void mark(final int readlimit) {
> - super.mark(readlimit);
> - }
> -
> - @Override
> - public void reset() throws IOException {
> - super.reset();
> - }
> -
> - @Override
> - public boolean markSupported() {
> - return false;
> - }
> -
> - @Override
> - public void close() throws IOException {
> - try {
> - in.close();
> - } catch (final IOException ex) {
> - wire.input("[close] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/LoggingOutputStream.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LoggingOutputStream.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java
> deleted file mode 100644
> index ec82d1f..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/
> LoggingOutputStream.java
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.io.IOException;
> -import java.io.OutputStream;
> -
> -/**
> - * Internal class.
> - *
> - * @since 4.3
> - */
> -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(final int b) throws IOException {
> - try {
> - out.write(b);
> - wire.output(b);
> - } catch (final IOException ex) {
> - wire.output("[write] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public void write(final byte[] b) throws IOException {
> - try {
> - wire.output(b);
> - out.write(b);
> - } catch (final IOException ex) {
> - wire.output("[write] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public void write(final byte[] b, final int off, final int len)
> throws IOException {
> - try {
> - wire.output(b, off, len);
> - out.write(b, off, len);
> - } catch (final IOException ex) {
> - wire.output("[write] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public void flush() throws IOException {
> - try {
> - out.flush();
> - } catch (final IOException ex) {
> - wire.output("[flush] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> - @Override
> - public void close() throws IOException {
> - try {
> - out.close();
> - } catch (final IOException ex) {
> - wire.output("[close] I/O error: " + ex.getMessage());
> - throw ex;
> - }
> - }
> -
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/LoggingSocketHolder.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/LoggingSocketHolder.java b/httpclient5/src/main/java/
> org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java
> deleted file mode 100644
> index ddde402..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/
> LoggingSocketHolder.java
> +++ /dev/null
> @@ -1,56 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.io.IOException;
> -import java.io.InputStream;
> -import java.io.OutputStream;
> -import java.net.Socket;
> -
> -import org.apache.hc.core5.http.impl.io.SocketHolder;
> -import org.apache.logging.log4j.Logger;
> -
> -public class LoggingSocketHolder extends SocketHolder {
> -
> - private final Wire wire;
> -
> - public LoggingSocketHolder(final Socket socket, final String id,
> final Logger log) {
> - super(socket);
> - this.wire = new Wire(log, id);
> - }
> -
> - @Override
> - protected InputStream getInputStream(final Socket socket) throws
> IOException {
> - return new LoggingInputStream(super.getInputStream(socket),
> wire);
> - }
> -
> - @Override
> - protected OutputStream getOutputStream(final Socket socket) throws
> IOException {
> - return new LoggingOutputStream(super.getOutputStream(socket),
> wire);
> - }
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/logging/Wire.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/Wire.java
> deleted file mode 100644
> index 8bd9e4f..0000000
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/logging/Wire.java
> +++ /dev/null
> @@ -1,175 +0,0 @@
> -/*
> - * ====================================================================
> - * 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.hc.client5.http.impl.logging;
> -
> -import java.nio.ByteBuffer;
> -
> -import org.apache.hc.core5.util.Args;
> -import org.apache.logging.log4j.Logger;
> -
> -class Wire {
> -
> - private static final int MAX_STRING_BUILDER_SIZE = 2048;
> -
> - private static final ThreadLocal<StringBuilder> threadLocal = new
> ThreadLocal<>();
> -
> - /**
> - * Returns a {@code StringBuilder} that this Layout implementation
> can use to write the formatted log event to.
> - *
> - * @return a {@code StringBuilder}
> - */
> - private static StringBuilder getStringBuilder() {
> - StringBuilder result = threadLocal.get();
> - if (result == null) {
> - result = new StringBuilder(MAX_STRING_BUILDER_SIZE);
> - threadLocal.set(result);
> - }
> - // TODO Delegate to Log4j's 2.9 StringBuilds.trimToMaxSize() when
> it is released.
> - trimToMaxSize(result, MAX_STRING_BUILDER_SIZE);
> - result.setLength(0);
> - return result;
> - }
> -
> - /**
> - * Ensures that the char[] array of the specified StringBuilder does
> not exceed the specified number of characters.
> - * This method is useful to ensure that excessively long char[]
> arrays are not kept in memory forever.
> - *
> - * @param stringBuilder the StringBuilder to check
> - * @param maxSize the maximum number of characters the StringBuilder
> is allowed to have
> - */
> - // TODO Delete wheb Log4j's 2.9 (see #trimToMaxSize(StringBuild))
> - private static void trimToMaxSize(final StringBuilder stringBuilder,
> final int maxSize) {
> - if (stringBuilder != null && stringBuilder.capacity() > maxSize) {
> - stringBuilder.setLength(maxSize);
> - stringBuilder.trimToSize();
> - }
> - }
> -
> - private final Logger log;
> - private final String id;
> -
> - Wire(final Logger log, final String id) {
> - super();
> - this.log = log;
> - this.id = id;
> - }
> -
> - private void wire(final String header, final byte[] b, final int pos,
> final int off) {
> - final StringBuilder buffer = getStringBuilder();
> - for (int i = 0; i < off; i++) {
> - final int ch = b[pos + i];
> - if (ch == 13) {
> - buffer.append("[\\r]");
> - } else if (ch == 10) {
> - buffer.append("[\\n]\"");
> - buffer.insert(0, "\"");
> - buffer.insert(0, header);
> - this.log.debug(this.id + " " + buffer.toString());
> - buffer.setLength(0);
> - } else if ((ch < 32) || (ch > 127)) {
> - buffer.append("[0x");
> - buffer.append(Integer.toHexString(ch));
> - buffer.append("]");
> - } else {
> - buffer.append((char) ch);
> - }
> - }
> - if (buffer.length() > 0) {
> - buffer.append('\"');
> - buffer.insert(0, '\"');
> - buffer.insert(0, header);
> - this.log.debug(this.id + " " + buffer.toString());
> - }
> - }
> -
> -
> - public boolean isEnabled() {
> - return this.log.isDebugEnabled();
> - }
> -
> - public void output(final byte[] b, final int pos, final int off) {
> - Args.notNull(b, "Output");
> - wire(">> ", b, pos, off);
> - }
> -
> - public void input(final byte[] b, final int pos, final int off) {
> - Args.notNull(b, "Input");
> - wire("<< ", b, pos, off);
> - }
> -
> - public void output(final byte[] b) {
> - Args.notNull(b, "Output");
> - output(b, 0, b.length);
> - }
> -
> - public void input(final byte[] b) {
> - Args.notNull(b, "Input");
> - input(b, 0, b.length);
> - }
> -
> - public void output(final int b) {
> - output(new byte[] {(byte) b});
> - }
> -
> - public void input(final int b) {
> - input(new byte[] {(byte) b});
> - }
> -
> - public void output(final String s) {
> - Args.notNull(s, "Output");
> - output(s.getBytes());
> - }
> -
> - public void input(final String s) {
> - Args.notNull(s, "Input");
> - input(s.getBytes());
> - }
> -
> - public void output(final ByteBuffer b) {
> - Args.notNull(b, "Output");
> - if (b.hasArray()) {
> - output(b.array(), b.arrayOffset() + b.position(),
> b.remaining());
> - } else {
> - final byte[] tmp = new byte[b.remaining()];
> - b.get(tmp);
> - output(tmp);
> - }
> - }
> -
> - public void input(final ByteBuffer b) {
> - Args.notNull(b, "Input");
> - if (b.hasArray()) {
> - input(b.array(), b.arrayOffset() + b.position(),
> b.remaining());
> - } else {
> - final byte[] tmp = new byte[b.remaining()];
> - b.get(tmp);
> - input(tmp);
> - }
> - }
> -
> -}
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/nio/PoolingAsyncClientConnectionManager.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManager.java
> index 59d37bb..93ce8eb 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManager.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManager.java
> @@ -58,7 +58,6 @@ import org.apache.hc.core5.http2.nio.
> command.PingCommand;
> import org.apache.hc.core5.http2.nio.support.BasicPingHandler;
> import org.apache.hc.core5.io.ShutdownType;
> import org.apache.hc.core5.pool.ConnPoolControl;
> -import org.apache.hc.core5.pool.ConnPoolListener;
> import org.apache.hc.core5.pool.PoolEntry;
> import org.apache.hc.core5.pool.PoolReusePolicy;
> import org.apache.hc.core5.pool.PoolStats;
> @@ -106,10 +105,9 @@ public class PoolingAsyncClientConnectionManager
> implements AsyncClientConnectio
> final SchemePortResolver schemePortResolver,
> final DnsResolver dnsResolver,
> final TimeValue timeToLive,
> - final PoolReusePolicy poolReusePolicy,
> - final ConnPoolListener<HttpRoute> connPoolListener) {
> + final PoolReusePolicy poolReusePolicy) {
> this.connectionOperator = new AsyncClientConnectionOperator(schemePortResolver,
> dnsResolver, tlsStrategyLookup);
> - this.pool = new StrictConnPool<>(20, 50, timeToLive,
> poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO,
> connPoolListener);
> + this.pool = new StrictConnPool<>(20, 50, timeToLive,
> poolReusePolicy != null ? poolReusePolicy : PoolReusePolicy.LIFO, null);
> this.closed = new AtomicBoolean(false);
> }
>
> @@ -400,7 +398,7 @@ public class PoolingAsyncClientConnectionManager
> implements AsyncClientConnectio
>
> InternalConnectionEndpoint(final PoolEntry<HttpRoute,
> ManagedAsyncClientConnection> poolEntry) {
> this.poolEntryRef = new AtomicReference<>(poolEntry);
> - this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet());
> + this.id = String.format("ep-%08X", COUNT.getAndIncrement());
> }
>
> @Override
>
> http://git-wip-us.apache.org/repos/asf/httpcomponents-
> client/blob/e8f72b7c/httpclient5/src/main/java/org/
> apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionMa
> nagerBuilder.java
> ----------------------------------------------------------------------
> diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/
> impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
> b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManagerBuilder.java
> index 9a840ad..ed2e42d 100644
> --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManagerBuilder.java
> +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/
> PoolingAsyncClientConnectionManagerBuilder.java
> @@ -31,12 +31,10 @@ import java.security.AccessController;
> import java.security.PrivilegedAction;
>
> import org.apache.hc.client5.http.DnsResolver;
> -import org.apache.hc.client5.http.HttpRoute;
> import org.apache.hc.client5.http.SchemePortResolver;
> import org.apache.hc.client5.http.ssl.H2TlsStrategy;
> import org.apache.hc.core5.http.config.RegistryBuilder;
> import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
> -import org.apache.hc.core5.pool.ConnPoolListener;
> import org.apache.hc.core5.pool.PoolReusePolicy;
> import org.apache.hc.core5.util.TimeValue;
>
> @@ -72,7 +70,6 @@ public class PoolingAsyncClientConnectionManagerBuilder
> {
> private SchemePortResolver schemePortResolver;
> private DnsResolver dnsResolver;
> private PoolReusePolicy poolReusePolicy;
> - private ConnPoolListener<HttpRoute> connPoolListener;
>
> private boolean systemProperties;
>
> @@ -124,14 +121,6 @@ public class PoolingAsyncClientConnectionManagerBuilder
> {
> }
>
> /**
> - * Assigns {@link ConnPoolListener} instance.
> - */
> - public final PoolingAsyncClientConnectionManagerBuilder
> setConnPoolListener(final ConnPoolListener<HttpRoute> connPoolListener) {
> - this.connPoolListener = connPoolListener;
> - return this;
> - }
> -
> - /**
> * Assigns maximum total connection value.
> */
> public final PoolingAsyncClientConnectionManagerBuilder
> setMaxConnTotal(final int maxConnTotal) {
> @@ -184,8 +173,7 @@ public class PoolingAsyncClientConnectionManagerBuilder
> {
> schemePortResolver,
> dnsResolver,
> timeToLive,
> - poolReusePolicy,
> - connPoolListener);
> + poolReusePolicy);
> poolingmgr.setValidateAfterInactivity(
> this.validateAfterInactivity);
> if (maxConnTotal > 0) {
> poolingmgr.setMaxTotal(maxConnTotal);
>
>