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