001: /*
002: * $Id: HttpConstants.java 10489 2008-01-23 17:53:38Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.transport.http;
012:
013: import org.mule.api.config.MuleProperties;
014: import org.mule.util.MapUtils;
015:
016: import java.util.Collections;
017: import java.util.Map;
018:
019: import org.apache.commons.collections.map.CaseInsensitiveMap;
020:
021: /**
022: * <code>HttpConstants</code> for request and response headers
023: */
024: // @ThreadSafe
025: public class HttpConstants {
026: // HTTP prefix
027: public static final String HTTP10 = "HTTP/1.0";
028: public static final String HTTP1X = "HTTP/1.x";
029: public static final String HTTP11 = "HTTP/1.1";
030: public static final String DEFAULT_HTTP_VERSION = HttpConstants.HTTP11;
031:
032: // Default HTTP port
033: public static final int DEFAULT_HTTP_PORT = 80;
034:
035: // HTTP Methods
036: public static final String METHOD_OPTIONS = "OPTIONS";
037: public static final String METHOD_GET = "GET";
038: public static final String METHOD_HEAD = "HEAD";
039: public static final String METHOD_POST = "POST";
040: public static final String METHOD_PUT = "PUT";
041: public static final String METHOD_DELETE = "DELETE";
042: public static final String METHOD_TRACE = "TRACE";
043: public static final String METHOD_CONNECT = "CONNECT";
044:
045: // Date header format
046: public static final String DATE_FORMAT = "EEE, dd MMM yyyy hh:mm:ss zzz";
047:
048: // Newline
049: public static final String CRLF = "\r\n";
050: // Mime/Content separator
051: public static final String HEADER_CONTENT_SEPARATOR = CRLF + CRLF;
052:
053: // The default content type
054: public static final String DEFAULT_CONTENT_TYPE = "text/plain";
055:
056: // Headers
057: public static final String HEADER_ACCEPT = "Accept"; // [Request]
058: public static final String HEADER_ACCEPT_CHARSET = "Accept-Charset"; // [Request]
059: public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; // [Request]
060: public static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language"; // [Request]
061: public static final String HEADER_ACCEPT_RANGES = "Accept-Ranges"; // [Response]
062: public static final String HEADER_AGE = "Age"; // [Response]
063: public static final String HEADER_ALLOW = "Allow"; // [Entity]
064: public static final String HEADER_AUTHORIZATION = "Authorization"; // [Request]
065: public static final String HEADER_CACHE_CONTROL = "Cache-Control"; // [General]
066: public static final String HEADER_CONNECTION = "Connection"; // [General]
067: public static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; // [Entity]
068: public static final String HEADER_CONTENT_LANGUAGE = "Content-Language"; // [Entity]
069: public static final String HEADER_CONTENT_LENGTH = "Content-Length"; // [Entity]
070: public static final String HEADER_CONTENT_LOCATION = "Content-Location"; // [Entity]
071: public static final String HEADER_CONTENT_MD5 = "Content-MD5"; // [Entity]
072: public static final String HEADER_CONTENT_RANGE = "Content-Range"; // [Entity]
073: public static final String HEADER_CONTENT_TYPE = "Content-Type"; // [Entity]
074: public static final String HEADER_COOKIE = "Cookie"; // [Request]
075: public static final String HEADER_COOKIE_SET = "Set-Cookie"; // [Response]
076: public static final String HEADER_DATE = "Date"; // [General]
077: public static final String HEADER_ETAG = "ETag"; // [Response]
078: public static final String HEADER_EXPECT = "Expect"; // [Request]
079: public static final String HEADER_EXPIRES = "Expires"; // [Entity]
080: public static final String HEADER_FROM = "From"; // [Request]
081: public static final String HEADER_HOST = "Host"; // [Request]
082: public static final String HEADER_IF_MATCH = "If-Match"; // [Request]
083: public static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since"; // [Request]
084: public static final String HEADER_IF_NONE_MATCH = "If-None-Match"; // [Request]
085: public static final String HEADER_IF_RANGE = "If-Range"; // [Request]
086: public static final String HEADER_IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; // [Request]
087: public static final String HEADER_KEEP_ALIVE = "Keep-Alive"; // [Entity]
088: public static final String HEADER_LAST_MODIFIED = "Last-Modified"; // [Entity]
089: public static final String HEADER_LOCATION = "Location"; // [Response]
090: public static final String HEADER_MAX_FORWARDS = "Max-Forwards"; // [Request]
091: public static final String HEADER_PRAGMA = "Pragma"; // [General]
092: public static final String HEADER_PROXY_AUTHENTICATE = "Proxy-Authenticate"; // [Response]
093: public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization"; // [Request]
094: public static final String HEADER_RANGE = "Range"; // [Request]
095: public static final String HEADER_REFERER = "Referer"; // [Request]
096: public static final String HEADER_RETRY_AFTER = "Retry-After"; // [Response]
097: public static final String HEADER_SERVER = "Server"; // [Response]
098: public static final String HEADER_SLUG = "Slug"; // [Response]
099: public static final String HEADER_TE = "TE"; // [Request]
100: public static final String HEADER_TRAILER = "Trailer"; // [General]
101: public static final String HEADER_TRANSFER_ENCODING = "Transfer-Encoding"; // [General]
102: public static final String HEADER_UPGRADE = "Upgrade"; // [General]
103: public static final String HEADER_USER_AGENT = "User-Agent"; // [Request]
104: public static final String HEADER_VARY = "Vary"; // [Response]
105: public static final String HEADER_VIA = "Via"; // [General]
106: public static final String HEADER_WARNING = "Warning"; // [General]
107: public static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate"; // [Response]
108:
109: // This is a POST-related request header value
110: public static final String HEADER_EXPECT_CONTINUE_REQUEST_VALUE = "100-continue"; // [Request]
111:
112: // Chunked transfer encoding indicator
113: public static final String TRANSFER_ENCODING_CHUNKED = "chunked";
114:
115: // Key for X-MULE headers
116: public static final String X_PROPERTY_PREFIX = "X-"
117: + MuleProperties.PROPERTY_PREFIX;
118:
119: // case-insenitive Maps of header names to their normalized representations
120: public static final Map REQUEST_HEADER_NAMES;
121: public static final Map RESPONSE_HEADER_NAMES;
122: public static final Map ALL_HEADER_NAMES;
123:
124: // Status codes
125: public static final int SC_CONTINUE = 100;
126: public static final int SC_SWITCHING_PROTOCOLS = 101;
127: public static final int SC_PROCESSING = 102;
128: public static final int SC_OK = 200;
129: public static final int SC_CREATED = 201;
130: public static final int SC_ACCEPTED = 202;
131: public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
132: public static final int SC_NO_CONTENT = 204;
133: public static final int SC_RESET_CONTENT = 205;
134: public static final int SC_PARTIAL_CONTENT = 206;
135: public static final int SC_MULTI_STATUS = 207;
136: public static final int SC_MULTIPLE_CHOICES = 300;
137: public static final int SC_MOVED_PERMANENTLY = 301;
138: public static final int SC_MOVED_TEMPORARILY = 302;
139: public static final int SC_SEE_OTHER = 303;
140: public static final int SC_NOT_MODIFIED = 304;
141: public static final int SC_USE_PROXY = 305;
142: public static final int SC_TEMPORARY_REDIRECT = 307;
143: public static final int SC_BAD_REQUEST = 400;
144: public static final int SC_UNAUTHORIZED = 401;
145: public static final int SC_PAYMENT_REQUIRED = 402;
146: public static final int SC_FORBIDDEN = 403;
147: public static final int SC_NOT_FOUND = 404;
148: public static final int SC_METHOD_NOT_ALLOWED = 405;
149: public static final int SC_NOT_ACCEPTABLE = 406;
150: public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
151: public static final int SC_REQUEST_TIMEOUT = 408;
152: public static final int SC_CONFLICT = 409;
153: public static final int SC_GONE = 410;
154: public static final int SC_LENGTH_REQUIRED = 411;
155: public static final int SC_PRECONDITION_FAILED = 412;
156: public static final int SC_REQUEST_TOO_LONG = 413;
157: public static final int SC_REQUEST_URI_TOO_LONG = 414;
158: public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
159: public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
160: public static final int SC_EXPECTATION_FAILED = 417;
161: public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
162: public static final int SC_METHOD_FAILURE = 420;
163: public static final int SC_UNPROCESSABLE_ENTITY = 422;
164: public static final int SC_LOCKED = 423;
165: public static final int SC_FAILED_DEPENDENCY = 424;
166: public static final int SC_INTERNAL_SERVER_ERROR = 500;
167: public static final int SC_NOT_IMPLEMENTED = 501;
168: public static final int SC_BAD_GATEWAY = 502;
169: public static final int SC_SERVICE_UNAVAILABLE = 503;
170: public static final int SC_GATEWAY_TIMEOUT = 504;
171: public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
172: public static final int SC_INSUFFICIENT_STORAGE = 507;
173:
174: static {
175: String[] strings = new String[] { HEADER_ACCEPT,
176: HEADER_ACCEPT_CHARSET, HEADER_ACCEPT_ENCODING,
177: HEADER_ACCEPT_LANGUAGE, HEADER_AUTHORIZATION,
178: HEADER_CACHE_CONTROL, HEADER_CONNECTION, HEADER_COOKIE,
179: HEADER_DATE, HEADER_EXPECT, HEADER_FROM, HEADER_HOST,
180: HEADER_IF_MATCH, HEADER_IF_MODIFIED_SINCE,
181: HEADER_IF_NONE_MATCH, HEADER_IF_RANGE,
182: HEADER_IF_UNMODIFIED_SINCE, HEADER_MAX_FORWARDS,
183: HEADER_PRAGMA, HEADER_PROXY_AUTHORIZATION,
184: HEADER_RANGE, HEADER_REFERER, HEADER_TE,
185: HEADER_TRAILER, HEADER_TRANSFER_ENCODING,
186: HEADER_UPGRADE, HEADER_USER_AGENT, HEADER_VIA,
187: HEADER_WARNING, HEADER_CONTENT_LENGTH, HEADER_SLUG };
188:
189: REQUEST_HEADER_NAMES = Collections.unmodifiableMap(MapUtils
190: .mapWithKeysAndValues(CaseInsensitiveMap.class,
191: strings, strings));
192:
193: strings = new String[] { HEADER_ACCEPT_RANGES, HEADER_AGE,
194: HEADER_ALLOW, HEADER_CACHE_CONTROL, HEADER_CONNECTION,
195: HEADER_CONTENT_ENCODING, HEADER_CONTENT_LANGUAGE,
196: HEADER_COOKIE_SET, HEADER_CONTENT_LOCATION,
197: HEADER_CONTENT_MD5, HEADER_CONTENT_RANGE, HEADER_DATE,
198: HEADER_ETAG, HEADER_EXPIRES, HEADER_LAST_MODIFIED,
199: HEADER_LOCATION, HEADER_PRAGMA,
200: HEADER_PROXY_AUTHENTICATE, HEADER_RETRY_AFTER,
201: HEADER_SERVER, HEADER_TRAILER,
202: HEADER_TRANSFER_ENCODING, HEADER_UPGRADE, HEADER_VARY,
203: HEADER_VIA, HEADER_WARNING, HEADER_WWW_AUTHENTICATE };
204:
205: RESPONSE_HEADER_NAMES = Collections.unmodifiableMap(MapUtils
206: .mapWithKeysAndValues(CaseInsensitiveMap.class,
207: strings, strings));
208:
209: strings = new String[] { HEADER_ALLOW, HEADER_CACHE_CONTROL,
210: HEADER_CONNECTION, HEADER_CONTENT_ENCODING,
211: HEADER_CONTENT_LANGUAGE, HEADER_CONTENT_LENGTH,
212: HEADER_CONTENT_LOCATION, HEADER_CONTENT_MD5,
213: HEADER_CONTENT_RANGE, HEADER_CONTENT_TYPE, HEADER_DATE,
214: HEADER_EXPIRES, HEADER_KEEP_ALIVE,
215: HEADER_LAST_MODIFIED, HEADER_PRAGMA, HEADER_TRAILER,
216: HEADER_TRANSFER_ENCODING, HEADER_UPGRADE, HEADER_VIA,
217: HEADER_WARNING };
218:
219: Map allHeaders = MapUtils.mapWithKeysAndValues(
220: CaseInsensitiveMap.class, strings, strings);
221: allHeaders.putAll(REQUEST_HEADER_NAMES);
222: allHeaders.putAll(RESPONSE_HEADER_NAMES);
223: ALL_HEADER_NAMES = Collections.unmodifiableMap(allHeaders);
224: }
225:
226: }
|