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

The following examples show how to use javax.servlet.http.HttpServletResponse#SC_REQUEST_ENTITY_TOO_LARGE . These examples are extracted from open source projects. 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 Project: Tomcat7.0.67   File: Request.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Perform whatever actions are required to flush and close the input
 * stream or reader, in a single operation.
 *
 * @exception IOException if an input/output error occurs
 */
public void finishRequest() throws IOException {
    // Optionally disable swallowing of additional request data.
    Context context = getContext();
    if (context != null &&
            response.getStatus() == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE &&
            !context.getSwallowAbortedUploads()) {
        coyoteRequest.action(ActionCode.DISABLE_SWALLOW_INPUT, null);
    }
}
 
Example 2
Source Project: tomcatsrc   File: Request.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Perform whatever actions are required to flush and close the input
 * stream or reader, in a single operation.
 *
 * @exception IOException if an input/output error occurs
 */
public void finishRequest() throws IOException {
    // Optionally disable swallowing of additional request data.
    Context context = getContext();
    if (context != null &&
            response.getStatus() == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE &&
            !context.getSwallowAbortedUploads()) {
        coyoteRequest.action(ActionCode.DISABLE_SWALLOW_INPUT, null);
    }
}
 
Example 3
public String readLine()
    throws IOException, HttpException
{

  if (lineBuffer == null) {
    lineBuffer = new byte[127];
  }

  int count = readLine(lineBuffer, 0, lineBuffer.length);
  int offset = count;

  while (count > 0 && offset == lineBuffer.length
         && lineBuffer[offset - 1] != '\n') {
    // double the size of the buffer
    final int newsize = offset * 2 + 1;
    if (newsize > limitRequestLine) {
      throw new HttpException(
                              HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
                              "Request line length exceeds upper limit");
    }
    byte[] tmp = new byte[newsize];
    System.arraycopy(lineBuffer, 0, tmp, 0, offset);
    lineBuffer = tmp;
    tmp = null;

    count = readLine(lineBuffer, offset, lineBuffer.length - offset);
    offset += count;
  }

  if (count == -1) {
    throw new IOException("End of stream reached before CRLF");
  }

  return HttpUtil.newString(lineBuffer, 0, 0, offset - 2); // remove
                                                           // CRLF
}
 
Example 4
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (!isGoodRequest(request)) {
        FailReason reason = (FailReason) request.getAttribute(
                Globals.PARAMETER_PARSE_FAILED_REASON_ATTR);

        int status;

        switch (reason) {
            case IO_ERROR:
                // Not the client's fault
                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                break;
            case POST_TOO_LARGE:
                status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
                break;
            case TOO_MANY_PARAMETERS:
                // 413/414 aren't really correct here since the request body
                // and/or URI could be well below any limits set. Use the
                // default.
            case UNKNOWN: // Assume the client is at fault
            // Various things that the client can get wrong that don't have
            // a specific status code so use the default.
            case INVALID_CONTENT_TYPE:
            case MULTIPART_CONFIG_INVALID:
            case NO_NAME:
            case REQUEST_BODY_INCOMPLETE:
            case URL_DECODING:
            case CLIENT_DISCONNECT:
                // Client is never going to see this so this is really just
                // for the access logs. The default is fine.
            default:
                // 400
                status = HttpServletResponse.SC_BAD_REQUEST;
                break;
        }

        ((HttpServletResponse) response).sendError(status);
        return;
    }
    chain.doFilter(request, response);
}
 
Example 5
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (!isGoodRequest(request)) {
        FailReason reason = (FailReason) request.getAttribute(
                Globals.PARAMETER_PARSE_FAILED_REASON_ATTR);

        int status;

        switch (reason) {
            case IO_ERROR:
                // Not the client's fault
                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                break;
            case POST_TOO_LARGE:
                status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
                break;
            case TOO_MANY_PARAMETERS:
                // 413/414 aren't really correct here since the request body
                // and/or URI could be well below any limits set. Use the
                // default.
            case UNKNOWN: // Assume the client is at fault
            // Various things that the client can get wrong that don't have
            // a specific status code so use the default.
            case INVALID_CONTENT_TYPE:
            case MULTIPART_CONFIG_INVALID:
            case NO_NAME:
            case REQUEST_BODY_INCOMPLETE:
            case URL_DECODING:
            case CLIENT_DISCONNECT:
                // Client is never going to see this so this is really just
                // for the access logs. The default is fine.
            default:
                // 400
                status = HttpServletResponse.SC_BAD_REQUEST;
                break;
        }

        ((HttpServletResponse) response).sendError(status);
        return;
    }
    chain.doFilter(request, response);
}
 
Example 6
public MaxUploadLengthExceededException(String message) {
    super(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, message);
}
 
Example 7
Source Project: tomcatsrc   File: FailedRequestFilter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (!isGoodRequest(request)) {
        FailReason reason = (FailReason) request.getAttribute(
                Globals.PARAMETER_PARSE_FAILED_REASON_ATTR);

        int status;

        switch (reason) {
            case IO_ERROR:
                // Not the client's fault
                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                break;
            case POST_TOO_LARGE:
                status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
                break;
            case TOO_MANY_PARAMETERS:
                // 413/414 aren't really correct here since the request body
                // and/or URI could be well below any limits set. Use the
                // default.
            case UNKNOWN: // Assume the client is at fault
            // Various things that the client can get wrong that don't have
            // a specific status code so use the default.
            case INVALID_CONTENT_TYPE:
            case MULTIPART_CONFIG_INVALID:
            case NO_NAME:
            case REQUEST_BODY_INCOMPLETE:
            case URL_DECODING:
            case CLIENT_DISCONNECT:
                // Client is never going to see this so this is really just
                // for the access logs. The default is fine.
            default:
                // 400
                status = HttpServletResponse.SC_BAD_REQUEST;
                break;
        }

        ((HttpServletResponse) response).sendError(status);
        return;
    }
    chain.doFilter(request, response);
}
 
Example 8
void parseHeaders(ServletInputStreamImpl in)
      throws HttpException, IOException
  {
    String name = null;
    String value = null;
    ArrayList<String> values = null;
    final int limit = httpConfig.getLimitRequestHeaders() - 1;

    String line = in.readLine();
    while (line != null && line.length() > 0) {
//      Activator.log.info(Thread.currentThread().getName() + " - Attempting to parse: " + line);
      if (headers.size() > limit) {
        throw new HttpException(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
      }

      final char c = line.charAt(0);
      if (c == ' ' || c == '\t') { // continued header value

        // check not first line
        if (!(name != null && value != null && values != null)) {
          throw new HttpException(HttpServletResponse.SC_BAD_REQUEST);
        }

        // set concatenated header value
        value = value + line.substring(1);
        values.remove(values.size() - 1);
        values.add(value);

      } else {

        final int index = line.indexOf(": ");

        // get header name
        name = line.substring(0, index).trim().toLowerCase();

        // get header value
        @SuppressWarnings("unchecked")
        final ArrayList<String> newValues =
          (ArrayList<String>) headers.get(name);
        values = newValues;
        if (values == null) {
          values = new ArrayList<String>();
        }

        // add header value to vector
        value = line.substring(index + 2);
        values.add(value);
        headers.put(name, values);
      }

      // read next line
      line = in.readLine();
    }
  }
 
Example 9
Source Project: Tomcat8-Source-Read   File: Request.java    License: MIT License 2 votes vote down vote up
/**
 * Perform whatever actions are required to flush and close the input
 * stream or reader, in a single operation.
 *
 * @exception IOException if an input/output error occurs
 */
public void finishRequest() throws IOException {
    if (response.getStatus() == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE) {
        checkSwallowInput();
    }
}