/
Status.java
1872 lines (1733 loc) · 63.8 KB
/
Status.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2005-2014 Restlet
*
* The contents of this file are subject to the terms of one of the following
* open source licenses: Apache 2.0 or or EPL 1.0 (the "Licenses"). You can
* select the license that you prefer but you may not use this file except in
* compliance with one of these Licenses.
*
* You can obtain a copy of the Apache 2.0 license at
* http://www.opensource.org/licenses/apache-2.0
*
* You can obtain a copy of the EPL 1.0 license at
* http://www.opensource.org/licenses/eclipse-1.0
*
* See the Licenses for the specific language governing permissions and
* limitations under the Licenses.
*
* Alternatively, you can obtain a royalty free commercial license with less
* limitations, transferable or non-transferable, directly at
* http://restlet.com/products/restlet-framework
*
* Restlet is a registered trademark of Restlet S.A.S.
*/
package org.restlet.data;
import org.restlet.engine.Edition;
import org.restlet.engine.Engine;
/**
* Status to return after handling a call.
*
* @author Jerome Louvel
*/
public final class Status {
private static final String BASE_ADDED_HTTP = "http://tools.ietf.org/html/rfc6585";
private static final String BASE_HTTP = "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html";
private static final String BASE_RESTLET = "http://restlet.org/learn/javadocs/"
+ Engine.MAJOR_NUMBER
+ '.'
+ Engine.MINOR_NUMBER
+ "/"
+ Edition.CURRENT.getShortName().toLowerCase() + "/api/";
private static final String BASE_WEBDAV = "http://www.webdav.org/specs/rfc2518.html";
/**
* The request could not be understood by the server due to malformed
* syntax.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1">HTTP
* RFC - 10.4.1 400 Bad Request</a>
*/
public static final Status CLIENT_ERROR_BAD_REQUEST = new Status(400);
/**
* The request could not be completed due to a conflict with the current
* state of the resource (as experienced in a version control system).
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10">HTTP
* RFC - 10.4.10 409 Conflict</a>
*/
public static final Status CLIENT_ERROR_CONFLICT = new Status(409);
/**
* The user agent expects some behavior of the server (given in an Expect
* request-header field), but this expectation could not be met by this
* server.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18">HTTP
* RFC - 10.4.18 417 Expectation Failed</a>
*/
public static final Status CLIENT_ERROR_EXPECTATION_FAILED = new Status(417);
/**
* This status code means that the method could not be performed on the
* resource because the requested action depended on another action and that
* action failed.
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_424">WEBDAV
* RFC - 10.5 424 Failed Dependency</a>
*/
public static final Status CLIENT_ERROR_FAILED_DEPENDENCY = new Status(424);
/**
* The server understood the request, but is refusing to fulfill it as it
* could be explained in the entity.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4">HTTP
* RFC - 10.4.4 403 Forbidden</a>
*/
public static final Status CLIENT_ERROR_FORBIDDEN = new Status(403);
/**
* The requested resource is no longer available at the server and no
* forwarding address is known.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11">HTTP
* RFC - 10.4.11 410 Gone</a>
*/
public static final Status CLIENT_ERROR_GONE = new Status(410);
/**
* The server refuses to accept the request without a defined
* Content-Length.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12">HTTP
* RFC - 10.4.12 411 Length Required</a>
*/
public static final Status CLIENT_ERROR_LENGTH_REQUIRED = new Status(411);
/**
* The source or destination resource of a method is locked (or temporarily
* involved in another process).
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_423">WEBDAV
* RFC - 10.4 423 Locked</a>
*/
public static final Status CLIENT_ERROR_LOCKED = new Status(423);
/**
* The method specified in the Request-Line is not allowed for the resource
* identified by the Request-URI.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6">HTTP
* RFC - 10.4.6 405 Method Not Allowed</a>
*/
public static final Status CLIENT_ERROR_METHOD_NOT_ALLOWED = new Status(405);
/**
* The resource identified by the request is only capable of generating
* response entities whose content characteristics do not match the user's
* requirements (in Accept* headers).
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7">HTTP
* RFC - 10.4.7 406 Not Acceptable</a>
*/
public static final Status CLIENT_ERROR_NOT_ACCEPTABLE = new Status(406);
/**
* The server has not found anything matching the Request-URI or the server
* does not wish to reveal exactly why the request has been refused, or no
* other response is applicable.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5">HTTP
* RFC - 10.4.5 404 Not Found</a>
*/
public static final Status CLIENT_ERROR_NOT_FOUND = new Status(404);
/**
* This code is reserved for future use.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.3">HTTP
* RFC - 10.4.3 402 Payment Required</a>
*/
public static final Status CLIENT_ERROR_PAYMENT_REQUIRED = new Status(402);
/**
* Sent by the server when the user agent asks the server to carry out a
* request under certain conditions that are not met.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.13">HTTP
* RFC - 10.4.13 412 Precondition Failed</a>
*/
public static final Status CLIENT_ERROR_PRECONDITION_FAILED = new Status(
412);
/**
* This code is similar to 401 (Unauthorized), but indicates that the client
* must first authenticate itself with the proxy.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.8">HTTP
* RFC - 10.4.8 407 Proxy Authentication Required</a>
*/
public static final Status CLIENT_ERROR_PROXY_AUTHENTIFICATION_REQUIRED = new Status(
407);
/**
* The server is refusing to process a request because the request entity is
* larger than the server is willing or able to process.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.14">HTTP
* RFC - 10.4.14 413 Request Entity Too Large</a>
*/
public static final Status CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = new Status(
413);
/**
* Sent by the server when an HTTP client opens a connection, but has never
* sent a request (or never sent the blank line that signals the end of the
* request).
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.9">HTTP
* RFC - 10.4.9 408 Request Timeout</a>
*/
public static final Status CLIENT_ERROR_REQUEST_TIMEOUT = new Status(408);
/**
* The server is refusing to service the request because the Request-URI is
* longer than the server is willing to interpret.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.15">HTTP
* RFC - 10.4.15 414 Request-URI Too Long</a>
*/
public static final Status CLIENT_ERROR_REQUEST_URI_TOO_LONG = new Status(
414);
/**
* The request includes a Range request-header field and the selected
* resource is too small for any of the byte-ranges to apply.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.17">HTTP
* RFC - 10.4.17 416 Requested Range Not Satisfiable</a>
*/
public static final Status CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE = new Status(
416);
/**
* The server refuses to accept the request because the user has sent too
* many requests in a given amount of time.
*
* @see <a href="http://tools.ietf.org/html/rfc6585#section-4">HTTP RFC -
* 10.4.12 429 Too Many Requests</a>
*/
public static final Status CLIENT_ERROR_TOO_MANY_REQUESTS = new Status(429);
/**
* The request requires user authentication.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2">HTTP
* RFC - 10.4.2 401 Unauthorized</a>
*/
public static final Status CLIENT_ERROR_UNAUTHORIZED = new Status(401);
/**
* This status code means the server understands the content type of the
* request entity (syntactically correct) but was unable to process the
* contained instructions.
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_422">WEBDAV
* RFC - 10.3 422 Unprocessable Entity</a>
*/
public static final Status CLIENT_ERROR_UNPROCESSABLE_ENTITY = new Status(
422);
/**
* The server is refusing to service the request because the entity of the
* request is in a format not supported by the requested resource for the
* requested method.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16">HTTP
* RFC - 10.4.16 415 Unsupported Media Type</a>
*/
public static final Status CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE = new Status(
415);
/**
* The client connector faced an error during the communication with the
* remote server (interruption, timeout, etc.). The status code is 1001.
*/
public static final Status CONNECTOR_ERROR_COMMUNICATION = new Status(1001);
/**
* The client connector could not connect to the remote server. The status
* code is 1000.
*/
public static final Status CONNECTOR_ERROR_CONNECTION = new Status(1000);
/**
* The client connector faced an internal error during the process of a
* request to its server or the process of a response to its client. The
* status code is 1002.
*/
public static final Status CONNECTOR_ERROR_INTERNAL = new Status(1002);
/**
* This interim response (the client has to wait for the final response) is
* used to inform the client that the initial part of the request has been
* received and has not yet been rejected or completed by the server.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1">HTTP
* RFC - 10.1.1 100 Continue</a>
*/
public static final Status INFO_CONTINUE = new Status(100);
/**
* Warning status code, typically returned by a cache, indicating that it is
* intentionally disconnected from the rest of the network for a period of
* time.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status INFO_DISCONNECTED_OPERATION = new Status(112);
/**
* Warning status code, typically returned by a cache, indicating that it
* heuristically chose a freshness lifetime greater than 24 hours and the
* response's age is greater than 24 hours.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status INFO_HEURISTIC_EXPIRATION = new Status(113);
/**
* Warning status code, optionally including arbitrary information to be
* presented to a human user, typically returned by a cache.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status INFO_MISC_WARNING = new Status(199);
/**
* This interim response is used to inform the client that the server has
* accepted the complete request, but has not yet completed it since the
* server has a reasonable expectation that the request will take
* significant time to complete.
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_102">WEBDAV
* RFC - 10.1 102 Processing</a>
*/
public static final Status INFO_PROCESSING = new Status(102);
/**
* Warning status code, typically returned by a cache, indicating that the
* response is stale because an attempt to revalidate the response failed,
* due to an inability to reach the server.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status INFO_REVALIDATION_FAILED = new Status(111);
/**
* Warning status code, typically returned by a cache, indicating that the
* response is stale.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status INFO_STALE_RESPONSE = new Status(110);
/**
* The server understands and is willing to comply with the client's
* request, via the Upgrade message header field, for a change in the
* application protocol being used on this connection.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.2">HTTP
* RFC - 10.1.1 101 Switching Protocols</a>
*/
public static final Status INFO_SWITCHING_PROTOCOL = new Status(101);
/**
* The requested resource resides temporarily under a different URI which
* should not be used for future requests by the client (use status codes
* 303 or 307 instead since this status has been manifestly misused).
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3">HTTP
* RFC - 10.3.3 302 Found</a>
*/
public static final Status REDIRECTION_FOUND = new Status(302);
/**
* The server lets the user agent choosing one of the multiple
* representations of the requested resource, each representation having its
* own specific location provided in the response entity.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1">HTTP
* RFC - 10.3.1 300 Multiple Choices</a>
*/
public static final Status REDIRECTION_MULTIPLE_CHOICES = new Status(300);
/**
* Status code sent by the server in response to a conditional GET request
* in case the document has not been modified.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5">HTTP
* RFC - 10.3.5 304 Not Modified</a>
*/
public static final Status REDIRECTION_NOT_MODIFIED = new Status(304);
/**
* The requested resource has been assigned a new permanent URI and any
* future references to this resource SHOULD use one of the returned URIs.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2">HTTP
* RFC - 10.3.2 301 Moved Permanently</a>
*/
public static final Status REDIRECTION_PERMANENT = new Status(301);
/**
* The response to the request can be found under a different URI and SHOULD
* be retrieved using a GET method on that resource.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4">HTTP
* RFC - 10.3.4 303 See Other</a>
*/
public static final Status REDIRECTION_SEE_OTHER = new Status(303);
/**
* The requested resource resides temporarily under a different URI which
* should not be used for future requests by the client.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8">HTTP
* RFC - 10.3.8 307 Temporary Redirect</a>
*/
public static final Status REDIRECTION_TEMPORARY = new Status(307);
/**
* The requested resource MUST be accessed through the proxy given by the
* Location field.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.6">HTTP
* RFC - 10.3.6 305 Use Proxy</a>
*/
public static final Status REDIRECTION_USE_PROXY = new Status(305);
/**
* The server, while acting as a gateway or proxy, received an invalid
* response from the upstream server it accessed in attempting to fulfill
* the request.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.3">HTTP
* RFC - 10.5.3 502 Bad Gateway</a>
*/
public static final Status SERVER_ERROR_BAD_GATEWAY = new Status(502);
/**
* The server, while acting as a gateway or proxy, could not connect to the
* upstream server.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.5">HTTP
* RFC - 10.5.5 504 Gateway Timeout</a>
*/
public static final Status SERVER_ERROR_GATEWAY_TIMEOUT = new Status(504);
/**
* This status code means the method could not be performed on the resource
* because the server is unable to store the representation needed to
* successfully complete the request.
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_507">WEBDAV
* RFC - 10.6 507 Insufficient Storage</a>
*/
public static final Status SERVER_ERROR_INSUFFICIENT_STORAGE = new Status(
507);
/**
* The server encountered an unexpected condition which prevented it from
* fulfilling the request.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1">HTTP
* RFC - 10.5.1 500 Internal Server Error</a>
*/
public static final Status SERVER_ERROR_INTERNAL = new Status(500);
/**
* The server does not support the functionality required to fulfill the
* request.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2">HTTP
* RFC - 10.5.2 501 Not Implemented</a>
*/
public static final Status SERVER_ERROR_NOT_IMPLEMENTED = new Status(501);
/**
* The server is currently unable to handle the request due to a temporary
* overloading or maintenance of the server.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4">HTTP
* RFC - 10.5.4 503 Service Unavailable</a>
*/
public static final Status SERVER_ERROR_SERVICE_UNAVAILABLE = new Status(
503);
/**
* The server does not support, or refuses to support, the HTTP protocol
* version that was used in the request message.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.6">HTTP
* RFC - 10.5.6 505 HTTP Version Not Supported</a>
*/
public static final Status SERVER_ERROR_VERSION_NOT_SUPPORTED = new Status(
505);
/**
* The request has been accepted for processing, but the processing has not
* been completed.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.3">HTTP
* RFC - 10.2.3 202 Accepted</a>
*/
public static final Status SUCCESS_ACCEPTED = new Status(202);
/**
* The request has been fulfilled and resulted in a new resource being
* created.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2">HTTP
* RFC - 10.2.2 201 Created</a>
*/
public static final Status SUCCESS_CREATED = new Status(201);
/**
* Warning status code, optionally including arbitrary information to be
* presented to a human user, typically returned by a cache.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status SUCCESS_MISC_PERSISTENT_WARNING = new Status(299);
/**
* This response is used to inform the client that the HTTP response entity
* contains a set of status codes generated during the method invocation.
*
* @see <a href="http://www.webdav.org/specs/rfc2518.html#STATUS_207">WEBDAV
* RFC - 10.2 207 Multi-Status</a>
*/
public static final Status SUCCESS_MULTI_STATUS = new Status(207);
/**
* The server has fulfilled the request but does not need to return an
* entity-body (for example after a DELETE), and might want to return
* updated meta-information.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5">HTTP
* RFC - 10.2.5 204 No Content</a>
*/
public static final Status SUCCESS_NO_CONTENT = new Status(204);
/**
* The request has succeeded but the returned meta-information in the
* entity-header does not come from the origin server, but is gathered from
* a local or a third-party copy.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4">HTTP
* RFC - 10.2.4 203 Non-Authoritative Information</a>
*/
public static final Status SUCCESS_NON_AUTHORITATIVE = new Status(203);
/**
* The request has succeeded.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1">HTTP
* RFC - 10.2.1 200 OK</a>
*/
public static final Status SUCCESS_OK = new Status(200);
/**
* The server has fulfilled the partial GET request for the resource
* assuming the request has included a Range header field indicating the
* desired range.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.7">HTTP
* RFC - 10.2.7 206 Partial Content</a>
*/
public static final Status SUCCESS_PARTIAL_CONTENT = new Status(206);
/**
* The server has fulfilled the request and the user agent SHOULD reset the
* document view which caused the request to be sent.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.6">HTTP
* RFC - 10.2.6 205 Reset Content</a>
*/
public static final Status SUCCESS_RESET_CONTENT = new Status(205);
/**
* Warning status code, typically returned by a cache or a proxy, indicating
* that the response has been transformed.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">HTTP
* RFC - 14.46 Warning</a>
*/
public static final Status SUCCESS_TRANSFORMATION_APPLIED = new Status(214);
/**
* Check if the provided reason phrase of the status contains forbidden
* characters such as CR and LF. An IllegalArgumentException is thrown in
* this case.
*
* @see <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1">Status
* Code and Reason Phrase</a>
* @param reasonPhrase
* The reason phrase to check.
* @return The name if it is correct.
*/
private static String checkReasonPhrase(String reasonPhrase) {
if (reasonPhrase != null) {
if (reasonPhrase.contains("\n") || reasonPhrase.contains("\r")) {
throw new IllegalArgumentException(
"Reason phrase of the status must not contain CR or LF characters.");
}
}
return reasonPhrase;
}
/**
* Indicates if the status is a client error status, meaning "The request
* contains bad syntax or cannot be fulfilled".
*
* @param code
* The code of the status.
* @return True if the status is a client error status.
*/
public static boolean isClientError(int code) {
return (code >= 400) && (code <= 499);
}
/**
* Indicates if the status is a connector error status, meaning "The
* connector failed to send or receive an apparently valid message".
*
* @param code
* The code of the status.
* @return True if the status is a server error status.
*/
public static boolean isConnectorError(int code) {
return (code >= 1000) && (code <= 1099);
}
/**
* Indicates if the status is an error (client or server) status.
*
* @param code
* The code of the status.
* @return True if the status is an error (client or server) status.
*/
public static boolean isError(int code) {
return isClientError(code) || isServerError(code)
|| isConnectorError(code);
}
/**
* Indicates if the status is a client error status, meaning "The request
* contains bad syntax or cannot be fulfilled".
*
* @param code
* The code of the status.
* @return True if the status is a client error status.
*/
public static boolean isGlobalError(int code) {
return (code >= 600) && (code <= 699);
}
/**
* Indicates if the status is an information status, meaning "request
* received, continuing process".
*
* @param code
* The code of the status.
* @return True if the status is an information status.
*/
public static boolean isInformational(int code) {
return (code >= 100) && (code <= 199);
}
/**
* Indicates if the status is a redirection status, meaning "Further action
* must be taken in order to complete the request".
*
* @param code
* The code of the status.
* @return True if the status is a redirection status.
*/
public static boolean isRedirection(int code) {
return (code >= 300) && (code <= 399);
}
/**
* Indicates if the status is a server error status, meaning "The server
* failed to fulfill an apparently valid request".
*
* @param code
* The code of the status.
* @return True if the status is a server error status.
*/
public static boolean isServerError(int code) {
return (code >= 500) && (code <= 599);
}
/**
* Indicates if the status is a success status, meaning "The action was
* successfully received, understood, and accepted".
*
* @param code
* The code of the status.
* @return True if the status is a success status.
*/
public static boolean isSuccess(int code) {
return (code >= 200) && (code <= 299);
}
/**
* Returns the status associated to a code. If an existing constant exists
* then it is returned, otherwise a new instance is created.
*
* @param code
* The code.
* @return The associated status.
*/
public static Status valueOf(int code) {
Status result = null;
switch (code) {
case 100:
result = INFO_CONTINUE;
break;
case 101:
result = INFO_SWITCHING_PROTOCOL;
break;
case 102:
result = INFO_PROCESSING;
break;
case 110:
result = INFO_STALE_RESPONSE;
break;
case 111:
result = INFO_REVALIDATION_FAILED;
break;
case 112:
result = INFO_DISCONNECTED_OPERATION;
break;
case 113:
result = INFO_HEURISTIC_EXPIRATION;
break;
case 199:
result = INFO_MISC_WARNING;
break;
case 200:
result = SUCCESS_OK;
break;
case 201:
result = SUCCESS_CREATED;
break;
case 202:
result = SUCCESS_ACCEPTED;
break;
case 203:
result = SUCCESS_NON_AUTHORITATIVE;
break;
case 204:
result = SUCCESS_NO_CONTENT;
break;
case 205:
result = SUCCESS_RESET_CONTENT;
break;
case 206:
result = SUCCESS_PARTIAL_CONTENT;
break;
case 207:
result = SUCCESS_MULTI_STATUS;
break;
case 214:
result = SUCCESS_TRANSFORMATION_APPLIED;
break;
case 299:
result = SUCCESS_MISC_PERSISTENT_WARNING;
break;
case 300:
result = REDIRECTION_MULTIPLE_CHOICES;
break;
case 301:
result = REDIRECTION_PERMANENT;
break;
case 302:
result = REDIRECTION_FOUND;
break;
case 303:
result = REDIRECTION_SEE_OTHER;
break;
case 304:
result = REDIRECTION_NOT_MODIFIED;
break;
case 305:
result = REDIRECTION_USE_PROXY;
break;
case 307:
result = REDIRECTION_TEMPORARY;
break;
case 400:
result = CLIENT_ERROR_BAD_REQUEST;
break;
case 401:
result = CLIENT_ERROR_UNAUTHORIZED;
break;
case 402:
result = CLIENT_ERROR_PAYMENT_REQUIRED;
break;
case 403:
result = CLIENT_ERROR_FORBIDDEN;
break;
case 404:
result = CLIENT_ERROR_NOT_FOUND;
break;
case 405:
result = CLIENT_ERROR_METHOD_NOT_ALLOWED;
break;
case 406:
result = CLIENT_ERROR_NOT_ACCEPTABLE;
break;
case 407:
result = CLIENT_ERROR_PROXY_AUTHENTIFICATION_REQUIRED;
break;
case 408:
result = CLIENT_ERROR_REQUEST_TIMEOUT;
break;
case 409:
result = CLIENT_ERROR_CONFLICT;
break;
case 410:
result = CLIENT_ERROR_GONE;
break;
case 411:
result = CLIENT_ERROR_LENGTH_REQUIRED;
break;
case 412:
result = CLIENT_ERROR_PRECONDITION_FAILED;
break;
case 413:
result = CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE;
break;
case 414:
result = CLIENT_ERROR_REQUEST_URI_TOO_LONG;
break;
case 415:
result = CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE;
break;
case 416:
result = CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE;
break;
case 417:
result = CLIENT_ERROR_EXPECTATION_FAILED;
break;
case 422:
result = CLIENT_ERROR_UNPROCESSABLE_ENTITY;
break;
case 423:
result = CLIENT_ERROR_LOCKED;
break;
case 424:
result = CLIENT_ERROR_FAILED_DEPENDENCY;
break;
case 429:
result = CLIENT_ERROR_TOO_MANY_REQUESTS;
break;
case 500:
result = SERVER_ERROR_INTERNAL;
break;
case 501:
result = SERVER_ERROR_NOT_IMPLEMENTED;
break;
case 502:
result = SERVER_ERROR_BAD_GATEWAY;
break;
case 503:
result = SERVER_ERROR_SERVICE_UNAVAILABLE;
break;
case 504:
result = SERVER_ERROR_GATEWAY_TIMEOUT;
break;
case 505:
result = SERVER_ERROR_VERSION_NOT_SUPPORTED;
break;
case 507:
result = SERVER_ERROR_INSUFFICIENT_STORAGE;
break;
case 1000:
result = CONNECTOR_ERROR_CONNECTION;
break;
case 1001:
result = CONNECTOR_ERROR_COMMUNICATION;
break;
case 1002:
result = CONNECTOR_ERROR_INTERNAL;
break;
default:
result = new Status(code);
}
return result;
}
/** The specification code. */
private final int code;
/** The longer description. */
private final String description;
/**
* The short reason phrase displayed next to the status code in a HTTP
* response.
*/
private volatile String reasonPhrase;
/** The related error or exception. */
private final Throwable throwable;
/** The URI of the specification describing the method. */
private final String uri;
/**
* Constructor.
*
* @param code
* The specification code.
*/
public Status(int code) {
this(code, null, null, null, null);
}
/**
* Constructor.
*
* @param code
* The specification code.
* @param reasonPhrase
* The short reason phrase displayed next to the status code in a
* HTTP response.
*/
public Status(int code, String reasonPhrase) {
this(code, null, reasonPhrase, null, null);
}
/**
* Constructor.
*
* @param code
* The specification code.
* @param reasonPhrase
* The short reason phrase displayed next to the status code in a
* HTTP response.
* @param description
* The longer description.
*/
public Status(int code, String reasonPhrase, String description) {
this(code, null, reasonPhrase, description, null);
}
/**