Update license date and text
[aai/rest-client.git] / src / main / java / org / onap / aai / restclient / rest / HttpUtil.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017-2018 Amdocs\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 package org.onap.aai.restclient.rest;\r
22 \r
23 public class HttpUtil {\r
24 \r
25   /**\r
26    * Determines if the provided HTTP response is present in the provided list of acceptable response\r
27    * codes.\r
28    *\r
29    * @param response the http response we got from our request\r
30    * @param list the list of acceptable response codes\r
31    * @return true if the http response is in the provided list\r
32    */\r
33   public static boolean isHttpResponseInList(int response, int... list) {\r
34     for (int checkCode : list) {\r
35       if (checkCode == response) {\r
36         return true;\r
37       }\r
38     }\r
39     return false;\r
40   }\r
41 \r
42   /**\r
43    * Determines if the provided http response is of the information class.\r
44    *\r
45    * @param response the http response we got from our request\r
46    * @return true if the response is of the informational class and false otherwise\r
47    */\r
48   public static boolean isHttpResponseClassInformational(int response) {\r
49     return ( response >= 100 && response <= 199);\r
50   }\r
51 \r
52   /**\r
53    * Determines if the provided http response is of the success class.\r
54    *\r
55    * @param response the http response we got from our request\r
56    * @return true if the response is of the success class and false otherwise\r
57    */\r
58   public static boolean isHttpResponseClassSuccess(int response) {\r
59     return ( response >= 200 && response <= 299);\r
60 \r
61   }\r
62 \r
63   /**\r
64    * Determines if the provided http response is of the redirection class.\r
65    *\r
66    * @param response the http response we got from our request\r
67    * @return true if the response is of the redirection class and false otherwise\r
68    */\r
69   public static boolean isHttpResponseClassRedirection(int response) {\r
70     return ( response >= 300 && response <= 399);\r
71   }\r
72 \r
73   /**\r
74    * Determines if the provided http response is of the client error class.\r
75    *\r
76    * @param response the http response we got from our request\r
77    * @return true if the response is of the client error class and false otherwise\r
78    */\r
79   public static boolean isHttpResponseClassClientError(int response) {\r
80     return ( response >= 400 && response <= 499);\r
81   }\r
82 \r
83   /**\r
84    * Determines if the provided http response is of the server error class.\r
85    *\r
86    * @param response the http response we got from our request\r
87    * @return true if the response is of the server error class and false otherwise\r
88    */\r
89   public static boolean isHttpResponseClassServerError(int response) {\r
90     return ( response >= 500 && response <= 599);\r
91   }\r
92 \r
93 }\r