socket = null;
//}
}
private void handleClient() throws IOException, SocketTimeoutException {
InputStream is = new ContentLengthInputStream(new BufferedInputStream(socket.getInputStream()), maximumRequestLengthInBytes);
OutputStream os = new BufferedOutputStream(socket.getOutputStream());
/*
* we will only block in read for this many milliseconds before we fail with
* java.io.InterruptedIOException, at which point we will abandon the
* connection.
*/
socket.setSoTimeout(1000000/* WebServer.timeout */);
socket.setTcpNoDelay(true);
clearBuffer();
try {
IHttpContext context = establishContext(is, socket.getInetAddress(), os);
handleContext(context);
}
catch (ResourceNotFoundException rnfex) {
IHttpResponse httpResponse = createHttpResponseForStatusCode(HttpStatusCode.STATUS_404_NOT_FOUND);
IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
responseWriter.writeResponse(httpResponse);
}
catch (HttpException he) {
IHttpResponse httpResponse = createHttpResponseForStatusCode(he.getStatusCode());
IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
responseWriter.writeResponse(httpResponse);
}
catch (SocketTimeoutException ste) {
IHttpResponse httpResponse = createHttpResponseForStatusCode(HttpStatusCode.STATUS_408_REQUEST_TIMEOUT);
IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
responseWriter.writeResponse(httpResponse);
}
finally {
if (!socket.isClosed()) {
try {
os.flush();
is.close();
os.close();
socket.close();
}
catch (IOException ex) {