Inline NettyHttpChannel#getStatus

Relates #16725
This commit is contained in:
Jason Tedor 2016-02-12 19:07:35 -05:00
parent 2690f69d77
commit a447c06efc
1 changed files with 56 additions and 96 deletions

View File

@ -43,6 +43,8 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.HttpVersion;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -196,101 +198,59 @@ public class NettyHttpChannel extends HttpChannel {
private static final HttpResponseStatus TOO_MANY_REQUESTS = new HttpResponseStatus(429, "Too Many Requests"); private static final HttpResponseStatus TOO_MANY_REQUESTS = new HttpResponseStatus(429, "Too Many Requests");
private HttpResponseStatus getStatus(RestStatus status) { static Map<RestStatus, HttpResponseStatus> MAP;
switch (status) {
case CONTINUE: static {
return HttpResponseStatus.CONTINUE; EnumMap<RestStatus, HttpResponseStatus> map = new EnumMap<>(RestStatus.class);
case SWITCHING_PROTOCOLS: map.put(RestStatus.CONTINUE, HttpResponseStatus.CONTINUE);
return HttpResponseStatus.SWITCHING_PROTOCOLS; map.put(RestStatus.SWITCHING_PROTOCOLS, HttpResponseStatus.SWITCHING_PROTOCOLS);
case OK: map.put(RestStatus.OK, HttpResponseStatus.OK);
return HttpResponseStatus.OK; map.put(RestStatus.CREATED, HttpResponseStatus.CREATED);
case CREATED: map.put(RestStatus.ACCEPTED, HttpResponseStatus.ACCEPTED);
return HttpResponseStatus.CREATED; map.put(RestStatus.NON_AUTHORITATIVE_INFORMATION, HttpResponseStatus.NON_AUTHORITATIVE_INFORMATION);
case ACCEPTED: map.put(RestStatus.NO_CONTENT, HttpResponseStatus.NO_CONTENT);
return HttpResponseStatus.ACCEPTED; map.put(RestStatus.RESET_CONTENT, HttpResponseStatus.RESET_CONTENT);
case NON_AUTHORITATIVE_INFORMATION: map.put(RestStatus.PARTIAL_CONTENT, HttpResponseStatus.PARTIAL_CONTENT);
return HttpResponseStatus.NON_AUTHORITATIVE_INFORMATION; map.put(RestStatus.MULTI_STATUS, HttpResponseStatus.INTERNAL_SERVER_ERROR); // no status for this??
case NO_CONTENT: map.put(RestStatus.MULTIPLE_CHOICES, HttpResponseStatus.MULTIPLE_CHOICES);
return HttpResponseStatus.NO_CONTENT; map.put(RestStatus.MOVED_PERMANENTLY, HttpResponseStatus.MOVED_PERMANENTLY);
case RESET_CONTENT: map.put(RestStatus.FOUND, HttpResponseStatus.FOUND);
return HttpResponseStatus.RESET_CONTENT; map.put(RestStatus.SEE_OTHER, HttpResponseStatus.SEE_OTHER);
case PARTIAL_CONTENT: map.put(RestStatus.NOT_MODIFIED, HttpResponseStatus.NOT_MODIFIED);
return HttpResponseStatus.PARTIAL_CONTENT; map.put(RestStatus.USE_PROXY, HttpResponseStatus.USE_PROXY);
case MULTI_STATUS: map.put(RestStatus.TEMPORARY_REDIRECT, HttpResponseStatus.TEMPORARY_REDIRECT);
// no status for this?? map.put(RestStatus.BAD_REQUEST, HttpResponseStatus.BAD_REQUEST);
return HttpResponseStatus.INTERNAL_SERVER_ERROR; map.put(RestStatus.UNAUTHORIZED, HttpResponseStatus.UNAUTHORIZED);
case MULTIPLE_CHOICES: map.put(RestStatus.PAYMENT_REQUIRED, HttpResponseStatus.PAYMENT_REQUIRED);
return HttpResponseStatus.MULTIPLE_CHOICES; map.put(RestStatus.FORBIDDEN, HttpResponseStatus.FORBIDDEN);
case MOVED_PERMANENTLY: map.put(RestStatus.NOT_FOUND, HttpResponseStatus.NOT_FOUND);
return HttpResponseStatus.MOVED_PERMANENTLY; map.put(RestStatus.METHOD_NOT_ALLOWED, HttpResponseStatus.METHOD_NOT_ALLOWED);
case FOUND: map.put(RestStatus.NOT_ACCEPTABLE, HttpResponseStatus.NOT_ACCEPTABLE);
return HttpResponseStatus.FOUND; map.put(RestStatus.PROXY_AUTHENTICATION, HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED);
case SEE_OTHER: map.put(RestStatus.REQUEST_TIMEOUT, HttpResponseStatus.REQUEST_TIMEOUT);
return HttpResponseStatus.SEE_OTHER; map.put(RestStatus.CONFLICT, HttpResponseStatus.CONFLICT);
case NOT_MODIFIED: map.put(RestStatus.GONE, HttpResponseStatus.GONE);
return HttpResponseStatus.NOT_MODIFIED; map.put(RestStatus.LENGTH_REQUIRED, HttpResponseStatus.LENGTH_REQUIRED);
case USE_PROXY: map.put(RestStatus.PRECONDITION_FAILED, HttpResponseStatus.PRECONDITION_FAILED);
return HttpResponseStatus.USE_PROXY; map.put(RestStatus.REQUEST_ENTITY_TOO_LARGE, HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE);
case TEMPORARY_REDIRECT: map.put(RestStatus.REQUEST_URI_TOO_LONG, HttpResponseStatus.REQUEST_URI_TOO_LONG);
return HttpResponseStatus.TEMPORARY_REDIRECT; map.put(RestStatus.UNSUPPORTED_MEDIA_TYPE, HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
case BAD_REQUEST: map.put(RestStatus.REQUESTED_RANGE_NOT_SATISFIED, HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE);
return HttpResponseStatus.BAD_REQUEST; map.put(RestStatus.EXPECTATION_FAILED, HttpResponseStatus.EXPECTATION_FAILED);
case UNAUTHORIZED: map.put(RestStatus.UNPROCESSABLE_ENTITY, HttpResponseStatus.BAD_REQUEST);
return HttpResponseStatus.UNAUTHORIZED; map.put(RestStatus.LOCKED, HttpResponseStatus.BAD_REQUEST);
case PAYMENT_REQUIRED: map.put(RestStatus.FAILED_DEPENDENCY, HttpResponseStatus.BAD_REQUEST);
return HttpResponseStatus.PAYMENT_REQUIRED; map.put(RestStatus.TOO_MANY_REQUESTS, TOO_MANY_REQUESTS);
case FORBIDDEN: map.put(RestStatus.INTERNAL_SERVER_ERROR, HttpResponseStatus.INTERNAL_SERVER_ERROR);
return HttpResponseStatus.FORBIDDEN; map.put(RestStatus.NOT_IMPLEMENTED, HttpResponseStatus.NOT_IMPLEMENTED);
case NOT_FOUND: map.put(RestStatus.BAD_GATEWAY, HttpResponseStatus.BAD_GATEWAY);
return HttpResponseStatus.NOT_FOUND; map.put(RestStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.SERVICE_UNAVAILABLE);
case METHOD_NOT_ALLOWED: map.put(RestStatus.GATEWAY_TIMEOUT, HttpResponseStatus.GATEWAY_TIMEOUT);
return HttpResponseStatus.METHOD_NOT_ALLOWED; map.put(RestStatus.HTTP_VERSION_NOT_SUPPORTED, HttpResponseStatus.HTTP_VERSION_NOT_SUPPORTED);
case NOT_ACCEPTABLE: MAP = Collections.unmodifiableMap(map);
return HttpResponseStatus.NOT_ACCEPTABLE; }
case PROXY_AUTHENTICATION:
return HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED; private static HttpResponseStatus getStatus(RestStatus status) {
case REQUEST_TIMEOUT: return MAP.getOrDefault(status, HttpResponseStatus.INTERNAL_SERVER_ERROR);
return HttpResponseStatus.REQUEST_TIMEOUT;
case CONFLICT:
return HttpResponseStatus.CONFLICT;
case GONE:
return HttpResponseStatus.GONE;
case LENGTH_REQUIRED:
return HttpResponseStatus.LENGTH_REQUIRED;
case PRECONDITION_FAILED:
return HttpResponseStatus.PRECONDITION_FAILED;
case REQUEST_ENTITY_TOO_LARGE:
return HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE;
case REQUEST_URI_TOO_LONG:
return HttpResponseStatus.REQUEST_URI_TOO_LONG;
case UNSUPPORTED_MEDIA_TYPE:
return HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE;
case REQUESTED_RANGE_NOT_SATISFIED:
return HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
case EXPECTATION_FAILED:
return HttpResponseStatus.EXPECTATION_FAILED;
case UNPROCESSABLE_ENTITY:
return HttpResponseStatus.BAD_REQUEST;
case LOCKED:
return HttpResponseStatus.BAD_REQUEST;
case FAILED_DEPENDENCY:
return HttpResponseStatus.BAD_REQUEST;
case TOO_MANY_REQUESTS:
return TOO_MANY_REQUESTS;
case INTERNAL_SERVER_ERROR:
return HttpResponseStatus.INTERNAL_SERVER_ERROR;
case NOT_IMPLEMENTED:
return HttpResponseStatus.NOT_IMPLEMENTED;
case BAD_GATEWAY:
return HttpResponseStatus.BAD_GATEWAY;
case SERVICE_UNAVAILABLE:
return HttpResponseStatus.SERVICE_UNAVAILABLE;
case GATEWAY_TIMEOUT:
return HttpResponseStatus.GATEWAY_TIMEOUT;
case HTTP_VERSION_NOT_SUPPORTED:
return HttpResponseStatus.HTTP_VERSION_NOT_SUPPORTED;
default:
return HttpResponseStatus.INTERNAL_SERVER_ERROR;
}
} }
} }