- private static HttpPost getHttpPost(String url, Map<String, String> header,
- Map<String, String> param, HttpEntity entity) {
- HttpPost httpPost = new HttpPost(url);
- if (!header.isEmpty()) {
- for (Map.Entry<String, String> entry : header.entrySet()) {
- httpPost.addHeader(entry.getKey(), entry.getValue());
- }
+ public static HttpResponse get(String url, Map<String, String> header) throws CorrelationException {
+ return get(url, header, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse get(String url, Map<String, String> header, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpGet httpGet = new HttpGet(url);
+ try {
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpGet);
+ response = executeRequest(httpClient, httpGet);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to query data from server through GET method!");
+ }
+ return response;
+ }
+
+ public static HttpResponse delete(String url, Map<String, String> header) throws CorrelationException {
+ return delete(url, header, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse delete(String url, Map<String, String> header, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpDelete httpDelete = new HttpDelete(url);
+ try {
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpDelete);
+ response = executeRequest(httpClient, httpDelete);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to query data from server through DELETE method!");