Reputation: 63
I'm implementing a Restful client using Jersey Client as follows:
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 60000);
clientConfig.property(ClientProperties.READ_TIMEOUT, 60000);
Client client = ClientBuilder.newClient(clientConfig);
This code has been working OK with the timeout exception thrown properly whenever the request time exceed the defined value. However when I decided to switch to use the ApacheConnector as follow:
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(JacksonFeature.class);
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
ApacheConnectorProvider provider = new ApacheConnectorProvider();
clientConfig.connectorProvider(provider);
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 60000);
clientConfig.property(ClientProperties.READ_TIMEOUT, 60000);
Client client = ClientBuilder.newClient(clientConfig);
The timeout doesn't seem to work anymore so now when the server fails to respond my client will keep waiting until like forever without throwing timeout exception.
Have anyone encountered this problem before or had any clue of what I'm doing wrong here? Thanks
Upvotes: 2
Views: 3140
Reputation: 11
RequestConfig reqConfig = RequestConfig.custom()
.setConnectionRequestTimeout(time_out_value).build();
Upvotes: 1
Reputation: 374
Try to create and register a org.apache.http.client.config.RequestConfig
:
clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, RequestConfig.custom()
.setConnectTimeout(60000)
.setSocketTimeout(60000)
.build());
Upvotes: 1