View Javadoc
1   package ca.uhn.fhir.rest.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.nio.charset.Charset;
24  import java.util.*;
25  
26  public class Constants {
27  
28  	public static final String CACHE_CONTROL_MAX_RESULTS = "max-results";
29  	public static final String CACHE_CONTROL_NO_CACHE = "no-cache";
30  	public static final String CACHE_CONTROL_NO_STORE = "no-store";
31  	public static final String CHARSET_NAME_UTF8 = "UTF-8";
32  	public static final Charset CHARSET_UTF8;
33  	public static final String CHARSET_UTF8_CTSUFFIX = "; charset=" + CHARSET_NAME_UTF8;
34  	/**
35  	 * Contains a standard set of headers which are used by FHIR / HAPI FHIR, and therefore
36  	 * would make a useful set for CORS AllowedHeader declarations
37  	 */
38  	public static final Set<String> CORS_ALLOWED_HEADERS;
39  	/**
40  	 * Contains a standard set of HTTP Methods which are used by FHIR / HAPI FHIR, and therefore
41  	 * would make a useful set for CORS AllowedMethod declarations
42  	 */
43  	public static final Set<String> CORS_ALLWED_METHODS;
44  	public static final String CT_FHIR_JSON = "application/json+fhir";
45  	public static final String CT_FHIR_JSON_NEW = "application/fhir+json";
46  	public static final String CT_FHIR_XML = "application/xml+fhir";
47  	public static final String CT_FHIR_XML_NEW = "application/fhir+xml";
48  	public static final String CT_HTML = "text/html";
49  	public static final String CT_HTML_WITH_UTF8 = "text/html" + CHARSET_UTF8_CTSUFFIX;
50  	public static final String CT_JSON = "application/json";
51  	public static final String CT_JSON_PATCH = "application/json-patch+json";
52  	public static final String CT_OCTET_STREAM = "application/octet-stream";
53  	public static final String CT_TEXT = "text/plain";
54  	public static final String CT_TEXT_WITH_UTF8 = CT_TEXT + CHARSET_UTF8_CTSUFFIX;
55  	public static final String CT_X_FORM_URLENCODED = "application/x-www-form-urlencoded";
56  	public static final String CT_XML = "application/xml";
57  	public static final String CT_XML_PATCH = "application/xml-patch+xml";
58  	public static final String ENCODING_GZIP = "gzip";
59  	public static final String EXTOP_PROCESS_MESSAGE = "$process-message"; //Used in messaging
60  	public static final String EXTOP_VALIDATE = "$validate";
61  	public static final String EXTOP_VALIDATE_MODE = "mode";
62  	public static final String EXTOP_VALIDATE_PROFILE = "profile";
63  	public static final String EXTOP_VALIDATE_RESOURCE = "resource";
64  	public static final String FORMAT_HTML = "html";
65  	public static final String FORMAT_JSON = "json";
66  	public static final String FORMAT_XML = "xml";
67  	/**
68  	 * "text/html" and "html"
69  	 */
70  	public static final Set<String> FORMATS_HTML;
71  	public static final String FORMATS_HTML_JSON = "html/json";
72  	public static final String FORMATS_HTML_XML = "html/xml";
73  	public static final String HEADER_ACCEPT = "Accept";
74  	public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
75  	public static final String HEADER_ACCEPT_VALUE_JSON_NON_LEGACY = CT_FHIR_JSON_NEW + ";q=1.0, " + CT_FHIR_JSON + ";q=0.9";
76  	public static final String HEADER_ACCEPT_VALUE_XML_NON_LEGACY = CT_FHIR_XML_NEW + ";q=1.0, " + CT_FHIR_XML + ";q=0.9";
77  	public static final String HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY = CT_FHIR_XML + ";q=1.0, " + CT_FHIR_JSON + ";q=1.0";
78  	public static final String HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY = CT_FHIR_XML_NEW + ";q=1.0, " + CT_FHIR_JSON_NEW + ";q=1.0, " + HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY.replace("1.0", "0.9");
79  	public static final String HEADER_ALLOW = "Allow";
80  	public static final String HEADER_AUTHORIZATION = "Authorization";
81  	public static final String HEADER_AUTHORIZATION_VALPREFIX_BASIC = "Basic ";
82  	public static final String HEADER_AUTHORIZATION_VALPREFIX_BEARER = "Bearer ";
83  	public static final String HEADER_CACHE_CONTROL = "Cache-Control";
84  	public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";
85  	public static final String HEADER_CONTENT_ENCODING = "Content-Encoding";
86  	public static final String HEADER_CONTENT_LOCATION = "Content-Location";
87  	public static final String HEADER_CONTENT_LOCATION_LC = HEADER_CONTENT_LOCATION.toLowerCase();
88  	public static final String HEADER_CONTENT_TYPE = "Content-Type";
89  	public static final String HEADER_COOKIE = "Cookie";
90  	public static final String HEADER_CORS_ALLOW_METHODS = "Access-Control-Allow-Methods";
91  	public static final String HEADER_CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
92  	public static final String HEADER_CORS_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
93  	public static final String HEADER_ETAG = "ETag";
94  	public static final String HEADER_ETAG_LC = HEADER_ETAG.toLowerCase();
95  	public static final String HEADER_IF_MATCH = "If-Match";
96  	public static final String HEADER_IF_MATCH_LC = HEADER_IF_MATCH.toLowerCase();
97  	public static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since";
98  	public static final String HEADER_IF_MODIFIED_SINCE_LC = HEADER_IF_MODIFIED_SINCE.toLowerCase();
99  	public static final String HEADER_IF_NONE_EXIST = "If-None-Exist";
100 	public static final String HEADER_IF_NONE_EXIST_LC = HEADER_IF_NONE_EXIST.toLowerCase();
101 	public static final String HEADER_IF_NONE_MATCH = "If-None-Match";
102 	public static final String HEADER_IF_NONE_MATCH_LC = HEADER_IF_NONE_MATCH.toLowerCase();
103 	public static final String HEADER_LAST_MODIFIED = "Last-Modified";
104 	public static final String HEADER_LAST_MODIFIED_LOWERCASE = HEADER_LAST_MODIFIED.toLowerCase();
105 	public static final String HEADER_LOCATION = "Location";
106 	public static final String HEADER_LOCATION_LC = HEADER_LOCATION.toLowerCase();
107 	public static final String HEADER_ORIGIN = "Origin";
108 	public static final String HEADER_PREFER = "Prefer";
109 	public static final String HEADER_PREFER_RETURN = "return";
110 	public static final String HEADER_PREFER_RETURN_MINIMAL = "minimal";
111 	public static final String HEADER_PREFER_RETURN_REPRESENTATION = "representation";
112 	public static final String HEADER_PREFER_RETURN_OPERATION_OUTCOME = "OperationOutcome";
113 	public static final String HEADER_SUFFIX_CT_UTF_8 = "; charset=UTF-8";
114 	public static final String HEADERVALUE_CORS_ALLOW_METHODS_ALL = "GET, POST, PUT, DELETE, OPTIONS";
115 	public static final Map<Integer, String> HTTP_STATUS_NAMES;
116 	public static final String LINK_FHIR_BASE = "fhir-base";
117 	public static final String LINK_FIRST = "first";
118 	public static final String LINK_LAST = "last";
119 	public static final String LINK_NEXT = "next";
120 	public static final String LINK_PREVIOUS = "previous";
121 	public static final String LINK_SELF = "self";
122 	public static final String OPENSEARCH_NS_OLDER = "http://purl.org/atompub/tombstones/1.0";
123 	public static final String PARAM_ASYNC = "async"; //Used in messaging
124 	public static final String PARAM_AT = "_at";
125 	/**
126 	 * Used in paging links
127 	 */
128 	public static final String PARAM_BUNDLETYPE = "_bundletype";
129 	public static final String PARAM_CONTENT = "_content";
130 	public static final String PARAM_COUNT = "_count";
131 	public static final String PARAM_DELETE = "_delete";
132 	public static final String PARAM_ELEMENTS = "_elements";
133 	public static final String PARAM_FORMAT = "_format";
134 	public static final String PARAM_HAS = "_has";
135 	public static final String PARAM_HISTORY = "_history";
136 	public static final String PARAM_INCLUDE = "_include";
137 	public static final String PARAM_INCLUDE_QUALIFIER_RECURSE = ":recurse";
138 	public static final String PARAM_INCLUDE_RECURSE = "_include" + PARAM_INCLUDE_QUALIFIER_RECURSE;
139 	public static final String PARAM_LASTUPDATED = "_lastUpdated";
140 	public static final String PARAM_NARRATIVE = "_narrative";
141 	public static final String PARAM_PAGINGACTION = "_getpages";
142 	public static final String PARAM_PAGINGOFFSET = "_getpagesoffset";
143 	public static final String PARAM_PRETTY = "_pretty";
144 	public static final String PARAM_PRETTY_VALUE_FALSE = "false";
145 	public static final String PARAM_PRETTY_VALUE_TRUE = "true";
146 	public static final String PARAM_PROFILE = "_profile";
147 	public static final String PARAM_QUERY = "_query";
148 	public static final String PARAM_RESPONSE_URL = "response-url"; //Used in messaging
149 	public static final String PARAM_REVINCLUDE = "_revinclude";
150 	public static final String PARAM_REVINCLUDE_RECURSE = PARAM_REVINCLUDE + PARAM_INCLUDE_QUALIFIER_RECURSE;
151 	public static final String PARAM_SEARCH = "_search";
152 	public static final String PARAM_SECURITY = "_security";
153 	public static final String PARAM_SINCE = "_since";
154 	public static final String PARAM_SORT = "_sort";
155 	public static final String PARAM_SORT_ASC = "_sort:asc";
156 	public static final String PARAM_SORT_DESC = "_sort:desc";
157 	public static final String PARAM_SUMMARY = "_summary";
158 	public static final String PARAM_TAG = "_tag";
159 	public static final String PARAM_TAGS = "_tags";
160 	public static final String PARAM_TEXT = "_text";
161 	public static final String PARAM_VALIDATE = "_validate";
162 	public static final String PARAMQUALIFIER_MISSING = ":missing";
163 	public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
164 	public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
165 	public static final String PARAMQUALIFIER_STRING_CONTAINS = ":contains";
166 	public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
167 	public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
168 	public static final int STATUS_HTTP_200_OK = 200;
169 	public static final int STATUS_HTTP_201_CREATED = 201;
170 	public static final int STATUS_HTTP_204_NO_CONTENT = 204;
171 	public static final int STATUS_HTTP_304_NOT_MODIFIED = 304;
172 	public static final int STATUS_HTTP_400_BAD_REQUEST = 400;
173 	public static final int STATUS_HTTP_401_CLIENT_UNAUTHORIZED = 401;
174 	public static final int STATUS_HTTP_403_FORBIDDEN = 403;
175 
176 	public static final int STATUS_HTTP_404_NOT_FOUND = 404;
177 	public static final int STATUS_HTTP_405_METHOD_NOT_ALLOWED = 405;
178 	public static final int STATUS_HTTP_409_CONFLICT = 409;
179 	public static final int STATUS_HTTP_410_GONE = 410;
180 	public static final int STATUS_HTTP_412_PRECONDITION_FAILED = 412;
181 	public static final int STATUS_HTTP_422_UNPROCESSABLE_ENTITY = 422;
182 	public static final int STATUS_HTTP_500_INTERNAL_ERROR = 500;
183 	public static final int STATUS_HTTP_501_NOT_IMPLEMENTED = 501;
184 	public static final String TAG_SUBSETTED_CODE = "SUBSETTED";
185 	public static final String TAG_SUBSETTED_SYSTEM = "http://hl7.org/fhir/v3/ObservationValue";
186 	public static final String URL_TOKEN_HISTORY = "_history";
187 	public static final String URL_TOKEN_METADATA = "metadata";
188 	public static final String OO_INFOSTATUS_PROCESSING = "processing";
189 	public static final String PARAM_GRAPHQL_QUERY = "query";
190 	public static final String HEADER_X_CACHE = "X-Cache";
191 	public static final String HEADER_X_SECURITY_CONTEXT = "X-Security-Context";
192 	public static final String POWERED_BY_HEADER = "X-Powered-By";
193 	public static final Charset CHARSET_US_ASCII;
194 	public static final String PARAM_PAGEID = "_pageId";
195 	/**
196 	 * This is provided for testing only! Use with caution as this property may change.
197 	 */
198 	public static final String TEST_SYSTEM_PROP_VALIDATION_RESOURCE_CACHES_MS = "TEST_SYSTEM_PROP_VALIDATION_RESOURCE_CACHES_MS";
199 
200 	static {
201 		CHARSET_UTF8 = Charset.forName(CHARSET_NAME_UTF8);
202 		CHARSET_US_ASCII = Charset.forName("ISO-8859-1");
203 
204 		HashMap<Integer, String> statusNames = new HashMap<>();
205 		statusNames.put(200, "OK");
206 		statusNames.put(201, "Created");
207 		statusNames.put(202, "Accepted");
208 		statusNames.put(203, "Non-Authoritative Information");
209 		statusNames.put(204, "No Content");
210 		statusNames.put(205, "Reset Content");
211 		statusNames.put(206, "Partial Content");
212 		statusNames.put(207, "Multi-Status");
213 		statusNames.put(208, "Already Reported");
214 		statusNames.put(226, "IM Used");
215 		statusNames.put(300, "Multiple Choices");
216 		statusNames.put(301, "Moved Permanently");
217 		statusNames.put(302, "Found");
218 		statusNames.put(302, "Moved Temporarily");
219 		statusNames.put(303, "See Other");
220 		statusNames.put(304, "Not Modified");
221 		statusNames.put(305, "Use Proxy");
222 		statusNames.put(307, "Temporary Redirect");
223 		statusNames.put(308, "Permanent Redirect");
224 		statusNames.put(400, "Bad Request");
225 		statusNames.put(401, "Unauthorized");
226 		statusNames.put(402, "Payment Required");
227 		statusNames.put(403, "Forbidden");
228 		statusNames.put(404, "Not Found");
229 		statusNames.put(405, "Method Not Allowed");
230 		statusNames.put(406, "Not Acceptable");
231 		statusNames.put(407, "Proxy Authentication Required");
232 		statusNames.put(408, "Request Timeout");
233 		statusNames.put(409, "Conflict");
234 		statusNames.put(410, "Gone");
235 		statusNames.put(411, "Length Required");
236 		statusNames.put(412, "Precondition Failed");
237 		statusNames.put(413, "Payload Too Large");
238 		statusNames.put(413, "Request Entity Too Large");
239 		statusNames.put(414, "URI Too Long");
240 		statusNames.put(414, "Request-URI Too Long");
241 		statusNames.put(415, "Unsupported Media Type");
242 		statusNames.put(416, "Requested range not satisfiable");
243 		statusNames.put(417, "Expectation Failed");
244 		statusNames.put(418, "I'm a teapot");
245 		statusNames.put(419, "Insufficient Space On Resource");
246 		statusNames.put(420, "Method Failure");
247 		statusNames.put(421, "Destination Locked");
248 		statusNames.put(422, "Unprocessable Entity");
249 		statusNames.put(423, "Locked");
250 		statusNames.put(424, "Failed Dependency");
251 		statusNames.put(426, "Upgrade Required");
252 		statusNames.put(428, "Precondition Required");
253 		statusNames.put(429, "Too Many Requests");
254 		statusNames.put(431, "Request Header Fields Too Large");
255 		statusNames.put(500, "Internal Server Error");
256 		statusNames.put(501, "Not Implemented");
257 		statusNames.put(502, "Bad Gateway");
258 		statusNames.put(503, "Service Unavailable");
259 		statusNames.put(504, "Gateway Timeout");
260 		statusNames.put(505, "HTTP Version not supported");
261 		statusNames.put(506, "Variant Also Negotiates");
262 		statusNames.put(507, "Insufficient Storage");
263 		statusNames.put(508, "Loop Detected");
264 		statusNames.put(509, "Bandwidth Limit Exceeded");
265 		statusNames.put(510, "Not Extended");
266 		statusNames.put(511, "Network Authentication Required");
267 		HTTP_STATUS_NAMES = Collections.unmodifiableMap(statusNames);
268 
269 		Set<String> formatsHtml = new HashSet<>();
270 		formatsHtml.add(CT_HTML);
271 		formatsHtml.add(FORMAT_HTML);
272 		FORMATS_HTML = Collections.unmodifiableSet(formatsHtml);
273 
274 		// *********************************************************
275 		// Update CorsInterceptor's constructor documentation if you change these:
276 		// *********************************************************
277 		HashSet<String> corsAllowedHeaders = new HashSet<>();
278 		corsAllowedHeaders.add("Accept");
279 		corsAllowedHeaders.add("Access-Control-Request-Headers");
280 		corsAllowedHeaders.add("Access-Control-Request-Method");
281 		corsAllowedHeaders.add("Cache-Control");
282 		corsAllowedHeaders.add("Content-Type");
283 		corsAllowedHeaders.add("Origin");
284 		corsAllowedHeaders.add("Prefer");
285 		corsAllowedHeaders.add("X-FHIR-Starter");
286 		corsAllowedHeaders.add("X-Requested-With");
287 		CORS_ALLOWED_HEADERS = Collections.unmodifiableSet(corsAllowedHeaders);
288 
289 		// *********************************************************
290 		// Update CorsInterceptor's constructor documentation if you change these:
291 		// *********************************************************
292 		HashSet<String> corsAllowedMethods = new HashSet<>();
293 		corsAllowedMethods.addAll(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
294 		CORS_ALLWED_METHODS = Collections.unmodifiableSet(corsAllowedMethods);
295 	}
296 
297 }