| Line 61... |
Line 61... |
| 61 |
this.httpClient = HttpClientBuilder.create().disableCookieManagement()
|
61 |
this.httpClient = HttpClientBuilder.create().disableCookieManagement()
|
| 62 |
.setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig()).build();
|
62 |
.setDefaultRequestConfig(HttpClientFactory.defaultRequestConfig()).build();
|
| 63 |
|
63 |
|
| 64 |
}
|
64 |
}
|
| 65 |
|
65 |
|
| - |
|
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 |
|
| 66 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
82 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
| 67 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
83 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 68 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
|
84 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
|
| 69 |
: scheme.getValue() + hostName + ":" + port + "/" + uri;
|
85 |
: scheme.getValue() + hostName + ":" + port + "/" + uri;
|
| 70 |
return this.get(url, params, headers);
|
86 |
return this.get(url, params, headers);
|
| Line 146... |
Line 162... |
| 146 |
} catch (HttpHostConnectException httpHostConnectException) {
|
162 |
} catch (HttpHostConnectException httpHostConnectException) {
|
| 147 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
163 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
| 148 |
throw httpHostConnectException;
|
164 |
throw httpHostConnectException;
|
| 149 |
} catch (ClientProtocolException e) {
|
165 |
} catch (ClientProtocolException e) {
|
| 150 |
LOGGER.error("Client Error : ", e);
|
166 |
LOGGER.error("Client Error : ", e);
|
| 151 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
167 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 152 |
} catch (IOException e) {
|
168 |
} catch (IOException e) {
|
| 153 |
LOGGER.error("IO Error : ", e);
|
169 |
LOGGER.error("IO Error : ", e);
|
| 154 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
170 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 155 |
}
|
171 |
}
|
| 156 |
}
|
172 |
}
|
| 157 |
|
173 |
|
| 158 |
public String execute(HttpUriRequest request) throws ProfitMandiBusinessException, HttpHostConnectException {
|
174 |
public String execute(HttpUriRequest request) throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 159 |
LOGGER.info("Connecting to server at url {}", request.getURI());
|
175 |
LOGGER.info("Connecting to server at url {}", request.getURI());
|
| Line 172... |
Line 188... |
| 172 |
} catch (HttpHostConnectException httpHostConnectException) {
|
188 |
} catch (HttpHostConnectException httpHostConnectException) {
|
| 173 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
189 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
| 174 |
throw httpHostConnectException;
|
190 |
throw httpHostConnectException;
|
| 175 |
} catch (ClientProtocolException e) {
|
191 |
} catch (ClientProtocolException e) {
|
| 176 |
LOGGER.error("Client Error : ", e);
|
192 |
LOGGER.error("Client Error : ", e);
|
| 177 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
193 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 178 |
} catch (IOException e) {
|
194 |
} catch (IOException e) {
|
| 179 |
LOGGER.error("IO Error : ", e);
|
195 |
LOGGER.error("IO Error : ", e);
|
| 180 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
196 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 181 |
} finally {
|
197 |
} finally {
|
| 182 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
198 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
| 183 |
}
|
199 |
}
|
| 184 |
}
|
200 |
}
|
| 185 |
|
201 |
|
| Line 200... |
Line 216... |
| 200 |
} catch (HttpHostConnectException httpHostConnectException) {
|
216 |
} catch (HttpHostConnectException httpHostConnectException) {
|
| 201 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
217 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
| 202 |
throw httpHostConnectException;
|
218 |
throw httpHostConnectException;
|
| 203 |
} catch (ClientProtocolException e) {
|
219 |
} catch (ClientProtocolException e) {
|
| 204 |
LOGGER.error("Client Error : ", e);
|
220 |
LOGGER.error("Client Error : ", e);
|
| 205 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
221 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 206 |
} catch (IOException e) {
|
222 |
} catch (IOException e) {
|
| 207 |
LOGGER.error("IO Error : ", e);
|
223 |
LOGGER.error("IO Error : ", e);
|
| 208 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
224 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 209 |
} finally {
|
225 |
} finally {
|
| 210 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
226 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
| 211 |
}
|
227 |
}
|
| 212 |
}
|
228 |
}
|
| 213 |
|
229 |
|
| Line 223... |
Line 239... |
| 223 |
} catch (HttpHostConnectException httpHostConnectException) {
|
239 |
} catch (HttpHostConnectException httpHostConnectException) {
|
| 224 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
240 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
| 225 |
throw httpHostConnectException;
|
241 |
throw httpHostConnectException;
|
| 226 |
} catch (ClientProtocolException e) {
|
242 |
} catch (ClientProtocolException e) {
|
| 227 |
LOGGER.error("Client Error : ", e);
|
243 |
LOGGER.error("Client Error : ", e);
|
| 228 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
244 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 229 |
} catch (IOException e) {
|
245 |
} catch (IOException e) {
|
| 230 |
LOGGER.error("IO Error : ", e);
|
246 |
LOGGER.error("IO Error : ", e);
|
| 231 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
247 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 232 |
} finally {
|
248 |
} finally {
|
| 233 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
249 |
if (response != null) EntityUtils.consumeQuietly(response.getEntity());
|
| 234 |
}
|
250 |
}
|
| 235 |
}
|
251 |
}
|
| 236 |
|
252 |
|
| Line 261... |
Line 277... |
| 261 |
} catch (HttpHostConnectException httpHostConnectException) {
|
277 |
} catch (HttpHostConnectException httpHostConnectException) {
|
| 262 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
278 |
LOGGER.error("Connection Timeout Exception", httpHostConnectException);
|
| 263 |
throw httpHostConnectException;
|
279 |
throw httpHostConnectException;
|
| 264 |
} catch (ClientProtocolException e) {
|
280 |
} catch (ClientProtocolException e) {
|
| 265 |
LOGGER.error("Client Error : ", e);
|
281 |
LOGGER.error("Client Error : ", e);
|
| 266 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
282 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 267 |
} catch (IOException e) {
|
283 |
} catch (IOException e) {
|
| 268 |
LOGGER.error("IO Error : ", e);
|
284 |
LOGGER.error("IO Error : ", e);
|
| 269 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
|
285 |
throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"), e);
|
| 270 |
}
|
286 |
}
|
| 271 |
}
|
287 |
}
|
| 272 |
|
288 |
|
| 273 |
public String post(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
289 |
public String post(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
| 274 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
290 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|