Subversion Repositories SmartDukaan

Rev

Rev 36416 | Rev 37388 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21557 ashik.ali 1
package com.spice.profitmandi.common.web.client;
2
 
30289 amit.gupta 3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.spice.profitmandi.common.ResponseCodeHolder;
5
import com.spice.profitmandi.common.enumuration.SchemeType;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
7
import com.spice.profitmandi.common.model.MandiiResponse;
21557 ashik.ali 8
import org.apache.http.HttpResponse;
22215 ashik.ali 9
import org.apache.http.NameValuePair;
21557 ashik.ali 10
import org.apache.http.client.ClientProtocolException;
11
import org.apache.http.client.HttpClient;
25244 amit.gupta 12
import org.apache.http.client.config.RequestConfig;
22215 ashik.ali 13
import org.apache.http.client.entity.UrlEncodedFormEntity;
34805 ranu 14
import org.apache.http.client.methods.*;
23502 ashik.ali 15
import org.apache.http.conn.HttpHostConnectException;
16
import org.apache.http.entity.ContentType;
17
import org.apache.http.entity.StringEntity;
34805 ranu 18
import org.apache.http.impl.client.CloseableHttpClient;
25244 amit.gupta 19
import org.apache.http.impl.client.HttpClientBuilder;
21557 ashik.ali 20
import org.apache.http.impl.client.HttpClients;
30383 amit.gupta 21
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
22215 ashik.ali 22
import org.apache.http.message.BasicNameValuePair;
34805 ranu 23
import org.apache.http.util.EntityUtils;
25011 amit.gupta 24
import org.apache.logging.log4j.LogManager;
23568 govind 25
import org.apache.logging.log4j.Logger;
25726 amit.gupta 26
import org.springframework.beans.factory.annotation.Autowired;
21557 ashik.ali 27
import org.springframework.http.HttpStatus;
23526 ashik.ali 28
import org.springframework.stereotype.Component;
21557 ashik.ali 29
import org.springframework.web.util.UriComponentsBuilder;
30
 
30289 amit.gupta 31
import java.io.*;
32
import java.util.ArrayList;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.Set;
21557 ashik.ali 36
 
23526 ashik.ali 37
@Component
21557 ashik.ali 38
public class RestClient {
25011 amit.gupta 39
 
31828 amit.gupta 40
    private static final Logger LOGGER = LogManager.getLogger(RestClient.class);
25011 amit.gupta 41
 
31828 amit.gupta 42
    private HttpClient httpClient;
25011 amit.gupta 43
 
30289 amit.gupta 44
 
31828 amit.gupta 45
    @Autowired
46
    ObjectMapper objectMapper;
25726 amit.gupta 47
 
31828 amit.gupta 48
    public RestClient() {
49
        PoolingHttpClientConnectionManager connManager
50
                = new PoolingHttpClientConnectionManager();
36416 amit 51
        connManager.setMaxTotal(20);
52
        connManager.setDefaultMaxPerRoute(8);
31828 amit.gupta 53
        httpClient = HttpClients.custom().disableCookieManagement().disableAuthCaching().disableConnectionState().
36416 amit 54
                disableAuthCaching().setConnectionManager(connManager)
55
                .setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig())
56
                .build();
25244 amit.gupta 57
 
31828 amit.gupta 58
    }
25011 amit.gupta 59
 
31828 amit.gupta 60
    public RestClient(int connectionTimeoutMillis) {
36416 amit 61
        this.httpClient = HttpClientBuilder.create().disableCookieManagement()
62
                .setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig()).build();
25244 amit.gupta 63
 
31828 amit.gupta 64
    }
25244 amit.gupta 65
 
37321 amit 66
    /**
67
     * RestClient on a caller-supplied timeout profile from {@link HttpClientFactory}. Not a
68
     * Spring bean — construct it explicitly where a non-default timeout is justified, and pass
69
     * the ObjectMapper in, since field injection does not apply to hand-built instances.
70
     */
71
    public RestClient(RequestConfig requestConfig, ObjectMapper objectMapper) {
72
        PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
73
        connManager.setMaxTotal(20);
74
        connManager.setDefaultMaxPerRoute(8);
75
        this.httpClient = HttpClients.custom().disableCookieManagement().disableAuthCaching()
76
                .disableConnectionState().setConnectionManager(connManager)
77
                .setDefaultRequestConfig(requestConfig)
78
                .build();
79
        this.objectMapper = objectMapper;
80
    }
81
 
31828 amit.gupta 82
    public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
83
                      Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
84
        String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
85
                : scheme.getValue() + hostName + ":" + port + "/" + uri;
86
        return this.get(url, params, headers);
87
    }
25011 amit.gupta 88
 
31828 amit.gupta 89
    public String get(String url, Map<String, String> params, Map<String, String> headers)
90
            throws ProfitMandiBusinessException, HttpHostConnectException {
91
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
92
        if (params != null) {
93
            Set<String> keys = params.keySet();
94
            for (String key : keys) {
95
                builder.queryParam(key, params.get(key));
96
            }
97
        }
98
        HttpGet request = new HttpGet(builder.build().encode().toUri());
99
        if (headers != null) {
100
            for (Map.Entry<String, String> entry : headers.entrySet()) {
101
                request.setHeader(entry.getKey(), entry.getValue());
102
            }
103
        }
104
        return this.execute(request);
105
    }
22233 amit.gupta 106
 
31828 amit.gupta 107
    public MandiiResponse getMandii(String url, Map<String, String> params, Map<String, String> headers)
108
            throws ProfitMandiBusinessException, HttpHostConnectException {
109
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
110
        if (params != null) {
111
            Set<String> keys = params.keySet();
112
            for (String key : keys) {
113
                builder.queryParam(key, params.get(key));
114
            }
115
        }
116
        HttpGet request = new HttpGet(builder.build().encode().toUri());
117
        for (Map.Entry<String, String> entry : headers.entrySet()) {
118
            request.setHeader(entry.getKey(), entry.getValue());
119
        }
120
        return this.executeMandii(request);
121
    }
29834 tejbeer 122
 
31828 amit.gupta 123
    public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params)
124
            throws ProfitMandiBusinessException, HttpHostConnectException {
125
        String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
126
                : scheme.getValue() + hostName + ":" + port + "/" + uri;
127
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
128
        if (params != null) {
129
            Set<String> keys = params.keySet();
130
            for (String key : keys) {
131
                builder.queryParam(key, params.get(key));
132
            }
133
        }
134
        HttpGet request = new HttpGet(builder.build().encode().toUri());
135
        return this.execute(request);
136
    }
25011 amit.gupta 137
 
31828 amit.gupta 138
    public HttpResponse getResponse(String url, Map<String, String> params, Map<String, String> headers)
139
            throws ProfitMandiBusinessException, HttpHostConnectException {
140
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
141
        if (params != null) {
142
            for (Map.Entry<String, String> paramsEntry : params.entrySet()) {
143
                builder.queryParam(paramsEntry.getKey(), paramsEntry.getValue());
144
            }
30289 amit.gupta 145
 
31828 amit.gupta 146
        }
147
        HttpGet request = new HttpGet(builder.build().encode().toUri());
148
        if (headers != null) {
149
            for (Map.Entry<String, String> entry : headers.entrySet()) {
150
                request.setHeader(entry.getKey(), entry.getValue());
151
            }
152
        }
153
        try {
154
            LOGGER.info("Request uri is  {}", request.getURI().toString());
155
            HttpResponse response = httpClient.execute(request);
156
            LOGGER.info("Got response from server with responseCode {}", response.getStatusLine().getStatusCode());
157
            if (response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {
158
                return response;
159
            } else {
160
                throw new ProfitMandiBusinessException("", "", "GE_1005");
161
            }
162
        } catch (HttpHostConnectException httpHostConnectException) {
163
            LOGGER.error("Connection Timeout Exception", httpHostConnectException);
164
            throw httpHostConnectException;
165
        } catch (ClientProtocolException e) {
166
            LOGGER.error("Client Error : ", e);
37321 amit 167
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
31828 amit.gupta 168
        } catch (IOException e) {
169
            LOGGER.error("IO Error : ", e);
37321 amit 170
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
31828 amit.gupta 171
        }
172
    }
25011 amit.gupta 173
 
31828 amit.gupta 174
    public String execute(HttpUriRequest request) throws ProfitMandiBusinessException, HttpHostConnectException {
175
        LOGGER.info("Connecting to server at url {}", request.getURI());
36295 amit 176
        HttpResponse response = null;
31828 amit.gupta 177
        try {
36295 amit 178
            response = httpClient.execute(request);
31828 amit.gupta 179
            String responseString = this.toString(response.getEntity().getContent());
180
            LOGGER.info("Got response from server with responseCode {}", response.getStatusLine().getStatusCode());
181
            LOGGER.info("Response String {}", responseString);
34877 ranu 182
            if (response.getStatusLine().getStatusCode() == HttpStatus.OK.value()  || response.getStatusLine().getStatusCode() == HttpStatus.CREATED.value() || response.getStatusLine().getStatusCode() == HttpStatus.ACCEPTED.value()) {
31828 amit.gupta 183
                return responseString;
184
            } else {
185
                LOGGER.info("Response String {} ", responseString);
186
                throw new ProfitMandiBusinessException("", "", "GE_1005");
187
            }
188
        } catch (HttpHostConnectException httpHostConnectException) {
189
            LOGGER.error("Connection Timeout Exception", httpHostConnectException);
190
            throw httpHostConnectException;
191
        } catch (ClientProtocolException e) {
192
            LOGGER.error("Client Error : ", e);
37321 amit 193
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
31828 amit.gupta 194
        } catch (IOException e) {
195
            LOGGER.error("IO Error : ", e);
37321 amit 196
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
36295 amit 197
        } finally {
198
            if (response != null) EntityUtils.consumeQuietly(response.getEntity());
31828 amit.gupta 199
        }
200
    }
25011 amit.gupta 201
 
31828 amit.gupta 202
    public MandiiResponse executeMandii(HttpUriRequest request)
203
            throws ProfitMandiBusinessException, HttpHostConnectException {
204
        LOGGER.info("Connecting to server at url {}", request.getURI());
36295 amit 205
        HttpResponse response = null;
31828 amit.gupta 206
        try {
36295 amit 207
            response = httpClient.execute(request);
31828 amit.gupta 208
            String responseString = this.toString(response.getEntity().getContent());
209
            LOGGER.info("Got response from server with responseCode {}", response.getStatusLine().getStatusCode());
29834 tejbeer 210
 
31828 amit.gupta 211
            MandiiResponse mandiiResponse = new MandiiResponse();
212
            mandiiResponse.setResponseString(responseString);
213
            mandiiResponse.setStatusCode(response.getStatusLine().getStatusCode());
29834 tejbeer 214
 
31828 amit.gupta 215
            return mandiiResponse;
216
        } catch (HttpHostConnectException httpHostConnectException) {
217
            LOGGER.error("Connection Timeout Exception", httpHostConnectException);
218
            throw httpHostConnectException;
219
        } catch (ClientProtocolException e) {
220
            LOGGER.error("Client Error : ", e);
37321 amit 221
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
31828 amit.gupta 222
        } catch (IOException e) {
223
            LOGGER.error("IO Error : ", e);
37321 amit 224
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
36295 amit 225
        } finally {
226
            if (response != null) EntityUtils.consumeQuietly(response.getEntity());
31828 amit.gupta 227
        }
228
    }
29834 tejbeer 229
 
31828 amit.gupta 230
    public String executeJson(HttpUriRequest request) throws ProfitMandiBusinessException, HttpHostConnectException {
231
        LOGGER.info("Connecting to server at url {}", request.getURI());
36295 amit 232
        HttpResponse response = null;
31828 amit.gupta 233
        try {
36295 amit 234
            response = httpClient.execute(request);
31828 amit.gupta 235
            String responseString = this.toString(response.getEntity().getContent());
236
            LOGGER.info("Got response from server with responseCode {}", response.getStatusLine().getStatusCode());
237
            LOGGER.info("Response String {}", responseString);
238
            return responseString;
239
        } catch (HttpHostConnectException httpHostConnectException) {
240
            LOGGER.error("Connection Timeout Exception", httpHostConnectException);
241
            throw httpHostConnectException;
242
        } catch (ClientProtocolException e) {
243
            LOGGER.error("Client Error : ", e);
37321 amit 244
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
31828 amit.gupta 245
        } catch (IOException e) {
246
            LOGGER.error("IO Error : ", e);
37321 amit 247
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
36295 amit 248
        } finally {
249
            if (response != null) EntityUtils.consumeQuietly(response.getEntity());
31828 amit.gupta 250
        }
251
    }
27179 amit.gupta 252
 
35623 amit 253
    public HttpResponse postResponse(String url, Map<String, String> params, Map<String, String> headers)
254
            throws ProfitMandiBusinessException, HttpHostConnectException {
255
        List<NameValuePair> bodyParameters = new ArrayList<>();
256
        if (params != null) {
257
            for (Map.Entry<String, String> entry : params.entrySet()) {
258
                bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
259
            }
260
        }
261
        HttpPost request = new HttpPost(url);
262
        if (headers != null) {
263
            for (Map.Entry<String, String> entry : headers.entrySet()) {
264
                request.setHeader(entry.getKey(), entry.getValue());
265
            }
266
        }
267
        try {
268
            request.setEntity(new UrlEncodedFormEntity(bodyParameters));
269
            LOGGER.info("Request uri is  {}", request.getURI().toString());
270
            HttpResponse response = httpClient.execute(request);
271
            LOGGER.info("Got response from server with responseCode {}", response.getStatusLine().getStatusCode());
272
            if (response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {
273
                return response;
274
            } else {
275
                throw new ProfitMandiBusinessException("", "", "GE_1005");
276
            }
277
        } catch (HttpHostConnectException httpHostConnectException) {
278
            LOGGER.error("Connection Timeout Exception", httpHostConnectException);
279
            throw httpHostConnectException;
280
        } catch (ClientProtocolException e) {
281
            LOGGER.error("Client Error : ", e);
37321 amit 282
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
35623 amit 283
        } catch (IOException e) {
284
            LOGGER.error("IO Error : ", e);
37321 amit 285
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
35623 amit 286
        }
287
    }
288
 
31828 amit.gupta 289
    public String post(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
290
                       Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
291
        String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
292
                : scheme.getValue() + hostName + ":" + port + "/" + uri;
293
        return this.post(url, params, headers);
294
    }
25011 amit.gupta 295
 
31828 amit.gupta 296
    public String post(String url, Map<String, String> params, Map<String, String> headers)
297
            throws ProfitMandiBusinessException, HttpHostConnectException {
298
        // UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
299
        List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
300
        for (Map.Entry<String, String> entry : params.entrySet()) {
301
            bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
302
        }
25011 amit.gupta 303
 
31828 amit.gupta 304
        LOGGER.info("Body Parameters {}", params);
305
        HttpPost request = new HttpPost(url);
306
        for (Map.Entry<String, String> entry : headers.entrySet()) {
307
            request.setHeader(entry.getKey(), entry.getValue());
308
        }
25011 amit.gupta 309
 
31828 amit.gupta 310
        try {
311
            request.setEntity(new UrlEncodedFormEntity(bodyParameters));
312
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
313
            LOGGER.error("Encoding error : ", unsupportedEncodingException);
314
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
315
        }
25011 amit.gupta 316
 
31828 amit.gupta 317
        return this.execute(request);
25011 amit.gupta 318
 
31828 amit.gupta 319
    }
25011 amit.gupta 320
 
31828 amit.gupta 321
    public String post(String url, Map<String, String> queryParams, Map<String, String> postParams, Map<String, String> headers)
322
            throws ProfitMandiBusinessException, HttpHostConnectException {
323
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
324
        if (queryParams != null) {
325
            Set<String> keys = queryParams.keySet();
326
            for (String key : keys) {
327
                builder.queryParam(key, queryParams.get(key));
328
            }
329
        }
330
        List<NameValuePair> bodyParameters = new ArrayList<>();
331
        for (Map.Entry<String, String> entry : postParams.entrySet()) {
332
            bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
333
        }
28653 amit.gupta 334
 
31828 amit.gupta 335
        HttpPost request = new HttpPost(builder.build().encode().toUri());
336
        for (Map.Entry<String, String> entry : headers.entrySet()) {
337
            request.setHeader(entry.getKey(), entry.getValue());
338
        }
28653 amit.gupta 339
 
31828 amit.gupta 340
        try {
341
            request.setEntity(new UrlEncodedFormEntity(bodyParameters));
342
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
343
            LOGGER.error("Encoding error : ", unsupportedEncodingException);
344
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
345
        }
28653 amit.gupta 346
 
31828 amit.gupta 347
        return this.execute(request);
28653 amit.gupta 348
 
31828 amit.gupta 349
    }
25011 amit.gupta 350
 
31828 amit.gupta 351
    public String post(String url, String body, Map<String, String> headers)
352
            throws ProfitMandiBusinessException, HttpHostConnectException {
353
        HttpPost request = new HttpPost(url);
354
        for (Map.Entry<String, String> entry : headers.entrySet()) {
355
            request.setHeader(entry.getKey(), entry.getValue());
356
        }
25726 amit.gupta 357
 
31828 amit.gupta 358
        try {
359
            request.setEntity(new StringEntity(body));
360
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
361
            LOGGER.error("Encoding error : ", unsupportedEncodingException);
362
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
363
        }
29834 tejbeer 364
 
31828 amit.gupta 365
        return this.execute(request);
29834 tejbeer 366
 
31828 amit.gupta 367
    }
29834 tejbeer 368
 
31828 amit.gupta 369
    public String postJson(String url, Object object, Map<String, String> headers)
370
            throws ProfitMandiBusinessException, HttpHostConnectException {
371
        String jsonString;
372
        try {
373
            if (object.getClass().equals(String.class)) {
374
                jsonString = (String) object;
375
            } else {
376
                jsonString = objectMapper.writeValueAsString(object);
377
            }
378
            LOGGER.info("JSON String - {}", jsonString);
379
        } catch (Exception e) {
380
            e.printStackTrace();
381
            throw new ProfitMandiBusinessException("Json Object", object.toString(), "Could not write as String");
382
        }
383
        StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
25011 amit.gupta 384
 
31828 amit.gupta 385
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
27179 amit.gupta 386
 
31828 amit.gupta 387
        HttpPost request = new HttpPost(builder.build().encode().toUri());
388
        for (Map.Entry<String, String> entry : headers.entrySet()) {
389
            request.setHeader(entry.getKey(), entry.getValue());
390
        }
391
        request.setEntity(requestEntity);
392
        return this.executeJson(request);
393
    }
394
 
36200 ranu 395
    public MandiiResponse postWithResponse(String url, String body, Map<String, String> headers)
396
            throws ProfitMandiBusinessException, HttpHostConnectException {
397
        HttpPost request = new HttpPost(url);
398
        for (Map.Entry<String, String> entry : headers.entrySet()) {
399
            request.setHeader(entry.getKey(), entry.getValue());
400
        }
401
        try {
402
            request.setEntity(new StringEntity(body));
403
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
404
            LOGGER.error("Encoding error : ", unsupportedEncodingException);
405
            throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
406
        }
407
        return this.executeMandii(request);
408
    }
409
 
31828 amit.gupta 410
    public String patchJson(String url, Object object, Map<String, String> headers)
411
            throws ProfitMandiBusinessException, HttpHostConnectException {
412
        String jsonString;
413
        try {
414
            if (object.getClass().equals(String.class)) {
415
                jsonString = (String) object;
416
            } else {
417
                jsonString = objectMapper.writeValueAsString(object);
418
            }
419
            LOGGER.info("JSON String - {}", jsonString);
420
        } catch (Exception e) {
421
            e.printStackTrace();
422
            throw new ProfitMandiBusinessException("Json Object", object.toString(), "Could not write as String");
423
        }
424
        StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
425
 
426
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
427
 
428
        HttpPatch request = new HttpPatch(builder.build().encode().toUri());
429
        for (Map.Entry<String, String> entry : headers.entrySet()) {
430
            request.setHeader(entry.getKey(), entry.getValue());
431
        }
432
        request.setEntity(requestEntity);
433
        return this.executeJson(request);
434
    }
435
 
436
    private String toString(InputStream inputStream) {
437
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
438
        StringBuilder responseString = new StringBuilder();
439
        String line = null;
440
        try {
441
            while ((line = reader.readLine()) != null) {
442
                responseString.append(line);
443
            }
444
            inputStream.close();
445
        } catch (IOException e) {
446
            throw new RuntimeException();
447
        }
448
        return responseString.toString();
449
    }
34805 ranu 450
 
451
    public byte[] postForBytes(String url, String payload, Map<String, String> headers) throws IOException {
452
        HttpPost post = new HttpPost(url);
453
        headers.forEach(post::setHeader);
454
 
455
        post.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
456
 
36416 amit 457
        try (CloseableHttpClient client = HttpClientFactory.apacheHttp();
34805 ranu 458
             CloseableHttpResponse response = client.execute(post)) {
459
 
460
            int statusCode = response.getStatusLine().getStatusCode();
461
            if (statusCode != 200) {
462
                throw new IOException("Failed : HTTP error code : " + statusCode);
463
            }
464
 
465
            return EntityUtils.toByteArray(response.getEntity());
466
        }
467
    }
468
 
21557 ashik.ali 469
}