Hi all,
Can someone please do me a favour and check that I am setting my
timeouts correctly in the below code. I'm trying to get my code to
timeout after roughly 2 seconds & not retry. But what I'm seeing is
that the code sticks to the HttpClient defaults of retrying 5 times and
using a 10 second timeout. Here's the appropriate bit of code:
private static DefaultHttpClient httpClient;
private void createClient() {
httpClient = new DefaultHttpClient()
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
HttpConnectionParams.setSoTimeout(httpParams, 2000);
httpClient.setHttpRequestRetryHandler(new
DefaultHttpRequestRetryHandler(0, false));
httpClient.setParams(httpParams);
}
private ClientExecutor getClientExecutor() {
return new ApacheHttpClient4Executor(httpClient);
}
private ILoggingService
createLoggingService(ClassPathXmlApplicationContext applicationContext) {
return ProxyFactory.create(ILoggingService.class,
loggingTaskSettings.getRestAddress(), getClientExecutor());
}
When I attempt to use this code, I'm always receive and exception like
below, 5 times with 10 seconds between each one:
2011-09-16 15:34:28,239 - ERROR
[com.oobjects.kbroker.logging.LoggingTask:147] -
java.lang.RuntimeException:
org.apache.http.conn.HttpHostConnectException: Connection to
http://blade304.openobjects.com:8080 refused
java.lang.RuntimeException:
org.apache.http.conn.HttpHostConnectException: Connection to
http://blade304:8080 refused
at
org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:108)
at
org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72)
at $Proxy54.logMultiple(Unknown Source)
at
com.oobjects.kbroker.logging.LoggingTask.logQueue(LoggingTask.java:104)
at com.oobjects.kbroker.logging.LoggingTask.run(LoggingTask.java:145)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: org.apache.http.conn.HttpHostConnectException: Connection to
http://blade304:8080 refused
at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159)
at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor.execute(ApacheHttpClient4Executor.java:87)
at
org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:39)
at
org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:40)
at
org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45)
at
org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:473)
at
org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704)
at
org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:104)
... 6 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:133)
... 19 more
I've breakpointed the execute call in the ApacheHttpClient4Executor
class and it appears to be using my HttpClient with my parameters set.
But the timeouts & retries don't match what I've set. Does anyone have
any clues on what else I could try? I've been banging my head against
this problem all day and I'm not getting any further. Could there be
something else that's possibly resetting my client?
Cheers for any input,
Lee
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users