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();
}
}
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();
}
}
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;
}
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();
}
}
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;
}
Aggregations