fixing warnings from checkstyle in common-app-api
[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     private static final Properties DEFAULT_HEADERS = null;
32     private static final HttpClientConfig DEFAULT_CONFIG = new HttpClientConfig();
33
34
35     private HttpRequest() {
36     }
37
38     public static Properties getDefaultHeaders() {
39         return DEFAULT_HEADERS;
40     }
41
42     public static HttpClientConfig getDefaultConfig() {
43         return DEFAULT_CONFIG;
44     }
45
46     /*
47      * GET response as string
48      */
49     public static HttpResponse<String> get(String url) throws HttpExecuteException {
50         return get(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
51     }
52
53     public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
54         return get(url, headers, DEFAULT_CONFIG);
55     }
56
57     public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
58         return get(url, DEFAULT_HEADERS, config);
59     }
60
61     public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
62         return HttpRequestHandler.get().get(url, headers, config);
63     }
64
65     /*
66      * GET response as byte array
67      */
68     public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
69         return getAsByteArray(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
70     }
71
72     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
73         return getAsByteArray(url, headers, DEFAULT_CONFIG);
74     }
75
76     public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
77         return getAsByteArray(url, DEFAULT_HEADERS, config);
78     }
79
80     public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
81         return HttpRequestHandler.get().getAsByteArray(url, headers, config);
82     }
83
84     /*
85      * PUT
86      */
87     public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
88         return put(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
89     }
90
91     public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
92         return put(url, headers, entity, DEFAULT_CONFIG);
93     }
94
95     public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
96         return put(url, DEFAULT_HEADERS, entity, config);
97     }
98
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);
101     }
102
103     /*
104      * POST
105      */
106     public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
107         return post(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
108     }
109
110     public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
111         return post(url, headers, entity, DEFAULT_CONFIG);
112     }
113
114     public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
115         return post(url, DEFAULT_HEADERS, entity, config);
116     }
117
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);
120     }
121
122     /*
123      * PATCH
124      */
125     public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
126         return patch(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
127     }
128
129     public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
130         return patch(url, headers, entity, DEFAULT_CONFIG);
131     }
132
133     public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
134         return patch(url, DEFAULT_HEADERS, entity, config);
135     }
136
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);
139     }
140
141     /*
142      * DELETE
143      */
144     public static HttpResponse<String> delete(String url) throws HttpExecuteException {
145         return delete(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
146     }
147
148     public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
149         return delete(url, headers, DEFAULT_CONFIG);
150     }
151
152     public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
153         return delete(url, DEFAULT_HEADERS, config);
154     }
155
156     public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
157         return HttpRequestHandler.get().delete(url, headers, config);
158     }
159
160     public static void destroy() {
161         HttpRequestHandler.get().destroy();
162     }
163 }