-
Bug
-
Resolution: Done
-
Major
-
3.0.16.Final
-
None
-
None
From: Borut Bolčina <borut.bolcina@gmail.com>
Subject: Client Framework not honoring connection timeouts
Date: 11. oktober 2013 12:37:51 GMT+02:00
To: resteasy-users@lists.sourceforge.net
Hello,
what is wrong with the code below? When using RestEasy Proxy Framework it seems the client is not using the configuration for connection timeouts.
At line 54 there is a test url which returns response after 7 seconds, but the call is not aborted as one might expect.
package si.najdi.httpclient; import javax.ws.rs.ProcessingException; import javax.ws.rs.core.Response; import org.apache.http.client.config.RequestConfig; import org.apache.http.config.SocketConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Main { static Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) { logger.info("Starting HttpClient test."); SocketConfig socketConfig = SocketConfig.custom() .setTcpNoDelay(true) .setSoKeepAlive(true) .setSoReuseAddress(true) .build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setMaxTotal(100); connManager.setDefaultMaxPerRoute(100); connManager.setDefaultSocketConfig(socketConfig); RequestConfig defaultRequestConfig = RequestConfig.custom() .setSocketTimeout(2000) .setConnectTimeout(100) .setConnectionRequestTimeout(3000) .setStaleConnectionCheckEnabled(true) .build(); CloseableHttpClient httpClient = HttpClients.custom() .setDefaultRequestConfig(defaultRequestConfig) .setConnectionManager(connManager) .build(); ApacheHttpClient4Engine apacheHttpClient4Engine = new ApacheHttpClient4Engine(httpClient); ResteasyClient client = new ResteasyClientBuilder().httpEngine(apacheHttpClient4Engine).build(); //String host = "http://httpstat.us/400"; String host = "http://fake-response.appspot.com/?sleep=7"; ResteasyWebTarget newsWebTarget = client.target(host); NewsClient newsClient = newsWebTarget.proxy(NewsClient.class); boolean ok = false; Response response = null; try { logger.info("Calling..."); response = newsClient.clickIncrement("666"); logger.info("...returning"); if (response.getStatus() == Response.Status.OK.getStatusCode()) { String line = (String) response.readEntity(String.class); logger.info("Response line: " + line); } else { String failMessage = response.getStatusInfo().getStatusCode() + " " + response.getStatusInfo().getReasonPhrase(); logger.warn("Failed call. Reason: " + failMessage); } } catch (ProcessingException e) { logger.warn("Exception incrementing click counter." + e); } finally { if (response != null) { response.close(); } } } }
Here is the client interface if it matters:
import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; public interface NewsClient { @GET //@Path("clickcounter/news/{newsId}") Response clickIncrement(@PathParam("newsId") @DefaultValue("123") String newsId); }
The log output:
[12:05:46] INFO [si.najdi.httpclient.Main]: Starting HttpClient test. [12:05:47] DEBUG [org.jboss.resteasy.plugins.providers.DocumentProvider]: Unable to retrieve config: expandEntityReferences defaults to true [12:05:47] DEBUG [org.jboss.resteasy.plugins.providers.DocumentProvider]: Unable to retrieve config: expandEntityReferences defaults to true [12:05:47] INFO [si.najdi.httpclient.Main]: Calling... [12:05:54] INFO [si.najdi.httpclient.Main]: ...returning [12:05:54] INFO [si.najdi.httpclient.Main]: Response line: {"response":"This request has finsihed sleeping for 7 seconds"}
Best regards,
borut
- is related to
-
JBEAP-12010 [GSS](7.0.z) RESTEASY-975 - Client Framework not honoring connection timeouts Apache Client 4.3
- Closed
- relates to
-
RESTEASY-1285 ApacheHttpClient4Engine ignores HttpClient#defaultRequestConfig
- Resolved
-
RESTEASY-1463 Apache http client 4.5 API upgrade causes 4 build test failures
- Resolved
-
RESTEASY-1357 Deprecated Apache classes cleanup
- Resolved