| Line 46... |
Line 46... |
| 46 |
ObjectMapper objectMapper;
|
46 |
ObjectMapper objectMapper;
|
| 47 |
|
47 |
|
| 48 |
public RestClient() {
|
48 |
public RestClient() {
|
| 49 |
PoolingHttpClientConnectionManager connManager
|
49 |
PoolingHttpClientConnectionManager connManager
|
| 50 |
= new PoolingHttpClientConnectionManager();
|
50 |
= new PoolingHttpClientConnectionManager();
|
| 51 |
connManager.setMaxTotal(5);
|
51 |
connManager.setMaxTotal(20);
|
| 52 |
connManager.setDefaultMaxPerRoute(4);
|
52 |
connManager.setDefaultMaxPerRoute(8);
|
| 53 |
httpClient = HttpClients.custom().disableCookieManagement().disableAuthCaching().disableConnectionState().
|
53 |
httpClient = HttpClients.custom().disableCookieManagement().disableAuthCaching().disableConnectionState().
|
| 54 |
disableAuthCaching().setConnectionManager(connManager).build();
|
54 |
disableAuthCaching().setConnectionManager(connManager)
|
| - |
|
55 |
.setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig())
|
| - |
|
56 |
.build();
|
| 55 |
|
57 |
|
| 56 |
}
|
58 |
}
|
| 57 |
|
59 |
|
| 58 |
public RestClient(int connectionTimeoutMillis) {
|
60 |
public RestClient(int connectionTimeoutMillis) {
|
| 59 |
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5 * 1000).build();
|
61 |
this.httpClient = HttpClientBuilder.create().disableCookieManagement()
|
| 60 |
this.httpClient = HttpClientBuilder.create().disableCookieManagement().setDefaultRequestConfig(requestConfig).build();
|
62 |
.setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig()).build();
|
| 61 |
|
63 |
|
| 62 |
}
|
64 |
}
|
| 63 |
|
65 |
|
| 64 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
66 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
| 65 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
67 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
| Line 434... |
Line 436... |
| 434 |
HttpPost post = new HttpPost(url);
|
436 |
HttpPost post = new HttpPost(url);
|
| 435 |
headers.forEach(post::setHeader);
|
437 |
headers.forEach(post::setHeader);
|
| 436 |
|
438 |
|
| 437 |
post.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
|
439 |
post.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
|
| 438 |
|
440 |
|
| 439 |
try (CloseableHttpClient client = HttpClients.createDefault();
|
441 |
try (CloseableHttpClient client = HttpClientFactory.apacheHttp();
|
| 440 |
CloseableHttpResponse response = client.execute(post)) {
|
442 |
CloseableHttpResponse response = client.execute(post)) {
|
| 441 |
|
443 |
|
| 442 |
int statusCode = response.getStatusLine().getStatusCode();
|
444 |
int statusCode = response.getStatusLine().getStatusCode();
|
| 443 |
if (statusCode != 200) {
|
445 |
if (statusCode != 200) {
|
| 444 |
throw new IOException("Failed : HTTP error code : " + statusCode);
|
446 |
throw new IOException("Failed : HTTP error code : " + statusCode);
|