2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.http.client.api;
23 import org.apache.http.HttpEntity;
24 import org.openecomp.sdc.common.http.config.HttpClientConfig;
26 import java.util.Properties;
28 //TODO- remove all static and use instance methods for better testing
29 public abstract class HttpRequest {
31 private static final Properties DEFAULT_HEADERS = null;
32 private static final HttpClientConfig DEFAULT_CONFIG = new HttpClientConfig();
35 private HttpRequest() {
38 public static Properties getDefaultHeaders() {
39 return DEFAULT_HEADERS;
42 public static HttpClientConfig getDefaultConfig() {
43 return DEFAULT_CONFIG;
47 * GET response as string
49 public static HttpResponse<String> get(String url) throws HttpExecuteException {
50 return get(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
53 public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
54 return get(url, headers, DEFAULT_CONFIG);
57 public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
58 return get(url, DEFAULT_HEADERS, config);
61 public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
62 return HttpRequestHandler.get().get(url, headers, config);
66 * GET response as byte array
68 public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
69 return getAsByteArray(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
72 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
73 return getAsByteArray(url, headers, DEFAULT_CONFIG);
76 public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
77 return getAsByteArray(url, DEFAULT_HEADERS, config);
80 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
81 return HttpRequestHandler.get().getAsByteArray(url, headers, config);
87 public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
88 return put(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
91 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
92 return put(url, headers, entity, DEFAULT_CONFIG);
95 public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
96 return put(url, DEFAULT_HEADERS, entity, config);
99 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
100 return HttpRequestHandler.get().put(url, headers, entity, config);
106 public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
107 return post(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
110 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
111 return post(url, headers, entity, DEFAULT_CONFIG);
114 public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
115 return post(url, DEFAULT_HEADERS, entity, config);
118 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
119 return HttpRequestHandler.get().post(url, headers, entity, config);
125 public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
126 return patch(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
129 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
130 return patch(url, headers, entity, DEFAULT_CONFIG);
133 public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
134 return patch(url, DEFAULT_HEADERS, entity, config);
137 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
138 return HttpRequestHandler.get().patch(url, headers, entity, config);
144 public static HttpResponse<String> delete(String url) throws HttpExecuteException {
145 return delete(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
148 public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
149 return delete(url, headers, DEFAULT_CONFIG);
152 public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
153 return delete(url, DEFAULT_HEADERS, config);
156 public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
157 return HttpRequestHandler.get().delete(url, headers, config);
160 public static void destroy() {
161 HttpRequestHandler.get().destroy();