Search in sources :

Example 6 with DefaultedHttpParams

use of org.apache.http.params.DefaultedHttpParams in project robovm by robovm.

the class HttpService method handleRequest.

public void handleRequest(final HttpServerConnection conn, final HttpContext context) throws IOException, HttpException {
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    HttpResponse response = null;
    try {
        HttpRequest request = conn.receiveRequestHeader();
        request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
            // Downgrade protocol version if greater than HTTP/1.1 
            ver = HttpVersion.HTTP_1_1;
        }
        if (request instanceof HttpEntityEnclosingRequest) {
            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
                response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context);
                response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                if (this.expectationVerifier != null) {
                    try {
                        this.expectationVerifier.verify(request, response, context);
                    } catch (HttpException ex) {
                        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
                        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                        handleException(ex, response);
                    }
                }
                if (response.getStatusLine().getStatusCode() < 200) {
                    // Send 1xx response indicating the server expections
                    // have been met
                    conn.sendResponseHeader(response);
                    conn.flush();
                    response = null;
                    conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
                }
            } else {
                conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
            }
        }
        if (response == null) {
            response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
            response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
            context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
            context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
            this.processor.process(request, context);
            doService(request, response, context);
        }
        // Make sure the request content is fully consumed
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
            if (entity != null) {
                entity.consumeContent();
            }
        }
    } catch (HttpException ex) {
        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
        handleException(ex, response);
    }
    this.processor.process(response, context);
    conn.sendResponseHeader(response);
    conn.sendResponseEntity(response);
    conn.flush();
    if (!this.connStrategy.keepAlive(response, context)) {
        conn.close();
    }
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) ProtocolVersion(org.apache.http.ProtocolVersion) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 7 with DefaultedHttpParams

use of org.apache.http.params.DefaultedHttpParams in project XobotOS by xamarin.

the class HttpService method handleRequest.

public void handleRequest(final HttpServerConnection conn, final HttpContext context) throws IOException, HttpException {
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    HttpResponse response = null;
    try {
        HttpRequest request = conn.receiveRequestHeader();
        request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
            // Downgrade protocol version if greater than HTTP/1.1 
            ver = HttpVersion.HTTP_1_1;
        }
        if (request instanceof HttpEntityEnclosingRequest) {
            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
                response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context);
                response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                if (this.expectationVerifier != null) {
                    try {
                        this.expectationVerifier.verify(request, response, context);
                    } catch (HttpException ex) {
                        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
                        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                        handleException(ex, response);
                    }
                }
                if (response.getStatusLine().getStatusCode() < 200) {
                    // Send 1xx response indicating the server expections
                    // have been met
                    conn.sendResponseHeader(response);
                    conn.flush();
                    response = null;
                    conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
                }
            } else {
                conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
            }
        }
        if (response == null) {
            response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
            response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
            context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
            context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
            this.processor.process(request, context);
            doService(request, response, context);
        }
        // Make sure the request content is fully consumed
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
            if (entity != null) {
                entity.consumeContent();
            }
        }
    } catch (HttpException ex) {
        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
        handleException(ex, response);
    }
    this.processor.process(response, context);
    conn.sendResponseHeader(response);
    conn.sendResponseEntity(response);
    conn.flush();
    if (!this.connStrategy.keepAlive(response, context)) {
        conn.close();
    }
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) ProtocolVersion(org.apache.http.ProtocolVersion) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 8 with DefaultedHttpParams

use of org.apache.http.params.DefaultedHttpParams in project android_frameworks_base by ResurrectionRemix.

the class TestHttpClient method execute.

public HttpResponse execute(final HttpRequest request, final HttpHost targetHost, final HttpClientConnection conn) throws HttpException, IOException {
    this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
    this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
    this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
    this.httpexecutor.preProcess(request, this.httpproc, this.context);
    HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
    response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
    this.httpexecutor.postProcess(response, this.httpproc, this.context);
    return response;
}
Also used : HttpResponse(org.apache.http.HttpResponse) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 9 with DefaultedHttpParams

use of org.apache.http.params.DefaultedHttpParams in project platform_external_apache-http by android.

the class HttpService method handleRequest.

public void handleRequest(final HttpServerConnection conn, final HttpContext context) throws IOException, HttpException {
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    HttpResponse response = null;
    try {
        HttpRequest request = conn.receiveRequestHeader();
        request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
            // Downgrade protocol version if greater than HTTP/1.1 
            ver = HttpVersion.HTTP_1_1;
        }
        if (request instanceof HttpEntityEnclosingRequest) {
            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
                response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context);
                response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                if (this.expectationVerifier != null) {
                    try {
                        this.expectationVerifier.verify(request, response, context);
                    } catch (HttpException ex) {
                        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
                        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
                        handleException(ex, response);
                    }
                }
                if (response.getStatusLine().getStatusCode() < 200) {
                    // Send 1xx response indicating the server expections
                    // have been met
                    conn.sendResponseHeader(response);
                    conn.flush();
                    response = null;
                    conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
                }
            } else {
                conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
            }
        }
        if (response == null) {
            response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
            response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
            context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
            context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
            this.processor.process(request, context);
            doService(request, response, context);
        }
        // Make sure the request content is fully consumed
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
            if (entity != null) {
                entity.consumeContent();
            }
        }
    } catch (HttpException ex) {
        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
        handleException(ex, response);
    }
    this.processor.process(response, context);
    conn.sendResponseHeader(response);
    conn.sendResponseEntity(response);
    conn.flush();
    if (!this.connStrategy.keepAlive(response, context)) {
        conn.close();
    }
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) ProtocolVersion(org.apache.http.ProtocolVersion) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Example 10 with DefaultedHttpParams

use of org.apache.http.params.DefaultedHttpParams in project android_frameworks_base by crdroidandroid.

the class TestHttpClient method execute.

public HttpResponse execute(final HttpRequest request, final HttpHost targetHost, final HttpClientConnection conn) throws HttpException, IOException {
    this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
    this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
    this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
    this.httpexecutor.preProcess(request, this.httpproc, this.context);
    HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
    response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
    this.httpexecutor.postProcess(response, this.httpproc, this.context);
    return response;
}
Also used : HttpResponse(org.apache.http.HttpResponse) DefaultedHttpParams(org.apache.http.params.DefaultedHttpParams)

Aggregations

DefaultedHttpParams (org.apache.http.params.DefaultedHttpParams)10 HttpResponse (org.apache.http.HttpResponse)8 HttpEntity (org.apache.http.HttpEntity)3 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)3 HttpException (org.apache.http.HttpException)3 HttpRequest (org.apache.http.HttpRequest)3 ProtocolVersion (org.apache.http.ProtocolVersion)3 BasicHttpParams (org.apache.http.params.BasicHttpParams)2 HttpParams (org.apache.http.params.HttpParams)2 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 NTCredentials (org.apache.http.auth.NTCredentials)1 HttpRequestRetryHandler (org.apache.http.client.HttpRequestRetryHandler)1 DnsResolver (org.apache.http.conn.DnsResolver)1 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)1 AbstractHttpClient (org.apache.http.impl.client.AbstractHttpClient)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 StandardHttpRequestRetryHandler (org.apache.http.impl.client.StandardHttpRequestRetryHandler)1 SystemDefaultDnsResolver (org.apache.http.impl.conn.SystemDefaultDnsResolver)1