connState.setInputState(ServerConnState.REQUEST_RECEIVED);
connState.setRequest(request);
connState.setWorkerRunning(true);
}
request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
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;
}
HttpResponse response = null;
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest eeRequest = (HttpEntityEnclosingRequest) request;
if (eeRequest.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
synchronized (connState) {
connState.setResponse(response);
conn.requestOutput();
// Block until 1xx response is sent to the client
try {
for (;;) {
int currentState = connState.getOutputState();
if (currentState == ServerConnState.RESPONSE_SENT) {
break;
}
if (currentState == ServerConnState.SHUTDOWN) {
return;
}
connState.wait();
}
} catch (InterruptedException ex) {
connState.shutdown();
return;
}
connState.resetOutput();
response = null;
}
} else {
// Discard request entity
conn.resetInput();
eeRequest.setEntity(null);
}
}
// Create a wrapper entity instead of the original one
if (eeRequest.getEntity() != null) {
eeRequest.setEntity(new ContentBufferEntity(
eeRequest.getEntity(),
connState.getInbuffer()));
}
}
if (response == null) {
response = this.responseFactory.newHttpResponse(
ver,
HttpStatus.SC_OK,
context);
response.setParams(
new DefaultedHttpParams(response.getParams(), this.params));
context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
try {
this.httpProcessor.process(request, context);
HttpRequestHandler handler = null;
if (this.handlerResolver != null) {
String requestURI = request.getRequestLine().getUri();
handler = this.handlerResolver.lookup(requestURI);
}
if (handler != null) {
handler.handle(request, response, context);
} else {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
}
} 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.httpProcessor.process(response, context);