Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (C) 2013-2018 Expedia Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.hotels.styx.api.messages;
import java.lang.reflect.Field;
import java.util.stream.Stream;
import static java.lang.reflect.Modifier.isStatic;
/**
* Contains all HTTP response status codes as HttpResponseStatus constants,
* as well as a method to go from a code to its name.
*/
public final class HttpResponseStatus {
public static final HttpResponseStatus CONTINUE = new HttpResponseStatus(100, "Continue");
public static final HttpResponseStatus SWITCHING_PROTOCOLS = new HttpResponseStatus(101, "Switching Protocols");
public static final HttpResponseStatus PROCESSING = new HttpResponseStatus(102, "Processing");
public static final HttpResponseStatus OK = new HttpResponseStatus(200, "OK");
public static final HttpResponseStatus CREATED = new HttpResponseStatus(201, "Created");
public static final HttpResponseStatus ACCEPTED = new HttpResponseStatus(202, "Accepted");
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION = new HttpResponseStatus(203, "Non-Authoritative Information");
public static final HttpResponseStatus NO_CONTENT = new HttpResponseStatus(204, "No Content");
public static final HttpResponseStatus RESET_CONTENT = new HttpResponseStatus(205, "Reset Content");
public static final HttpResponseStatus PARTIAL_CONTENT = new HttpResponseStatus(206, "Partial Content");
public static final HttpResponseStatus MULTI_STATUS = new HttpResponseStatus(207, "Multi-Status");
public static final HttpResponseStatus MULTIPLE_CHOICES = new HttpResponseStatus(300, "Multiple Choices");
public static final HttpResponseStatus MOVED_PERMANENTLY = new HttpResponseStatus(301, "Moved Permanently");
public static final HttpResponseStatus FOUND = new HttpResponseStatus(302, "Found");
public static final HttpResponseStatus SEE_OTHER = new HttpResponseStatus(303, "See Other");
public static final HttpResponseStatus NOT_MODIFIED = new HttpResponseStatus(304, "Not Modified");
public static final HttpResponseStatus USE_PROXY = new HttpResponseStatus(305, "Use Proxy");
public static final HttpResponseStatus TEMPORARY_REDIRECT = new HttpResponseStatus(307, "Temporary Redirect");
public static final HttpResponseStatus PERMANENT_REDIRECT = new HttpResponseStatus(308, "Permanent Redirect");
public static final HttpResponseStatus BAD_REQUEST = new HttpResponseStatus(400, "Bad Request");
public static final HttpResponseStatus UNAUTHORIZED = new HttpResponseStatus(401, "Unauthorized");
public static final HttpResponseStatus PAYMENT_REQUIRED = new HttpResponseStatus(402, "Payment Required");
public static final HttpResponseStatus FORBIDDEN = new HttpResponseStatus(403, "Forbidden");
public static final HttpResponseStatus NOT_FOUND = new HttpResponseStatus(404, "Not Found");
public static final HttpResponseStatus METHOD_NOT_ALLOWED = new HttpResponseStatus(405, "Method Not Allowed");
public static final HttpResponseStatus NOT_ACCEPTABLE = new HttpResponseStatus(406, "Not Acceptable");
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = new HttpResponseStatus(407, "Proxy Authentication Required");
public static final HttpResponseStatus REQUEST_TIMEOUT = new HttpResponseStatus(408, "Request Timeout");
public static final HttpResponseStatus CONFLICT = new HttpResponseStatus(409, "Conflict");
public static final HttpResponseStatus GONE = new HttpResponseStatus(410, "Gone");
public static final HttpResponseStatus LENGTH_REQUIRED = new HttpResponseStatus(411, "Length Required");
public static final HttpResponseStatus PRECONDITION_FAILED = new HttpResponseStatus(412, "Precondition Failed");
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE = new HttpResponseStatus(413, "Request Entity Too Large");
public static final HttpResponseStatus REQUEST_URI_TOO_LONG = new HttpResponseStatus(414, "Request-URI Too Long");
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = new HttpResponseStatus(415, "Unsupported Media Type");
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE = new HttpResponseStatus(416, "Requested Range Not Satisfiable");
public static final HttpResponseStatus EXPECTATION_FAILED = new HttpResponseStatus(417, "Expectation Failed");
public static final HttpResponseStatus MISDIRECTED_REQUEST = new HttpResponseStatus(421, "Misdirected Request");
public static final HttpResponseStatus UNPROCESSABLE_ENTITY = new HttpResponseStatus(422, "Unprocessable Entity");
public static final HttpResponseStatus LOCKED = new HttpResponseStatus(423, "Locked");
public static final HttpResponseStatus FAILED_DEPENDENCY = new HttpResponseStatus(424, "Failed Dependency");
public static final HttpResponseStatus UNORDERED_COLLECTION = new HttpResponseStatus(425, "Unordered Collection");
public static final HttpResponseStatus UPGRADE_REQUIRED = new HttpResponseStatus(426, "Upgrade Required");
public static final HttpResponseStatus PRECONDITION_REQUIRED = new HttpResponseStatus(428, "Precondition Required");
public static final HttpResponseStatus TOO_MANY_REQUESTS = new HttpResponseStatus(429, "Too Many Requests");
public static final HttpResponseStatus REQUEST_HEADER_FIELDS_TOO_LARGE = new HttpResponseStatus(431, "Request Header Fields Too Large");
public static final HttpResponseStatus INTERNAL_SERVER_ERROR = new HttpResponseStatus(500, "Internal Server Error");
public static final HttpResponseStatus NOT_IMPLEMENTED = new HttpResponseStatus(501, "Not Implemented");
public static final HttpResponseStatus BAD_GATEWAY = new HttpResponseStatus(502, "Bad Gateway");
public static final HttpResponseStatus SERVICE_UNAVAILABLE = new HttpResponseStatus(503, "Service Unavailable");
public static final HttpResponseStatus GATEWAY_TIMEOUT = new HttpResponseStatus(504, "Gateway Timeout");
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED = new HttpResponseStatus(505, "HTTP Version Not Supported");
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES = new HttpResponseStatus(506, "Variant Also Negotiates");
public static final HttpResponseStatus INSUFFICIENT_STORAGE = new HttpResponseStatus(507, "Insufficient Storage");
public static final HttpResponseStatus NOT_EXTENDED = new HttpResponseStatus(510, "Not Extended");
public static final HttpResponseStatus NETWORK_AUTHENTICATION_REQUIRED = new HttpResponseStatus(511, "Network Authentication Required");
private final int code;
private final String description;
private static final HttpResponseStatus[] STATUSES = generateStatusArray();
private static HttpResponseStatus[] generateStatusArray() {
// Using the array prevents us from needlessly instantiating objects at runtime.
// The large number of empty elements is not significant, as only one instance of this array exists.
HttpResponseStatus[] array = new HttpResponseStatus[600];
Stream.of(HttpResponseStatus.class.getDeclaredFields())
.filter(field -> field.getType() == HttpResponseStatus.class)
.filter(field -> isStatic(field.getModifiers()))
.map(HttpResponseStatus::value)
.forEach(status -> array[status.code] = status);
return array;
}
private static HttpResponseStatus value(Field staticField) {
try {
return (HttpResponseStatus) staticField.get(null);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public static HttpResponseStatus statusWithCode(int code) {
if (code < 0 || code >= STATUSES.length || STATUSES[code] == null) {
return new HttpResponseStatus(code, "Unknown status");
}
return STATUSES[code];
}
private HttpResponseStatus(int code, String description) {
this.code = code;
this.description = description;
}
public int code() {
return code;
}
public String description() {
return description;
}
@Override
public String toString() {
return code + " " + description;
}
}