Sync Integ to Master
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / http / client / api / HttpRequest.java
1 package org.openecomp.sdc.common.http.client.api;
2
3 import org.apache.http.HttpEntity;
4 import org.openecomp.sdc.common.http.config.HttpClientConfig;
5
6 import java.util.Properties;
7
8 //TODO- remove all static and use instance methods for better testing
9 public abstract class HttpRequest {
10
11     static final  Properties defaultHeaders = null;
12     static final HttpClientConfig defaultConfig = new HttpClientConfig();
13
14
15
16     private HttpRequest() {
17     }
18
19     /*
20      * GET response as string
21      */
22     public static HttpResponse<String> get(String url) throws HttpExecuteException {
23         return get(url, defaultHeaders, defaultConfig);
24     }
25
26     public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
27         return get(url, headers, defaultConfig);
28     }
29     
30     public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
31         return get(url, defaultHeaders, config);
32     }
33
34     public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
35         return HttpRequestHandler.get().get(url, headers, config);
36     }
37
38     /*
39      * GET response as byte array
40      */
41     public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
42         return getAsByteArray(url, defaultHeaders, defaultConfig);
43     }
44
45     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
46         return getAsByteArray(url, headers, defaultConfig);
47     }
48
49     public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
50         return getAsByteArray(url, defaultHeaders, config);
51     }
52
53     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
54         return HttpRequestHandler.get().getAsByteArray(url, headers, config);
55     }
56
57     /*
58      * PUT
59      */
60     public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
61         return put(url, defaultHeaders, entity, defaultConfig);
62     }
63
64     public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
65         return put(url, headers, entity, defaultConfig);
66     }
67     
68     public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
69         return put(url, defaultHeaders, entity, config);
70     }
71
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);
74     }
75
76     /*
77      * POST
78      */
79     public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
80         return post(url, defaultHeaders, entity, defaultConfig);
81     }
82
83     public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
84         return post(url, headers, entity, defaultConfig);
85     }
86     
87     public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
88         return post(url, defaultHeaders, entity, config);
89     }
90
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);
93     }
94     
95     /*
96      * PATCH
97      */
98     public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
99         return patch(url, defaultHeaders, entity, defaultConfig);
100     }
101
102     public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
103         return patch(url, headers, entity, defaultConfig);
104     }
105     
106     public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
107         return patch(url, defaultHeaders, entity, config);
108     }
109
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);
112     }
113     
114     /*
115      * DELETE
116      */
117     public static HttpResponse<String> delete(String url) throws HttpExecuteException {
118         return delete(url, defaultHeaders, defaultConfig);
119     }
120
121     public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
122         return delete(url, headers, defaultConfig);
123     }
124     
125     public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
126         return delete(url, defaultHeaders, config);
127     }
128
129     public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
130         return HttpRequestHandler.get().delete(url, headers, config);
131     }
132     
133     public static void destroy() {
134         HttpRequestHandler.get().destroy();
135     }
136 }