Exemple #1
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;
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * Constructs a new {@link HttpResponse} containing the given XML-RPC method response.
  *
  * <p>This implementation encodes the response using <code>UTF-8</code>, sets the status code to
  * <code>200</code>, and sets <code>Content-Type</code> header to <code>text/xml</code> as
  * required. No other headers are set.
  *
  * @param methodRsp The XML-RPC method response to be returned in the HTTP response.
  * @param encoding An {@link Encoding} describing the encoding to use when constructing this
  *     message. This also informs the <code>Content-Encoding</code> header value. May be <code>
  *     null</code>.
  * @return A new {@link HttpResponse} with the marshalled XML-RPC response as its content.
  * @throws IOException if an error occurs while marshalling the XML-RPC response.
  * @throws MarshallingException
  */
 protected HttpResponse toHttpResponse(
     HttpMessageBuffer origMsg, RpcResponse methodRsp, Encoding encoding)
     throws IOException, MarshallingException {
   ByteArrayOutputStream byteOs = new ByteArrayOutputStream();
   methodRsp.marshal(byteOs, Charset.forName("UTF-8"));
   byte[] rspXml = byteOs.toByteArray();
   HttpResponse httpRsp = this.newHttpResponse(origMsg, 200, "OK", encoding);
   httpRsp.addHeader(HttpConstants.Headers.CONTENT_TYPE, methodRsp.getContentType());
   httpRsp.setContent(rspXml);
   return httpRsp;
 }