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