2 * ============LICENSE_START=======================================================
\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
13 * http://www.apache.org/licenses/LICENSE-2.0
\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
22 * ECOMP and OpenECOMP are trademarks
\r
23 * and service marks of AT&T Intellectual Property.
\r
25 package org.openecomp.restclient.rest;
\r
27 public class HttpUtil {
\r
30 * Determines if the provided HTTP response is present in the provided list of acceptable response
\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
37 public static boolean isHttpResponseInList(int response, int... list) {
\r
38 for (int checkCode : list) {
\r
39 if (checkCode == response) {
\r
47 * Determines if the provided http response is of the information class.
\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
52 public static boolean isHttpResponseClassInformational(int response) {
\r
53 return isExpectedHttpResponseClass(response, '1');
\r
57 * Determines if the provided http response is of the success class.
\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
62 public static boolean isHttpResponseClassSuccess(int response) {
\r
63 return isExpectedHttpResponseClass(response, '2');
\r
67 * Determines if the provided http response is of the redirection class.
\r
69 * @param response the http response we got from our request
\r
70 * @return true if the response is of the redirection class and false otherwise
\r
72 public static boolean isHttpResponseClassRedirection(int response) {
\r
73 return isExpectedHttpResponseClass(response, '3');
\r
77 * Determines if the provided http response is of the client error class.
\r
79 * @param response the http response we got from our request
\r
80 * @return true if the response is of the client error class and false otherwise
\r
82 public static boolean isHttpResponseClassClientError(int response) {
\r
83 return isExpectedHttpResponseClass(response, '4');
\r
87 * Determines if the provided http response is of the server error class.
\r
89 * @param response the http response we got from our request
\r
90 * @return true if the response is of the server error class and false otherwise
\r
92 public static boolean isHttpResponseClassServerError(int response) {
\r
93 return isExpectedHttpResponseClass(response, '5');
\r
97 * Helper method to determine if we have received the response class we are expecting.
\r
99 * @param response the http response we got from our request
\r
100 * @param expectedClass the expected http response class ie: 1, 2, 3, 4, 5 which maps to 1xx, 2xx,
\r
101 * 3xx, 4xx, 5xx respectively
\r
102 * @return true if the response if of our expected class and false if not
\r
104 private static boolean isExpectedHttpResponseClass(int response, char expectedClass) {
\r
105 if (response < 100 || response >= 600) {
\r
109 if (Integer.toString(response).charAt(0) == expectedClass) {
\r