|
1 | 1 | package org.unify4j.model.builder; |
2 | 2 |
|
| 3 | +import org.unify4j.common.Collection4j; |
3 | 4 | import org.unify4j.model.response.HttpResponse; |
4 | 5 |
|
5 | 6 | import java.util.Arrays; |
|
16 | 17 | * and an optional description or message. |
17 | 18 | */ |
18 | 19 | public class HttpStatusBuilder { |
19 | | - protected static final List<HttpResponse> statuses = Arrays.asList( |
20 | | - HttpStatusBuilder.CONTINUE, |
21 | | - HttpStatusBuilder.SWITCHING_PROTOCOLS, |
22 | | - HttpStatusBuilder.PROCESSING, |
23 | | - HttpStatusBuilder.OK, |
24 | | - HttpStatusBuilder.CREATED, |
25 | | - HttpStatusBuilder.ACCEPTED, |
26 | | - HttpStatusBuilder.NON_AUTHORITATIVE_INFORMATION, |
27 | | - HttpStatusBuilder.NO_CONTENT, |
28 | | - HttpStatusBuilder.RESET_CONTENT, |
29 | | - HttpStatusBuilder.PARTIAL_CONTENT, |
30 | | - HttpStatusBuilder.MULTI_STATUS, |
31 | | - HttpStatusBuilder.ALREADY_REPORTED, |
32 | | - HttpStatusBuilder.IM_USED, |
33 | | - HttpStatusBuilder.MULTIPLE_CHOICES, |
34 | | - HttpStatusBuilder.MOVED_PERMANENTLY, |
35 | | - HttpStatusBuilder.FOUND, |
36 | | - HttpStatusBuilder.SEE_OTHER, |
37 | | - HttpStatusBuilder.NOT_MODIFIED, |
38 | | - HttpStatusBuilder.USE_PROXY, |
39 | | - HttpStatusBuilder.RESERVED, |
40 | | - HttpStatusBuilder.TEMPORARY_REDIRECT, |
41 | | - HttpStatusBuilder.PERMANENT_REDIRECT, |
42 | | - HttpStatusBuilder.BAD_REQUEST, |
43 | | - HttpStatusBuilder.UNAUTHORIZED, |
44 | | - HttpStatusBuilder.PAYMENT_REQUIRED, |
45 | | - HttpStatusBuilder.FORBIDDEN, |
46 | | - HttpStatusBuilder.NOT_FOUND, |
47 | | - HttpStatusBuilder.METHOD_NOT_ALLOWED, |
48 | | - HttpStatusBuilder.NOT_ACCEPTABLE, |
49 | | - HttpStatusBuilder.PROXY_AUTHENTICATION_REQUIRED, |
50 | | - HttpStatusBuilder.REQUEST_TIMEOUT, |
51 | | - HttpStatusBuilder.CONFLICT, |
52 | | - HttpStatusBuilder.GONE, |
53 | | - HttpStatusBuilder.LENGTH_REQUIRED, |
54 | | - HttpStatusBuilder.PRECONDITION_FAILED, |
55 | | - HttpStatusBuilder.REQUEST_ENTITY_TOO_LARGE, |
56 | | - HttpStatusBuilder.REQUEST_URI_TOO_LONG, |
57 | | - HttpStatusBuilder.UNSUPPORTED_MEDIA_TYPE, |
58 | | - HttpStatusBuilder.REQUESTED_RANGE_NOT_SATISFIABLE, |
59 | | - HttpStatusBuilder.EXPECTATION_FAILED, |
60 | | - HttpStatusBuilder.IM_A_TEAPOT, |
61 | | - HttpStatusBuilder.ENHANCE_YOUR_CALM, |
62 | | - HttpStatusBuilder.UN_PROCESSABLE_ENTITY, |
63 | | - HttpStatusBuilder.LOCKED, |
64 | | - HttpStatusBuilder.FAILED_DEPENDENCY, |
65 | | - HttpStatusBuilder.UNORDERED_COLLECTION, |
66 | | - HttpStatusBuilder.UPGRADE_REQUIRED, |
67 | | - HttpStatusBuilder.PRECONDITION_REQUIRED, |
68 | | - HttpStatusBuilder.TOO_MANY_REQUESTS, |
69 | | - HttpStatusBuilder.REQUEST_HEADER_FIELDS_TOO_LARGE, |
70 | | - HttpStatusBuilder.NO_RESPONSE, |
71 | | - HttpStatusBuilder.RETRY_WITH, |
72 | | - HttpStatusBuilder.BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS, |
73 | | - HttpStatusBuilder.UNAVAILABLE_FOR_LEGAL_REASONS, |
74 | | - HttpStatusBuilder.CLIENT_CLOSED_REQUEST, |
75 | | - HttpStatusBuilder.INTERNAL_SERVER_ERROR, |
76 | | - HttpStatusBuilder.NOT_IMPLEMENTED, |
77 | | - HttpStatusBuilder.BAD_GATEWAY, |
78 | | - HttpStatusBuilder.SERVICE_UNAVAILABLE, |
79 | | - HttpStatusBuilder.GATEWAY_TIMEOUT, |
80 | | - HttpStatusBuilder.HTTP_VERSION_NOT_SUPPORTED, |
81 | | - HttpStatusBuilder.VARIANT_ALSO_NEGOTIATES, |
82 | | - HttpStatusBuilder.INSUFFICIENT_STORAGE, |
83 | | - HttpStatusBuilder.LOOP_DETECTED, |
84 | | - HttpStatusBuilder.BANDWIDTH_LIMIT_EXCEEDED, |
85 | | - HttpStatusBuilder.NOT_EXTENDED, |
86 | | - HttpStatusBuilder.NETWORK_AUTHENTICATION_REQUIRED, |
87 | | - HttpStatusBuilder.NETWORK_READ_TIMEOUT_ERROR, |
88 | | - HttpStatusBuilder.NETWORK_CONNECT_TIMEOUT_ERROR |
89 | | - ); |
| 20 | + protected static List<HttpResponse> statuses; |
90 | 21 |
|
91 | 22 | public static HttpResponse valueOf(int statusCode) { |
| 23 | + if (Collection4j.isEmpty(statuses)) { |
| 24 | + statuses = Arrays.asList( |
| 25 | + HttpStatusBuilder.CONTINUE, |
| 26 | + HttpStatusBuilder.SWITCHING_PROTOCOLS, |
| 27 | + HttpStatusBuilder.PROCESSING, |
| 28 | + HttpStatusBuilder.OK, |
| 29 | + HttpStatusBuilder.CREATED, |
| 30 | + HttpStatusBuilder.ACCEPTED, |
| 31 | + HttpStatusBuilder.NON_AUTHORITATIVE_INFORMATION, |
| 32 | + HttpStatusBuilder.NO_CONTENT, |
| 33 | + HttpStatusBuilder.RESET_CONTENT, |
| 34 | + HttpStatusBuilder.PARTIAL_CONTENT, |
| 35 | + HttpStatusBuilder.MULTI_STATUS, |
| 36 | + HttpStatusBuilder.ALREADY_REPORTED, |
| 37 | + HttpStatusBuilder.IM_USED, |
| 38 | + HttpStatusBuilder.MULTIPLE_CHOICES, |
| 39 | + HttpStatusBuilder.MOVED_PERMANENTLY, |
| 40 | + HttpStatusBuilder.FOUND, |
| 41 | + HttpStatusBuilder.SEE_OTHER, |
| 42 | + HttpStatusBuilder.NOT_MODIFIED, |
| 43 | + HttpStatusBuilder.USE_PROXY, |
| 44 | + HttpStatusBuilder.RESERVED, |
| 45 | + HttpStatusBuilder.TEMPORARY_REDIRECT, |
| 46 | + HttpStatusBuilder.PERMANENT_REDIRECT, |
| 47 | + HttpStatusBuilder.BAD_REQUEST, |
| 48 | + HttpStatusBuilder.UNAUTHORIZED, |
| 49 | + HttpStatusBuilder.PAYMENT_REQUIRED, |
| 50 | + HttpStatusBuilder.FORBIDDEN, |
| 51 | + HttpStatusBuilder.NOT_FOUND, |
| 52 | + HttpStatusBuilder.METHOD_NOT_ALLOWED, |
| 53 | + HttpStatusBuilder.NOT_ACCEPTABLE, |
| 54 | + HttpStatusBuilder.PROXY_AUTHENTICATION_REQUIRED, |
| 55 | + HttpStatusBuilder.REQUEST_TIMEOUT, |
| 56 | + HttpStatusBuilder.CONFLICT, |
| 57 | + HttpStatusBuilder.GONE, |
| 58 | + HttpStatusBuilder.LENGTH_REQUIRED, |
| 59 | + HttpStatusBuilder.PRECONDITION_FAILED, |
| 60 | + HttpStatusBuilder.REQUEST_ENTITY_TOO_LARGE, |
| 61 | + HttpStatusBuilder.REQUEST_URI_TOO_LONG, |
| 62 | + HttpStatusBuilder.UNSUPPORTED_MEDIA_TYPE, |
| 63 | + HttpStatusBuilder.REQUESTED_RANGE_NOT_SATISFIABLE, |
| 64 | + HttpStatusBuilder.EXPECTATION_FAILED, |
| 65 | + HttpStatusBuilder.IM_A_TEAPOT, |
| 66 | + HttpStatusBuilder.ENHANCE_YOUR_CALM, |
| 67 | + HttpStatusBuilder.UN_PROCESSABLE_ENTITY, |
| 68 | + HttpStatusBuilder.LOCKED, |
| 69 | + HttpStatusBuilder.FAILED_DEPENDENCY, |
| 70 | + HttpStatusBuilder.UNORDERED_COLLECTION, |
| 71 | + HttpStatusBuilder.UPGRADE_REQUIRED, |
| 72 | + HttpStatusBuilder.PRECONDITION_REQUIRED, |
| 73 | + HttpStatusBuilder.TOO_MANY_REQUESTS, |
| 74 | + HttpStatusBuilder.REQUEST_HEADER_FIELDS_TOO_LARGE, |
| 75 | + HttpStatusBuilder.NO_RESPONSE, |
| 76 | + HttpStatusBuilder.RETRY_WITH, |
| 77 | + HttpStatusBuilder.BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS, |
| 78 | + HttpStatusBuilder.UNAVAILABLE_FOR_LEGAL_REASONS, |
| 79 | + HttpStatusBuilder.CLIENT_CLOSED_REQUEST, |
| 80 | + HttpStatusBuilder.INTERNAL_SERVER_ERROR, |
| 81 | + HttpStatusBuilder.NOT_IMPLEMENTED, |
| 82 | + HttpStatusBuilder.BAD_GATEWAY, |
| 83 | + HttpStatusBuilder.SERVICE_UNAVAILABLE, |
| 84 | + HttpStatusBuilder.GATEWAY_TIMEOUT, |
| 85 | + HttpStatusBuilder.HTTP_VERSION_NOT_SUPPORTED, |
| 86 | + HttpStatusBuilder.VARIANT_ALSO_NEGOTIATES, |
| 87 | + HttpStatusBuilder.INSUFFICIENT_STORAGE, |
| 88 | + HttpStatusBuilder.LOOP_DETECTED, |
| 89 | + HttpStatusBuilder.BANDWIDTH_LIMIT_EXCEEDED, |
| 90 | + HttpStatusBuilder.NOT_EXTENDED, |
| 91 | + HttpStatusBuilder.NETWORK_AUTHENTICATION_REQUIRED, |
| 92 | + HttpStatusBuilder.NETWORK_READ_TIMEOUT_ERROR, |
| 93 | + HttpStatusBuilder.NETWORK_CONNECT_TIMEOUT_ERROR |
| 94 | + ); |
| 95 | + } |
92 | 96 | return statuses.stream().filter(e -> e.getCode() == statusCode).findFirst().orElse(new HttpResponse(-1, "unknown", "unknown", "out of HTTP status version")); |
93 | 97 | } |
94 | 98 |
|
|
0 commit comments