FileDocCategorySizeDatePackage
DefaultClientConnection.javaAPI DocAndroid 1.5 API8387Wed May 06 22:41:10 BST 2009org.apache.http.impl.conn

DefaultClientConnection

public class DefaultClientConnection extends SocketHttpClientConnection implements OperatedClientConnection
Default implementation of an operated client connection.
author
Roland Weber
version
$Revision: 673450 $ $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
since
4.0

Fields Summary
private final Log
log
private final Log
headerLog
private final Log
wireLog
private volatile Socket
socket
The unconnected socket
private HttpHost
targetHost
The target host of this connection.
private boolean
connSecure
Whether this connection is secure.
private volatile boolean
shutdown
True if this connection was shutdown.
Constructors Summary
public DefaultClientConnection()


      
        super();
    
Methods Summary
public voidclose()

        log.debug("Connection closed");
        super.close();
    
protected org.apache.http.io.HttpMessageParsercreateResponseParser(org.apache.http.io.SessionInputBuffer buffer, org.apache.http.HttpResponseFactory responseFactory, org.apache.http.params.HttpParams params)

        // override in derived class to specify a line parser
        return new DefaultResponseParser
            (buffer, null, responseFactory, params);
    
protected org.apache.http.io.SessionInputBuffercreateSessionInputBuffer(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)

        SessionInputBuffer inbuffer = super.createSessionInputBuffer(
                socket, 
                buffersize,
                params);
        if (wireLog.isDebugEnabled()) {
            inbuffer = new LoggingSessionInputBuffer(inbuffer, new Wire(wireLog));
        }
        return inbuffer;
    
protected org.apache.http.io.SessionOutputBuffercreateSessionOutputBuffer(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)

        SessionOutputBuffer outbuffer = super.createSessionOutputBuffer(
                socket,
                buffersize,
                params);
        if (wireLog.isDebugEnabled()) {
            outbuffer = new LoggingSessionOutputBuffer(outbuffer, new Wire(wireLog));
        }
        return outbuffer;
    
public final java.net.SocketgetSocket()

        return this.socket;
    
public final org.apache.http.HttpHostgetTargetHost()

        return this.targetHost;
    
public final booleanisSecure()

        return this.connSecure;
    
public voidopenCompleted(boolean secure, org.apache.http.params.HttpParams params)

        assertNotOpen();
        if (params == null) {
            throw new IllegalArgumentException
                ("Parameters must not be null.");
        }
        this.connSecure = secure;
        bind(this.socket, params);
    
public voidopening(java.net.Socket sock, org.apache.http.HttpHost target)

        assertNotOpen();        
        this.socket = sock;
        this.targetHost = target;
        
        // Check for shutdown after assigning socket, so that 
        if (this.shutdown) {
            sock.close(); // allow this to throw...
            // ...but if it doesn't, explicitly throw one ourselves.
            throw new IOException("Connection already shutdown");
        }
    
public org.apache.http.HttpResponsereceiveResponseHeader()

        HttpResponse response = super.receiveResponseHeader();
        if (headerLog.isDebugEnabled()) {
            headerLog.debug("<< " + response.getStatusLine().toString());
            Header[] headers = response.getAllHeaders();
            for (Header header : headers) {
                headerLog.debug("<< " + header.toString());
            }
        }
        return response;
    
public voidsendRequestHeader(org.apache.http.HttpRequest request)

        super.sendRequestHeader(request);
        if (headerLog.isDebugEnabled()) {
            headerLog.debug(">> " + request.getRequestLine().toString());
            Header[] headers = request.getAllHeaders();
            for (Header header : headers) {
                headerLog.debug(">> " + header.toString());
            }
        }
    
public voidshutdown()
Force-closes this connection. If the connection is still in the process of being open (the method {@link #opening opening} was already called but {@link #openCompleted openCompleted} was not), the associated socket that is being connected to a remote address will be closed. That will interrupt a thread that is blocked on connecting the socket. If the connection is not yet open, this will prevent the connection from being opened.

throws
IOException in case of a problem

        log.debug("Connection shut down");
        shutdown = true;
        
        super.shutdown();        
        Socket sock = this.socket; // copy volatile attribute
        if (sock != null)
            sock.close();

    
public voidupdate(java.net.Socket sock, org.apache.http.HttpHost target, boolean secure, org.apache.http.params.HttpParams params)


        assertOpen();
        if (target == null) {
            throw new IllegalArgumentException
                ("Target host must not be null.");
        }
        if (params == null) {
            throw new IllegalArgumentException
                ("Parameters must not be null.");
        }

        if (sock != null) {
            this.socket = sock;
            bind(sock, params);
        }
        targetHost = target;
        connSecure = secure;