Java Code Examples for javax.servlet.http.HttpServletResponse#SC_LENGTH_REQUIRED

The following examples show how to use javax.servlet.http.HttpServletResponse#SC_LENGTH_REQUIRED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void handle() throws HttpException, IOException
{
  base.handle();
  is_http_1_1 = base.getProtocol().equals(RequestBase.HTTP_1_1_PROTOCOL);

  if (is_http_1_1
      && !base.getHeaders(HeaderBase.HOST_HEADER_KEY).hasMoreElements()) {
    throw new HttpException(HttpServletResponse.SC_BAD_REQUEST);
  }

  final int available = getContentLength();
  String connection = getHeader(HeaderBase.CONNECTION_HEADER_KEY);
  // For details on the Proxy-Connection header please read:
  // http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/web-proxy-connection-header.html
  if (null == connection || 0 == connection.length()) {
    // We handle Proxy-Connection in the same way as Connection
    connection = getHeader("Proxy-Connection");
  }

  final String method = base.getMethod();
  // TODO: OPTIONS and DELETE -> lengthKnown
  final boolean lengthKnown =
      method.equals(RequestBase.GET_METHOD)
          || method.equals(RequestBase.HEAD_METHOD) || available != -1;
  if (lengthKnown) {
    if (is_http_1_1) {
      if (!"close".equalsIgnoreCase(connection)) {
        keepAlive = true;
      }
    } else if ("Keep-Alive".equalsIgnoreCase(connection)) {
      keepAlive = true;
    }
  }

  // keepAlive = false;

  if (available != -1) {
    if (keepAlive) {
      base.getBody().setLimit(available);
    } else if (!is_http_1_1) {
      // perhaps not according to spec, but works better :)
      base.getBody().setLimit(available);
    }
  } else {
    if (method.equals(RequestBase.POST_METHOD)) {
      final String transfer_encoding =
          getHeader(HeaderBase.TRANSFER_ENCODING_KEY);
      if (HeaderBase.TRANSFER_ENCODING_VALUE_CHUNKED
                                                    .equals(transfer_encoding)) {
        // Handle chunked body the by reading every chunk and creating
        // a new servletinputstream for the decoded body
        // The only client (so far) that seems to be doing this is the
        // Axis2 library
        base.setBody(readChunkedBody(base.getBody()));
      } else {
        throw new HttpException(HttpServletResponse.SC_LENGTH_REQUIRED);
      }
    }
  }

  handleSession();
}