Example #1
0
 /**
  * Converts an exception raised while processing an HTTP request into a suitable HTTP response.
  *
  * <p>The response is marshalled and queued for writing on the socket associated with the original
  * request.
  *
  * @param msg The HTTP request being processed when the exception occurred.
  * @param e The exception that was raised.
  * @throws IOException if an error occurs marshalling or writing the response.
  */
 protected void handleMessageException(HttpMessageBuffer msg, Exception e) throws IOException {
   HttpResponse httpRsp;
   if (e instanceof HttpResponseException) {
     if (log.logWarn()) {
       log.warn("HttpResponseException", e);
     }
     httpRsp = this.newHttpResponse(msg, (HttpResponseException) e);
     this.queueWrite(msg.getSocket(), httpRsp.marshal(), true);
   } else if (e instanceof RemoteSocketClosedException) {
     if (log.logTrace()) {
       log.trace("Remote entity closed connection", e);
     }
   } else {
     if (log.logError()) {
       log.error("Internal Server Error", e);
     }
     httpRsp =
         this.newHttpResponse(
             msg,
             new HttpResponseException(
                 HttpConstants.StatusCodes._500_INTERNAL_SERVER_ERROR,
                 "Internal Server Error",
                 e));
     this.queueWrite(msg.getSocket(), httpRsp.marshal(), true);
   }
 }
Example #2
0
 protected HttpResponse newHttpResponse(HttpMessageBuffer msg, HttpResponseException e) {
   HttpResponse httpRsp = e.toHttpResponse(msg.getHttpVersionString());
   if (msg.getHttpVersion() > 1.0) {
     httpRsp.addHeader(HttpConstants.Headers.HOST, this.headerHostValue);
   }
   httpRsp.addHeader(HttpConstants.Headers.SERVER, this.getServerName());
   httpRsp.addHeader(HttpConstants.Headers.CONNECTION, "close");
   return httpRsp;
 }
Example #3
0
 protected HttpResponse newHttpResponse(
     HttpMessageBuffer origMsg, int statusCode, String reasonPhrase, Encoding encoding) {
   Encoding responseEncoding = null;
   if (this.encodeResponses) {
     responseEncoding = encoding;
   }
   HttpResponse httpRsp;
   if (origMsg == null) {
     httpRsp = new HttpResponse(statusCode, reasonPhrase, responseEncoding);
   } else {
     httpRsp =
         new HttpResponse(
             origMsg.getHttpVersionString(), statusCode, reasonPhrase, responseEncoding);
   }
   if (origMsg.getHttpVersion() > 1.0) {
     httpRsp.addHeader(HttpConstants.Headers.HOST, this.headerHostValue);
   }
   httpRsp.addHeader(HttpConstants.Headers.SERVER, this.getServerName());
   return httpRsp;
 }