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 static final Properties defaultHeaders = null;
32 static final HttpClientConfig defaultConfig = new HttpClientConfig();
36 private HttpRequest() {
40 * GET response as string
42 public static HttpResponse<String> get(String url) throws HttpExecuteException {
43 return get(url, defaultHeaders, defaultConfig);
46 public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
47 return get(url, headers, defaultConfig);
50 public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
51 return get(url, defaultHeaders, config);
54 public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
55 return HttpRequestHandler.get().get(url, headers, config);
59 * GET response as byte array
61 public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
62 return getAsByteArray(url, defaultHeaders, defaultConfig);
65 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
66 return getAsByteArray(url, headers, defaultConfig);
69 public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
70 return getAsByteArray(url, defaultHeaders, config);
73 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
74 return HttpRequestHandler.get().getAsByteArray(url, headers, config);
80 public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
81 return put(url, defaultHeaders, entity, defaultConfig);
84 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
85 return put(url, headers, entity, defaultConfig);
88 public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
89 return put(url, defaultHeaders, entity, config);
92 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
93 return HttpRequestHandler.get().put(url, headers, entity, config);
99 public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
100 return post(url, defaultHeaders, entity, defaultConfig);
103 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
104 return post(url, headers, entity, defaultConfig);
107 public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
108 return post(url, defaultHeaders, entity, config);
111 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
112 return HttpRequestHandler.get().post(url, headers, entity, config);
118 public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
119 return patch(url, defaultHeaders, entity, defaultConfig);
122 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
123 return patch(url, headers, entity, defaultConfig);
126 public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
127 return patch(url, defaultHeaders, entity, config);
130 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
131 return HttpRequestHandler.get().patch(url, headers, entity, config);
137 public static HttpResponse<String> delete(String url) throws HttpExecuteException {
138 return delete(url, defaultHeaders, defaultConfig);
141 public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
142 return delete(url, headers, defaultConfig);
145 public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
146 return delete(url, defaultHeaders, config);
149 public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
150 return HttpRequestHandler.get().delete(url, headers, config);
153 public static void destroy() {
154 HttpRequestHandler.get().destroy();