FileDocCategorySizeDatePackage
AbstractHttpClientConnection.javaAPI DocAndroid 1.5 API7550Wed May 06 22:41:10 BST 2009org.apache.http.impl

AbstractHttpClientConnection

public abstract class AbstractHttpClientConnection extends Object implements HttpClientConnection
Abstract client-side HTTP connection capable of transmitting and receiving data using arbitrary {@link SessionInputBuffer} and {@link SessionOutputBuffer}
author
Oleg Kalnichevski
version
$Revision: 627457 $
since
4.0

Fields Summary
private final EntitySerializer
entityserializer
private final EntityDeserializer
entitydeserializer
private SessionInputBuffer
inbuffer
private SessionOutputBuffer
outbuffer
private HttpMessageParser
responseParser
private HttpMessageWriter
requestWriter
private HttpConnectionMetricsImpl
metrics
Constructors Summary
public AbstractHttpClientConnection()




      
        super();
        this.entityserializer = createEntitySerializer();
        this.entitydeserializer = createEntityDeserializer();
    
Methods Summary
protected abstract voidassertOpen()

protected org.apache.http.impl.entity.EntityDeserializercreateEntityDeserializer()

        return new EntityDeserializer(new LaxContentLengthStrategy());
    
protected org.apache.http.impl.entity.EntitySerializercreateEntitySerializer()

        return new EntitySerializer(new StrictContentLengthStrategy());
    
protected org.apache.http.HttpResponseFactorycreateHttpResponseFactory()

        return new DefaultHttpResponseFactory();
    
protected org.apache.http.io.HttpMessageWritercreateRequestWriter(org.apache.http.io.SessionOutputBuffer buffer, org.apache.http.params.HttpParams params)

        // override in derived class to specify a line formatter
        return new HttpRequestWriter(buffer, null, params);
    
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 HttpResponseParser(buffer, null, responseFactory, params);
    
protected voiddoFlush()

        this.outbuffer.flush();
    
public voidflush()

        assertOpen();
        doFlush();
    
public org.apache.http.HttpConnectionMetricsgetMetrics()

        return this.metrics;
    
protected voidinit(org.apache.http.io.SessionInputBuffer inbuffer, org.apache.http.io.SessionOutputBuffer outbuffer, org.apache.http.params.HttpParams params)

        if (inbuffer == null) {
            throw new IllegalArgumentException("Input session buffer may not be null");
        }
        if (outbuffer == null) {
            throw new IllegalArgumentException("Output session buffer may not be null");
        }
        this.inbuffer = inbuffer;
        this.outbuffer = outbuffer;
        this.responseParser = createResponseParser(
                inbuffer, 
                createHttpResponseFactory(), 
                params);
        this.requestWriter = createRequestWriter(
                outbuffer, params);
        this.metrics = new HttpConnectionMetricsImpl(
                inbuffer.getMetrics(),
                outbuffer.getMetrics());
    
public booleanisResponseAvailable(int timeout)

        assertOpen();
        return this.inbuffer.isDataAvailable(timeout);
    
public booleanisStale()

        if (!isOpen()) {
            return true;
        }
        try {
            this.inbuffer.isDataAvailable(1);
            return false;
        } catch (IOException ex) {
            return true;
        }
    
public voidreceiveResponseEntity(org.apache.http.HttpResponse response)

        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        assertOpen();
        HttpEntity entity = this.entitydeserializer.deserialize(this.inbuffer, response);
        response.setEntity(entity);
    
public org.apache.http.HttpResponsereceiveResponseHeader()

        assertOpen();
        HttpResponse response = (HttpResponse) this.responseParser.parse();
        if (response.getStatusLine().getStatusCode() >= 200) {
            this.metrics.incrementResponseCount();
        }
        return response;
    
public voidsendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)

        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        assertOpen();
        if (request.getEntity() == null) {
            return;
        }
        this.entityserializer.serialize(
                this.outbuffer,
                request,
                request.getEntity());
    
public voidsendRequestHeader(org.apache.http.HttpRequest request)

        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        assertOpen();
        this.requestWriter.write(request);
        this.metrics.incrementRequestCount();