Java Code Examples for io.netty.handler.codec.http.HttpResponseStatus#REQUEST_ENTITY_TOO_LARGE

The following examples show how to use io.netty.handler.codec.http.HttpResponseStatus#REQUEST_ENTITY_TOO_LARGE . 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: HttpServerOperations.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
static void sendDecodingFailures(ChannelHandlerContext ctx, Throwable t, Object msg) {
	Throwable cause = t.getCause() != null ? t.getCause() : t;

	if (log.isDebugEnabled()) {
		log.debug(format(ctx.channel(), "Decoding failed: " + msg + " : "), cause);
	}

	ReferenceCountUtil.release(msg);

	HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_0,
			cause instanceof TooLongFrameException ? HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE:
			                                         HttpResponseStatus.BAD_REQUEST);
	response.headers()
	        .setInt(HttpHeaderNames.CONTENT_LENGTH, 0)
	        .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
	ctx.writeAndFlush(response)
	   .addListener(ChannelFutureListener.CLOSE);
}
 
Example 2
Source File: NettyResponseChannel.java    From ambry with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a {@link ResponseStatus} into a {@link HttpResponseStatus}.
 * @param responseStatus {@link ResponseStatus} that needs to be mapped to a {@link HttpResponseStatus}.
 * @return the {@link HttpResponseStatus} that maps to the {@link ResponseStatus}.
 */
private HttpResponseStatus getHttpResponseStatus(ResponseStatus responseStatus) {
  HttpResponseStatus status;
  switch (responseStatus) {
    case Ok:
      nettyMetrics.okCount.inc();
      status = HttpResponseStatus.OK;
      break;
    case Created:
      nettyMetrics.createdCount.inc();
      status = HttpResponseStatus.CREATED;
      break;
    case Accepted:
      nettyMetrics.acceptedCount.inc();
      status = HttpResponseStatus.ACCEPTED;
      break;
    case PartialContent:
      nettyMetrics.partialContentCount.inc();
      status = HttpResponseStatus.PARTIAL_CONTENT;
      break;
    case NotModified:
      nettyMetrics.notModifiedCount.inc();
      status = HttpResponseStatus.NOT_MODIFIED;
      break;
    case BadRequest:
      nettyMetrics.badRequestCount.inc();
      status = HttpResponseStatus.BAD_REQUEST;
      break;
    case Unauthorized:
      nettyMetrics.unauthorizedCount.inc();
      status = HttpResponseStatus.UNAUTHORIZED;
      break;
    case NotFound:
      nettyMetrics.notFoundCount.inc();
      status = HttpResponseStatus.NOT_FOUND;
      break;
    case Conflict:
      nettyMetrics.conflictCount.inc();
      status = HttpResponseStatus.CONFLICT;
      break;
    case Gone:
      nettyMetrics.goneCount.inc();
      status = HttpResponseStatus.GONE;
      break;
    case Forbidden:
      nettyMetrics.forbiddenCount.inc();
      status = HttpResponseStatus.FORBIDDEN;
      break;
    case ProxyAuthenticationRequired:
      nettyMetrics.proxyAuthRequiredCount.inc();
      status = HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
      break;
    case RangeNotSatisfiable:
      nettyMetrics.rangeNotSatisfiableCount.inc();
      status = HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
      break;
    case TooManyRequests:
      nettyMetrics.tooManyRequests.inc();
      status = HttpResponseStatus.TOO_MANY_REQUESTS;
      break;
    case RequestTooLarge:
      nettyMetrics.requestTooLargeCount.inc();
      status = HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE;
      break;
    case InternalServerError:
      nettyMetrics.internalServerErrorCount.inc();
      status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
      break;
    case ServiceUnavailable:
      nettyMetrics.serviceUnavailableErrorCount.inc();
      status = HttpResponseStatus.SERVICE_UNAVAILABLE;
      break;
    case InsufficientCapacity:
      nettyMetrics.insufficientCapacityErrorCount.inc();
      status = HttpResponseStatus.INSUFFICIENT_STORAGE;
      break;
    case PreconditionFailed:
      nettyMetrics.preconditionFailedErrorCount.inc();
      status = HttpResponseStatus.PRECONDITION_FAILED;
      break;
    case MethodNotAllowed:
      nettyMetrics.methodNotAllowedErrorCount.inc();
      status = HttpResponseStatus.METHOD_NOT_ALLOWED;
      break;
    default:
      nettyMetrics.unknownResponseStatusCount.inc();
      status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
      break;
  }
  return status;
}
 
Example 3
Source File: NettyResponseChannelTest.java    From ambry with Apache License 2.0 4 votes vote down vote up
/**
 * @param code the {@link RestServiceErrorCode} whose {@link HttpResponseStatus} equivalent is required.
 * @return the {@link HttpResponseStatus} equivalent of {@code code}.
 */
private HttpResponseStatus getExpectedHttpResponseStatus(RestServiceErrorCode code) {
  switch (code) {
    case RequestTooLarge:
      return HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE;
    case Conflict:
      return HttpResponseStatus.CONFLICT;
    case Deleted:
      return HttpResponseStatus.GONE;
    case NotFound:
      return HttpResponseStatus.NOT_FOUND;
    case BadRequest:
    case InvalidArgs:
    case InvalidAccount:
    case InvalidContainer:
    case InvalidRequestState:
    case MalformedRequest:
    case MissingArgs:
    case UnsupportedHttpMethod:
      return HttpResponseStatus.BAD_REQUEST;
    case ResourceDirty:
    case AccessDenied:
      return HttpResponseStatus.FORBIDDEN;
    case Unauthorized:
      return HttpResponseStatus.UNAUTHORIZED;
    case ResourceScanInProgress:
      return HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
    case RangeNotSatisfiable:
      return HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
    case ServiceUnavailable:
      return HttpResponseStatus.SERVICE_UNAVAILABLE;
    case TooManyRequests:
      return HttpResponseStatus.TOO_MANY_REQUESTS;
    case InsufficientCapacity:
      return HttpResponseStatus.INSUFFICIENT_STORAGE;
    case IdConverterServiceError:
    case InternalServerError:
    case RequestChannelClosed:
    case RequestResponseQueuingFailure:
    case UnsupportedRestMethod:
      return HttpResponseStatus.INTERNAL_SERVER_ERROR;
    case PreconditionFailed:
      return HttpResponseStatus.PRECONDITION_FAILED;
    case NotAllowed:
      return HttpResponseStatus.METHOD_NOT_ALLOWED;
    default:
      throw new IllegalArgumentException("Unrecognized RestServiceErrorCode - " + code);
  }
}