Renaming openecomp to onap
[aai/rest-client.git] / src / main / java / org / onap / aai / restclient / rest / HttpUtil.java
diff --git a/src/main/java/org/onap/aai/restclient/rest/HttpUtil.java b/src/main/java/org/onap/aai/restclient/rest/HttpUtil.java
new file mode 100644 (file)
index 0000000..0677a16
--- /dev/null
@@ -0,0 +1,95 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.restclient.rest;\r
+\r
+public class HttpUtil {\r
+\r
+  /**\r
+   * Determines if the provided HTTP response is present in the provided list of acceptable response\r
+   * codes.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @param list the list of acceptable response codes\r
+   * @return true if the http response is in the provided list\r
+   */\r
+  public static boolean isHttpResponseInList(int response, int... list) {\r
+    for (int checkCode : list) {\r
+      if (checkCode == response) {\r
+        return true;\r
+      }\r
+    }\r
+    return false;\r
+  }\r
+\r
+  /**\r
+   * Determines if the provided http response is of the information class.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @return true if the response is of the informational class and false otherwise\r
+   */\r
+  public static boolean isHttpResponseClassInformational(int response) {\r
+    return ( response >= 100 && response <= 199);\r
+  }\r
+\r
+  /**\r
+   * Determines if the provided http response is of the success class.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @return true if the response is of the success class and false otherwise\r
+   */\r
+  public static boolean isHttpResponseClassSuccess(int response) {\r
+    return ( response >= 200 && response <= 299);\r
+\r
+  }\r
+\r
+  /**\r
+   * Determines if the provided http response is of the redirection class.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @return true if the response is of the redirection class and false otherwise\r
+   */\r
+  public static boolean isHttpResponseClassRedirection(int response) {\r
+    return ( response >= 300 && response <= 399);\r
+  }\r
+\r
+  /**\r
+   * Determines if the provided http response is of the client error class.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @return true if the response is of the client error class and false otherwise\r
+   */\r
+  public static boolean isHttpResponseClassClientError(int response) {\r
+    return ( response >= 400 && response <= 499);\r
+  }\r
+\r
+  /**\r
+   * Determines if the provided http response is of the server error class.\r
+   *\r
+   * @param response the http response we got from our request\r
+   * @return true if the response is of the server error class and false otherwise\r
+   */\r
+  public static boolean isHttpResponseClassServerError(int response) {\r
+    return ( response >= 500 && response <= 599);\r
+  }\r
+\r
+}\r