summaryrefslogtreecommitdiffstats
path: root/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java
blob: 57911144a139154086f162356512b7b6c5376263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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();
    }
}