javaspringjavafxspring-remoting

org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service occurs when starting tasks from anbother thread


I have spring application with JavaFX client, and I get this exception when ever come method is called which runs in another thread (for background tasks) - which is not the main JavaFx thread.

org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [http://localhost:8080/server/service/security/UserGroupService]; 
 nested exception is java.net.SocketTimeoutException: Read timed out
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:144)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy63.batchJobSetAccessRightsToConsultant(Unknown Source)
at client.view.control.reporting.AccessRightsBatchDialog$1Local$744.invoke$(AccessRightsBatchDialog.fx:374)
at com.sun.javafx.functions.Function1.invoke(Function1.java:44)
at com.sun.javafx.functions.Function1.invoke$(Function1.java:38)
at client.async.AsyncTask.taskRun(AsyncTask.fx:71)
at client.async.AsyncTaskHelper.run(AsyncTaskHelper.java:32)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
  Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.executePostMethod(CommonsHttpInvokerRequestExecutor.java:195)
at org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.doExecuteRequest(CommonsHttpInvokerRequestExecutor.java:129)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:136)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:191)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:173)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:141)
... 11 more

The last change I made, and I suspect, a cause of this - because I need user info from HTTP session, in each service proxy , I am passing this httpInvokerRequestExecutor bean:

<bean id="httpInvokerRequestExecuter" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor" >

for example:

<bean id="testServiceProxy"
    class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="${remoteUrl}/service/test/TestService" />
    <property name="serviceInterface"
        value="common.service.test.TestService" />
    <property name="httpInvokerRequestExecutor" ref="httpInvokerRequestExecuter" />
</bean>

With methods which run in main thread, this never seems to happen.

All ideas on caused and possible solutions are very welcomed.


Solution

  • Inrease the read timeout for httpInvokerRequestExecuter. The default is a minute. You can either increase it or set to 0 which means it will never timeout (probably not a good idea but good for a test).

    Bean definition to remove readTimeout (or set it to applicable amount):

    <bean id="httpInvokerRequestExecuter" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecuto‌​r" > 
         <property name="readTimeout" value="0" /> 
    </bean>