Changing the license and trademark
[aai/rest-client.git] / src / main / java / org / openecomp / restclient / rest / HttpUtil.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  */\r
23 package org.openecomp.restclient.rest;\r
24 \r
25 public class HttpUtil {\r
26 \r
27   /**\r
28    * Determines if the provided HTTP response is present in the provided list of acceptable response\r
29    * codes.\r
30    *\r
31    * @param response the http response we got from our request\r
32    * @param list the list of acceptable response codes\r
33    * @return true if the http response is in the provided list\r
34    */\r
35   public static boolean isHttpResponseInList(int response, int... list) {\r
36     for (int checkCode : list) {\r
37       if (checkCode == response) {\r
38         return true;\r
39       }\r
40     }\r
41     return false;\r
42   }\r
43 \r
44   /**\r
45    * Determines if the provided http response is of the information class.\r
46    *\r
47    * @param response the http response we got from our request\r
48    * @return true if the response is of the informational class and false otherwise\r
49    */\r
50   public static boolean isHttpResponseClassInformational(int response) {\r
51     return ( response >= 100 && response <= 199);\r
52   }\r
53 \r
54   /**\r
55    * Determines if the provided http response is of the success class.\r
56    *\r
57    * @param response the http response we got from our request\r
58    * @return true if the response is of the success class and false otherwise\r
59    */\r
60   public static boolean isHttpResponseClassSuccess(int response) {\r
61     return ( response >= 200 && response <= 299);\r
62 \r
63   }\r
64 \r
65   /**\r
66    * Determines if the provided http response is of the redirection class.\r
67    *\r
68    * @param response the http response we got from our request\r
69    * @return true if the response is of the redirection class and false otherwise\r
70    */\r
71   public static boolean isHttpResponseClassRedirection(int response) {\r
72     return ( response >= 300 && response <= 399);\r
73   }\r
74 \r
75   /**\r
76    * Determines if the provided http response is of the client error class.\r
77    *\r
78    * @param response the http response we got from our request\r
79    * @return true if the response is of the client error class and false otherwise\r
80    */\r
81   public static boolean isHttpResponseClassClientError(int response) {\r
82     return ( response >= 400 && response <= 499);\r
83   }\r
84 \r
85   /**\r
86    * Determines if the provided http response is of the server error class.\r
87    *\r
88    * @param response the http response we got from our request\r
89    * @return true if the response is of the server error class and false otherwise\r
90    */\r
91   public static boolean isHttpResponseClassServerError(int response) {\r
92     return ( response >= 500 && response <= 599);\r
93   }\r
94 \r
95 }\r