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

AbstractHttpServerConnection

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

Fields Summary
private final EntitySerializer
entityserializer
private final EntityDeserializer
entitydeserializer
private SessionInputBuffer
inbuffer
private SessionOutputBuffer
outbuffer
private HttpMessageParser
requestParser
private HttpMessageWriter
responseWriter
private HttpConnectionMetricsImpl
metrics
Constructors Summary
public AbstractHttpServerConnection()




      
        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.HttpRequestFactorycreateHttpRequestFactory()

        return new DefaultHttpRequestFactory();
    
protected org.apache.http.io.HttpMessageParsercreateRequestParser(org.apache.http.io.SessionInputBuffer buffer, org.apache.http.HttpRequestFactory requestFactory, org.apache.http.params.HttpParams params)

        // override in derived class to specify a line parser
        return new HttpRequestParser(buffer, null, requestFactory, params);
    
protected org.apache.http.io.HttpMessageWritercreateResponseWriter(org.apache.http.io.SessionOutputBuffer buffer, org.apache.http.params.HttpParams params)

        // override in derived class to specify a line formatter
        return new HttpResponseWriter(buffer, null, 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.requestParser = createRequestParser(
                inbuffer, 
                createHttpRequestFactory(), 
                params);
        this.responseWriter = createResponseWriter(
                outbuffer, params);
        this.metrics = new HttpConnectionMetricsImpl(
                inbuffer.getMetrics(),
                outbuffer.getMetrics());
    
public booleanisStale()

        assertOpen();
        try {
            this.inbuffer.isDataAvailable(1);
            return false;
        } catch (IOException ex) {
            return true;
        }
    
public voidreceiveRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)

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

        assertOpen();
        HttpRequest request = (HttpRequest) this.requestParser.parse();
        this.metrics.incrementRequestCount();
        return request;
    
public voidsendResponseEntity(org.apache.http.HttpResponse response)

        if (response.getEntity() == null) {
            return;
        }
        this.entityserializer.serialize(
                this.outbuffer,
                response,
                response.getEntity());
    
public voidsendResponseHeader(org.apache.http.HttpResponse response)

        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        assertOpen();
        this.responseWriter.write(response);
        if (response.getStatusLine().getStatusCode() >= 200) {
            this.metrics.incrementResponseCount();
        }