1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package com.foxinmy.weixin4j.http; 29 30 /** 31 * Constants enumerating the HTTP status codes. All status codes defined in 32 * RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are listed. 33 * 34 * 35 * @since 4.0 36 */ 37 public final class HttpStatus { 38 39 // --- 1xx Informational --- 40 41 /** <tt>100 Continue</tt> (HTTP/1.1 - RFC 2616) */ 42 public static final int SC_CONTINUE = 100; 43 /** <tt>101 Switching Protocols</tt> (HTTP/1.1 - RFC 2616) */ 44 public static final int SC_SWITCHING_PROTOCOLS = 101; 45 /** <tt>102 Processing</tt> (WebDAV - RFC 2518) */ 46 public static final int SC_PROCESSING = 102; 47 48 // --- 2xx Success --- 49 50 /** <tt>200 OK</tt> (HTTP/1.0 - RFC 1945) */ 51 public static final int SC_OK = 200; 52 /** <tt>201 Created</tt> (HTTP/1.0 - RFC 1945) */ 53 public static final int SC_CREATED = 201; 54 /** <tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945) */ 55 public static final int SC_ACCEPTED = 202; 56 /** <tt>203 Non Authoritative Information</tt> (HTTP/1.1 - RFC 2616) */ 57 public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203; 58 /** <tt>204 No Content</tt> (HTTP/1.0 - RFC 1945) */ 59 public static final int SC_NO_CONTENT = 204; 60 /** <tt>205 Reset Content</tt> (HTTP/1.1 - RFC 2616) */ 61 public static final int SC_RESET_CONTENT = 205; 62 /** <tt>206 Partial Content</tt> (HTTP/1.1 - RFC 2616) */ 63 public static final int SC_PARTIAL_CONTENT = 206; 64 /** 65 * <tt>207 Multi-Status</tt> (WebDAV - RFC 2518) or <tt>207 Partial Update 66 * OK</tt> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) 67 */ 68 public static final int SC_MULTI_STATUS = 207; 69 70 // --- 3xx Redirection --- 71 72 /** <tt>300 Mutliple Choices</tt> (HTTP/1.1 - RFC 2616) */ 73 public static final int SC_MULTIPLE_CHOICES = 300; 74 /** <tt>301 Moved Permanently</tt> (HTTP/1.0 - RFC 1945) */ 75 public static final int SC_MOVED_PERMANENTLY = 301; 76 /** 77 * <tt>302 Moved Temporarily</tt> (Sometimes <tt>Found</tt>) (HTTP/1.0 - RFC 78 * 1945) 79 */ 80 public static final int SC_MOVED_TEMPORARILY = 302; 81 /** <tt>303 See Other</tt> (HTTP/1.1 - RFC 2616) */ 82 public static final int SC_SEE_OTHER = 303; 83 /** <tt>304 Not Modified</tt> (HTTP/1.0 - RFC 1945) */ 84 public static final int SC_NOT_MODIFIED = 304; 85 /** <tt>305 Use Proxy</tt> (HTTP/1.1 - RFC 2616) */ 86 public static final int SC_USE_PROXY = 305; 87 /** <tt>307 Temporary Redirect</tt> (HTTP/1.1 - RFC 2616) */ 88 public static final int SC_TEMPORARY_REDIRECT = 307; 89 90 // --- 4xx Client Error --- 91 92 /** <tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616) */ 93 public static final int SC_BAD_REQUEST = 400; 94 /** <tt>401 Unauthorized</tt> (HTTP/1.0 - RFC 1945) */ 95 public static final int SC_UNAUTHORIZED = 401; 96 /** <tt>402 Payment Required</tt> (HTTP/1.1 - RFC 2616) */ 97 public static final int SC_PAYMENT_REQUIRED = 402; 98 /** <tt>403 Forbidden</tt> (HTTP/1.0 - RFC 1945) */ 99 public static final int SC_FORBIDDEN = 403; 100 /** <tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945) */ 101 public static final int SC_NOT_FOUND = 404; 102 /** <tt>405 Method Not Allowed</tt> (HTTP/1.1 - RFC 2616) */ 103 public static final int SC_METHOD_NOT_ALLOWED = 405; 104 /** <tt>406 Not Acceptable</tt> (HTTP/1.1 - RFC 2616) */ 105 public static final int SC_NOT_ACCEPTABLE = 406; 106 /** <tt>407 Proxy Authentication Required</tt> (HTTP/1.1 - RFC 2616) */ 107 public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; 108 /** <tt>408 Request Timeout</tt> (HTTP/1.1 - RFC 2616) */ 109 public static final int SC_REQUEST_TIMEOUT = 408; 110 /** <tt>409 Conflict</tt> (HTTP/1.1 - RFC 2616) */ 111 public static final int SC_CONFLICT = 409; 112 /** <tt>410 Gone</tt> (HTTP/1.1 - RFC 2616) */ 113 public static final int SC_GONE = 410; 114 /** <tt>411 Length Required</tt> (HTTP/1.1 - RFC 2616) */ 115 public static final int SC_LENGTH_REQUIRED = 411; 116 /** <tt>412 Precondition Failed</tt> (HTTP/1.1 - RFC 2616) */ 117 public static final int SC_PRECONDITION_FAILED = 412; 118 /** <tt>413 Request Entity Too Large</tt> (HTTP/1.1 - RFC 2616) */ 119 public static final int SC_REQUEST_TOO_LONG = 413; 120 /** <tt>414 Request-URI Too Long</tt> (HTTP/1.1 - RFC 2616) */ 121 public static final int SC_REQUEST_URI_TOO_LONG = 414; 122 /** <tt>415 Unsupported Media Type</tt> (HTTP/1.1 - RFC 2616) */ 123 public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415; 124 /** <tt>416 Requested Range Not Satisfiable</tt> (HTTP/1.1 - RFC 2616) */ 125 public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416; 126 /** <tt>417 Expectation Failed</tt> (HTTP/1.1 - RFC 2616) */ 127 public static final int SC_EXPECTATION_FAILED = 417; 128 129 /** 130 * Static constant for a 418 error. <tt>418 Unprocessable Entity</tt> 131 * (WebDAV drafts?) or <tt>418 Reauthentication Required</tt> (HTTP/1.1 132 * drafts?) 133 */ 134 // not used 135 // public static final int SC_UNPROCESSABLE_ENTITY = 418; 136 137 /** 138 * Static constant for a 419 error. 139 * <tt>419 Insufficient Space on Resource</tt> (WebDAV - 140 * draft-ietf-webdav-protocol-05?) or 141 * <tt>419 Proxy Reauthentication Required</tt> (HTTP/1.1 drafts?) 142 */ 143 public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419; 144 /** 145 * Static constant for a 420 error. <tt>420 Method Failure</tt> (WebDAV - 146 * draft-ietf-webdav-protocol-05?) 147 */ 148 public static final int SC_METHOD_FAILURE = 420; 149 /** <tt>422 Unprocessable Entity</tt> (WebDAV - RFC 2518) */ 150 public static final int SC_UNPROCESSABLE_ENTITY = 422; 151 /** <tt>423 Locked</tt> (WebDAV - RFC 2518) */ 152 public static final int SC_LOCKED = 423; 153 /** <tt>424 Failed Dependency</tt> (WebDAV - RFC 2518) */ 154 public static final int SC_FAILED_DEPENDENCY = 424; 155 156 // --- 5xx Server Error --- 157 158 /** <tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945) */ 159 public static final int SC_INTERNAL_SERVER_ERROR = 500; 160 /** <tt>501 Not Implemented</tt> (HTTP/1.0 - RFC 1945) */ 161 public static final int SC_NOT_IMPLEMENTED = 501; 162 /** <tt>502 Bad Gateway</tt> (HTTP/1.0 - RFC 1945) */ 163 public static final int SC_BAD_GATEWAY = 502; 164 /** <tt>503 Service Unavailable</tt> (HTTP/1.0 - RFC 1945) */ 165 public static final int SC_SERVICE_UNAVAILABLE = 503; 166 /** <tt>504 Gateway Timeout</tt> (HTTP/1.1 - RFC 2616) */ 167 public static final int SC_GATEWAY_TIMEOUT = 504; 168 /** <tt>505 HTTP Version Not Supported</tt> (HTTP/1.1 - RFC 2616) */ 169 public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505; 170 171 /** <tt>507 Insufficient Storage</tt> (WebDAV - RFC 2518) */ 172 public static final int SC_INSUFFICIENT_STORAGE = 507; 173 174 private final int statusCode; 175 private final String statusText; 176 177 public HttpStatus(int statusCode, String statusText) { 178 this.statusCode = statusCode; 179 this.statusText = statusText; 180 } 181 182 public int getStatusCode() { 183 return statusCode; 184 } 185 186 public String getStatusText() { 187 return statusText; 188 } 189 190 /** 191 * Returns the HTTP status series of this status code. 192 * 193 * @see HttpStatus.Series 194 */ 195 public Series series() { 196 return Series.valueOf(this); 197 } 198 199 /** 200 * Java 5 enumeration of HTTP status series. 201 * <p> 202 * Retrievable via {@link HttpStatus#series()}. 203 */ 204 public static enum Series { 205 206 INFORMATIONAL(1), SUCCESSFUL(2), REDIRECTION(3), CLIENT_ERROR(4), SERVER_ERROR( 207 5); 208 209 private final int value; 210 211 private Series(int value) { 212 this.value = value; 213 } 214 215 /** 216 * Return the integer value of this status series. Ranges from 1 to 5. 217 */ 218 public int value() { 219 return this.value; 220 } 221 222 public static Series valueOf(int status) { 223 int seriesCode = status / 100; 224 for (Series series : values()) { 225 if (series.value == seriesCode) { 226 return series; 227 } 228 } 229 throw new IllegalArgumentException("No matching constant for [" 230 + status + "]"); 231 } 232 233 public static Series valueOf(HttpStatus status) { 234 return valueOf(status.statusCode); 235 } 236 } 237 238 @Override 239 public String toString() { 240 return "[" + statusCode + "," + statusText + "]"; 241 } 242 }