Added oparent to sdc main
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / http / client / api / HttpRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.common.http.client.api;
22
23 import org.apache.http.HttpEntity;
24 import org.openecomp.sdc.common.http.config.HttpClientConfig;
25
26 import java.util.Properties;
27
28 //TODO- remove all static and use instance methods for better testing
29 public abstract class HttpRequest {
30
31     static final  Properties defaultHeaders = null;
32     static final HttpClientConfig defaultConfig = new HttpClientConfig();
33
34
35
36     private HttpRequest() {
37     }
38
39     /*
40      * GET response as string
41      */
42     public static HttpResponse<String> get(String url) throws HttpExecuteException {
43         return get(url, defaultHeaders, defaultConfig);
44     }
45
46     public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
47         return get(url, headers, defaultConfig);
48     }
49     
50     public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
51         return get(url, defaultHeaders, config);
52     }
53
54     public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
55         return HttpRequestHandler.get().get(url, headers, config);
56     }
57
58     /*
59      * GET response as byte array
60      */
61     public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
62         return getAsByteArray(url, defaultHeaders, defaultConfig);
63     }
64
65     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
66         return getAsByteArray(url, headers, defaultConfig);
67     }
68
69     public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
70         return getAsByteArray(url, defaultHeaders, config);
71     }
72
73     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
74         return HttpRequestHandler.get().getAsByteArray(url, headers, config);
75     }
76
77     /*
78      * PUT
79      */
80     public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
81         return put(url, defaultHeaders, entity, defaultConfig);
82     }
83
84     public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
85         return put(url, headers, entity, defaultConfig);
86     }
87     
88     public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
89         return put(url, defaultHeaders, entity, config);
90     }
91
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);
94     }
95
96     /*
97      * POST
98      */
99     public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
100         return post(url, defaultHeaders, entity, defaultConfig);
101     }
102
103     public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
104         return post(url, headers, entity, defaultConfig);
105     }
106     
107     public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
108         return post(url, defaultHeaders, entity, config);
109     }
110
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);
113     }
114     
115     /*
116      * PATCH
117      */
118     public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
119         return patch(url, defaultHeaders, entity, defaultConfig);
120     }
121
122     public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
123         return patch(url, headers, entity, defaultConfig);
124     }
125     
126     public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
127         return patch(url, defaultHeaders, entity, config);
128     }
129
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);
132     }
133     
134     /*
135      * DELETE
136      */
137     public static HttpResponse<String> delete(String url) throws HttpExecuteException {
138         return delete(url, defaultHeaders, defaultConfig);
139     }
140
141     public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
142         return delete(url, headers, defaultConfig);
143     }
144     
145     public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
146         return delete(url, defaultHeaders, config);
147     }
148
149     public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
150         return HttpRequestHandler.get().delete(url, headers, config);
151     }
152     
153     public static void destroy() {
154         HttpRequestHandler.get().destroy();
155     }
156 }