All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jk.web.embedded.spring.HttpStatus Maven / Gradle / Ivy

Go to download

A wrapper for tomcat webserver that enables faster web application development in Java

There is a newer version: 7.0.0-M7
Show newest version
/*
 * Copyright 2002-2022 Dr. Jalal Kiswani. 
 * Email: [email protected]
 * Check out https://smart-api.com for more details
 * 
 * All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only, 
 * for commercial usage and support, please contact the author.
 *
 * 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.jk.web.embedded.spring;

import org.springframework.lang.Nullable;

// TODO: Auto-generated Javadoc
/**
 * The Enum HttpStatus.
 */
public enum HttpStatus {

	// 1xx Informational

	/** The continue. */
	CONTINUE(100, "Continue"),
	
	/** The switching protocols. */
	SWITCHING_PROTOCOLS(101, "Switching Protocols"),
	
	/** The processing. */
	PROCESSING(102, "Processing"),
	
	/** The checkpoint. */
	CHECKPOINT(103, "Checkpoint"),

	// 2xx Success

	/** The ok. */
	OK(200, "OK"),
	
	/** The created. */
	CREATED(201, "Created"),
	
	/** The accepted. */
	ACCEPTED(202, "Accepted"),
	
	/** The non authoritative information. */
	NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
	
	/** The no content. */
	NO_CONTENT(204, "No Content"),
	
	/** The reset content. */
	RESET_CONTENT(205, "Reset Content"),
	
	/** The partial content. */
	PARTIAL_CONTENT(206, "Partial Content"),
	
	/** The multi status. */
	MULTI_STATUS(207, "Multi-Status"),
	
	/** The already reported. */
	ALREADY_REPORTED(208, "Already Reported"),
	
	/** The im used. */
	IM_USED(226, "IM Used"),

	// 3xx Redirection

	/** The multiple choices. */
	MULTIPLE_CHOICES(300, "Multiple Choices"),
	
	/** The moved permanently. */
	MOVED_PERMANENTLY(301, "Moved Permanently"),
	
	/** The found. */
	FOUND(302, "Found"),
	
	/** The moved temporarily. */
	@Deprecated
	MOVED_TEMPORARILY(302, "Moved Temporarily"),
	
	/** The see other. */
	SEE_OTHER(303, "See Other"),
	
	/** The not modified. */
	NOT_MODIFIED(304, "Not Modified"),
	
	/** The use proxy. */
	@Deprecated
	USE_PROXY(305, "Use Proxy"),
	
	/** The temporary redirect. */
	TEMPORARY_REDIRECT(307, "Temporary Redirect"),
	
	/** The permanent redirect. */
	PERMANENT_REDIRECT(308, "Permanent Redirect"),

	// --- 4xx Client Error ---

	/** The bad request. */
	BAD_REQUEST(400, "Bad Request"),
	
	/** The unauthorized. */
	UNAUTHORIZED(401, "Unauthorized"),
	
	/** The payment required. */
	PAYMENT_REQUIRED(402, "Payment Required"),
	
	/** The forbidden. */
	FORBIDDEN(403, "Forbidden"),
	
	/** The not found. */
	NOT_FOUND(404, "Not Found"),
	
	/** The method not allowed. */
	METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
	
	/** The not acceptable. */
	NOT_ACCEPTABLE(406, "Not Acceptable"),
	
	/** The proxy authentication required. */
	PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
	
	/** The request timeout. */
	REQUEST_TIMEOUT(408, "Request Timeout"),
	
	/** The conflict. */
	CONFLICT(409, "Conflict"),
	
	/** The gone. */
	GONE(410, "Gone"),
	
	/** The length required. */
	LENGTH_REQUIRED(411, "Length Required"),
	
	/** The precondition failed. */
	PRECONDITION_FAILED(412, "Precondition Failed"),
	
	/** The payload too large. */
	PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
	
	/** The request entity too large. */
	@Deprecated
	REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
	
	/** The uri too long. */
	URI_TOO_LONG(414, "URI Too Long"),
	
	/** The request uri too long. */
	@Deprecated
	REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
	
	/** The unsupported media type. */
	UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
	
	/** The requested range not satisfiable. */
	REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
	
	/** The expectation failed. */
	EXPECTATION_FAILED(417, "Expectation Failed"),
	
	/** The i am a teapot. */
	I_AM_A_TEAPOT(418, "I'm a teapot"),
	
	/** The insufficient space on resource. */
	@Deprecated
	INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"),
	
	/** The method failure. */
	@Deprecated
	METHOD_FAILURE(420, "Method Failure"),
	
	/** The destination locked. */
	@Deprecated
	DESTINATION_LOCKED(421, "Destination Locked"),
	
	/** The unprocessable entity. */
	UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
	
	/** The locked. */
	LOCKED(423, "Locked"),
	
	/** The failed dependency. */
	FAILED_DEPENDENCY(424, "Failed Dependency"),
	
	/** The upgrade required. */
	UPGRADE_REQUIRED(426, "Upgrade Required"),
	
	/** The precondition required. */
	PRECONDITION_REQUIRED(428, "Precondition Required"),
	
	/** The too many requests. */
	TOO_MANY_REQUESTS(429, "Too Many Requests"),
	
	/** The request header fields too large. */
	REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
	
	/** The unavailable for legal reasons. */
	UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),

	// --- 5xx Server Error ---

	/** The internal server error. */
	INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
	
	/** The not implemented. */
	NOT_IMPLEMENTED(501, "Not Implemented"),
	
	/** The bad gateway. */
	BAD_GATEWAY(502, "Bad Gateway"),
	
	/** The service unavailable. */
	SERVICE_UNAVAILABLE(503, "Service Unavailable"),
	
	/** The gateway timeout. */
	GATEWAY_TIMEOUT(504, "Gateway Timeout"),
	
	/** The http version not supported. */
	HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),
	
	/** The variant also negotiates. */
	VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
	
	/** The insufficient storage. */
	INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
	
	/** The loop detected. */
	LOOP_DETECTED(508, "Loop Detected"),
	
	/** The bandwidth limit exceeded. */
	BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
	
	/** The not extended. */
	NOT_EXTENDED(510, "Not Extended"),
	
	/** The network authentication required. */
	NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");


	/** The value. */
	private final int value;

	/** The reason phrase. */
	private final String reasonPhrase;


	/**
	 * Instantiates a new http status.
	 *
	 * @param value        the value
	 * @param reasonPhrase the reason phrase
	 */
	HttpStatus(int value, String reasonPhrase) {
		this.value = value;
		this.reasonPhrase = reasonPhrase;
	}


	/**
	 * Value.
	 *
	 * @return the int
	 */
	public int value() {
		return this.value;
	}

	/**
	 * Gets the reason phrase.
	 *
	 * @return the reason phrase
	 */
	public String getReasonPhrase() {
		return this.reasonPhrase;
	}

	/**
	 * Checks if is 1 xx informational.
	 *
	 * @return true, if is 1 xx informational
	 */
	public boolean is1xxInformational() {
		return Series.INFORMATIONAL.equals(series());
	}

	/**
	 * Checks if is 2 xx successful.
	 *
	 * @return true, if is 2 xx successful
	 */
	public boolean is2xxSuccessful() {
		return Series.SUCCESSFUL.equals(series());
	}

	/**
	 * Checks if is 3 xx redirection.
	 *
	 * @return true, if is 3 xx redirection
	 */
	public boolean is3xxRedirection() {
		return Series.REDIRECTION.equals(series());
	}


	/**
	 * Checks if is 4 xx client error.
	 *
	 * @return true, if is 4 xx client error
	 */
	public boolean is4xxClientError() {
		return Series.CLIENT_ERROR.equals(series());
	}

	/**
	 * Checks if is 5 xx server error.
	 *
	 * @return true, if is 5 xx server error
	 */
	public boolean is5xxServerError() {
		return Series.SERVER_ERROR.equals(series());
	}

	/**
	 * Checks if is error.
	 *
	 * @return true, if is error
	 */
	public boolean isError() {
		return is4xxClientError() || is5xxServerError();
	}

	/**
	 * Series.
	 *
	 * @return the series
	 */
	public Series series() {
		return Series.valueOf(this);
	}

	/**
	 * To string.
	 *
	 * @return the string
	 */
	@Override
	public String toString() {
		return Integer.toString(this.value);
	}


	/**
	 * Value of.
	 *
	 * @param statusCode the status code
	 * @return the http status
	 */
	public static HttpStatus valueOf(int statusCode) {
		HttpStatus status = resolve(statusCode);
		if (status == null) {
			throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
		}
		return status;
	}


	/**
	 * Resolve.
	 *
	 * @param statusCode the status code
	 * @return the http status
	 */
	@Nullable
	public static HttpStatus resolve(int statusCode) {
		for (HttpStatus status : values()) {
			if (status.value == statusCode) {
				return status;
			}
		}
		return null;
	}


	/**
	 * The Enum Series.
	 */
	public enum Series {

		/** The informational. */
		INFORMATIONAL(1),
		
		/** The successful. */
		SUCCESSFUL(2),
		
		/** The redirection. */
		REDIRECTION(3),
		
		/** The client error. */
		CLIENT_ERROR(4),
		
		/** The server error. */
		SERVER_ERROR(5);

		/** The value. */
		private final int value;

		/**
		 * Instantiates a new series.
		 *
		 * @param value the value
		 */
		Series(int value) {
			this.value = value;
		}

		/**
		 * Value.
		 *
		 * @return the int
		 */
		public int value() {
			return this.value;
		}

		/**
		 * Value of.
		 *
		 * @param status the status
		 * @return the series
		 */
		public static Series valueOf(int status) {
			int seriesCode = status / 100;
			for (Series series : values()) {
				if (series.value == seriesCode) {
					return series;
				}
			}
			throw new IllegalArgumentException("No matching constant for [" + status + "]");
		}

		/**
		 * Value of.
		 *
		 * @param status the status
		 * @return the series
		 */
		public static Series valueOf(HttpStatus status) {
			return valueOf(status.value);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy