1 package org.openecomp.sdc.common.http.client.api;
3 import org.apache.http.HttpEntity;
4 import org.openecomp.sdc.common.http.config.HttpClientConfig;
6 import java.util.Properties;
8 //TODO- remove all static and use instance methods for better testing
9 public abstract class HttpRequest {
11 static final Properties defaultHeaders = null;
12 static final HttpClientConfig defaultConfig = new HttpClientConfig();
16 private HttpRequest() {
20 * GET response as string
22 public static HttpResponse<String> get(String url) throws HttpExecuteException {
23 return get(url, defaultHeaders, defaultConfig);
26 public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
27 return get(url, headers, defaultConfig);
30 public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
31 return get(url, defaultHeaders, config);
34 public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
35 return HttpRequestHandler.get().get(url, headers, config);
39 * GET response as byte array
41 public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
42 return getAsByteArray(url, defaultHeaders, defaultConfig);
45 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
46 return getAsByteArray(url, headers, defaultConfig);
49 public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
50 return getAsByteArray(url, defaultHeaders, config);
53 public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
54 return HttpRequestHandler.get().getAsByteArray(url, headers, config);
60 public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
61 return put(url, defaultHeaders, entity, defaultConfig);
64 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
65 return put(url, headers, entity, defaultConfig);
68 public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
69 return put(url, defaultHeaders, entity, config);
72 public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
73 return HttpRequestHandler.get().put(url, headers, entity, config);
79 public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
80 return post(url, defaultHeaders, entity, defaultConfig);
83 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
84 return post(url, headers, entity, defaultConfig);
87 public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
88 return post(url, defaultHeaders, entity, config);
91 public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
92 return HttpRequestHandler.get().post(url, headers, entity, config);
98 public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
99 return patch(url, defaultHeaders, entity, defaultConfig);
102 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
103 return patch(url, headers, entity, defaultConfig);
106 public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
107 return patch(url, defaultHeaders, entity, config);
110 public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
111 return HttpRequestHandler.get().patch(url, headers, entity, config);
117 public static HttpResponse<String> delete(String url) throws HttpExecuteException {
118 return delete(url, defaultHeaders, defaultConfig);
121 public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
122 return delete(url, headers, defaultConfig);
125 public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
126 return delete(url, defaultHeaders, config);
129 public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
130 return HttpRequestHandler.get().delete(url, headers, config);
133 public static void destroy() {
134 HttpRequestHandler.get().destroy();