diff options
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java')
-rw-r--r-- | common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java new file mode 100644 index 0000000000..57911144a1 --- /dev/null +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java @@ -0,0 +1,136 @@ +package org.openecomp.sdc.common.http.client.api; + +import org.apache.http.HttpEntity; +import org.openecomp.sdc.common.http.config.HttpClientConfig; + +import java.util.Properties; + +//TODO- remove all static and use instance methods for better testing +public abstract class HttpRequest { + + static final Properties defaultHeaders = null; + static final HttpClientConfig defaultConfig = new HttpClientConfig(); + + + + private HttpRequest() { + } + + /* + * GET response as string + */ + public static HttpResponse<String> get(String url) throws HttpExecuteException { + return get(url, defaultHeaders, defaultConfig); + } + + public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException { + return get(url, headers, defaultConfig); + } + + public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException { + return get(url, defaultHeaders, config); + } + + public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().get(url, headers, config); + } + + /* + * GET response as byte array + */ + public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException { + return getAsByteArray(url, defaultHeaders, defaultConfig); + } + + public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException { + return getAsByteArray(url, headers, defaultConfig); + } + + public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException { + return getAsByteArray(url, defaultHeaders, config); + } + + public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().getAsByteArray(url, headers, config); + } + + /* + * PUT + */ + public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException { + return put(url, defaultHeaders, entity, defaultConfig); + } + + public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException { + return put(url, headers, entity, defaultConfig); + } + + public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return put(url, defaultHeaders, entity, config); + } + + public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().put(url, headers, entity, config); + } + + /* + * POST + */ + public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException { + return post(url, defaultHeaders, entity, defaultConfig); + } + + public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException { + return post(url, headers, entity, defaultConfig); + } + + public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return post(url, defaultHeaders, entity, config); + } + + public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().post(url, headers, entity, config); + } + + /* + * PATCH + */ + public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException { + return patch(url, defaultHeaders, entity, defaultConfig); + } + + public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException { + return patch(url, headers, entity, defaultConfig); + } + + public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return patch(url, defaultHeaders, entity, config); + } + + public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().patch(url, headers, entity, config); + } + + /* + * DELETE + */ + public static HttpResponse<String> delete(String url) throws HttpExecuteException { + return delete(url, defaultHeaders, defaultConfig); + } + + public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException { + return delete(url, headers, defaultConfig); + } + + public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException { + return delete(url, defaultHeaders, config); + } + + public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException { + return HttpRequestHandler.get().delete(url, headers, config); + } + + public static void destroy() { + HttpRequestHandler.get().destroy(); + } +} |