Announcement Announcement Module
Collapse
No announcement yet.
HttpInvokerClientInterceptor retry Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpInvokerClientInterceptor retry

    I am using the Spring 2.5 HttpInvokers with a rich client gui. Due to frequent internet blips which causes the application to crash I am trying to set up a retry functionality where the remote connection will retry several times before crashing out sanely.

    I am using the HttpInvokerClientInterceptor on the client side and have tried implementing a method interceptor to retry:

    Client side HttpInvoker config:

    Code:
      <bean id="myServiceInterceptor"
              class="org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor">
            <property name="serviceUrl">
                <value>https://localhost/services/myService</value>
            </property>
            <property name="remoteInvocationFactory" ref="remoteInvocationFactory"/>
            <property name="httpInvokerRequestExecutor">
                <bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor">
                    <property name="readTimeout" value="2000000"/>
                </bean>
            </property>
        </bean>
        <bean id="myService" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="interceptorNames">
                <list>
                    <value>retryConnection</value>
                    <value>myServiceInterceptor</value>
                </list>
            </property>
            <property name="proxyInterfaces">
                <value>com.MyServiceIF</value>
            </property>
        </bean>
    Retry around advice interceptor config:

    Code:
     <bean id="retryConnection" class="org.springframework.aop.support.DefaultPointcutAdvisor">
            <property name="pointcut">
                <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
                    <property name="patterns">
                        <list>
                            <value>.*</value>
                        </list>
                    </property>
                </bean>
            </property>
            <property name="advice">
                <bean class="RetryConnectionTool">
                    <property name="maximumFailuresUntilExit" value="10"/>
                    <property name="maxRetriesPerCall" value="3"/>
                    <property name="sleepTime" value="15000"/>
                        </bean>
            </property>
        </bean>
    Here is the code for the RetryConnectionTool. The logic seems to work when I step through it, but whenever I call
    methodInvocation.proceed() a second time I get an RuntimeException wrapping a NullPointerException.

    Code:
    public class RetryConnectionTool implements MethodInterceptor
        {
    
        private static int FailureCount = 0;
        static Logger logger = Logger.getLogger(RetryConnectionTool.class);
        /**
         * 3 seconds of sleep
         */
        private int sleepTime = 3000;
        private int maxRetriesPerCall = 3;
        private int maximumFailuresUntilExit = 10;
    
        public void setSleepTime(int sleepTime)
            {
            this.sleepTime = sleepTime;
            }
    
        public void setMaximumFailuresUntilExit(int maximumFailuresUntilExit)
            {
            this.maximumFailuresUntilExit = maximumFailuresUntilExit;
            }
    
        public void setMaxRetriesPerCall(int maxRetriesPerCall)
            {
            this.maxRetriesPerCall = maxRetriesPerCall;
            }
    
        public RetryConnectionTool()
            {
            }
    
        public Object invoke(MethodInvocation methodInvocation) throws Throwable
            {
            int tryCount = 0;
            do
                {
                try
                    {
                    //logic to execute after first try or on any retry
                    if (tryCount >= 1)
                        {
                        if (tryCount == 1)   //increment the failure count on every first retry
                            FailureCount++;
    
                        //if the failure count now exceeds max times exit
                        if (FailureCount >= maximumFailuresUntilExit)
                            {
                            logger.error("internet issue failure " + methodInvocation.getMethod().toGenericString());
                            System.exit(-1);
                            return null;
                            }
                        else//otherwise delay before retrying
                            Thread.sleep(sleepTime);
                        }
    
                    //if we have failed 10 times in the past or retried 3 times to no success shut it down
    
                    Object result = methodInvocation.proceed();
    
                    //if we have tried more than once and there is already a record of a failure we try again
                    if (tryCount > 1 && FailureCount > 1)
                        {
                        String messagePassed = "There seems to be a problem with your internet connection.  It the problem persists Iridium Suite will be forced to close.\n" +
                                "Please evaluate your internet connectivity.";
                        JOptionPane.showMessageDialog(null, messagePassed, "WARNING", JOptionPane.WARNING_MESSAGE);
                        }
                    return result;
    
                    }
                catch (org.springframework.remoting.RemoteConnectFailureException x)
                    {
                    logger.error("internet issue " + methodInvocation.getMethod().toGenericString(), x);
                    //retry on failure
                    }
                catch (RemoteLookupFailureException x)
                    {
                    logger.error("internet issue " + methodInvocation.getMethod().toGenericString(), x);
                    //retry on failure
                    }
                catch (java.net.ConnectException x)
                    {
                    logger.error("internet issue " + methodInvocation.getMethod().toGenericString(), x);
                    //retry on failure
                    }
                catch (java.rmi.ConnectException x)
                    {
                    logger.error("internet issue " + methodInvocation.getMethod().toGenericString(), x);
                    //retry on failure
                    }
                catch (Throwable x)
                    {
                    throw x;
                    }
                }
            while (tryCount++ < maxRetriesPerCall);
    
            //if we have exceeded the max tries per call to no success shut it down
            logger.error("internet issue failure " + methodInvocation.getMethod().toGenericString());
            System.exit(-1);
            return null;
            }
    
        }

    Why can't I call methodInvocation.proceed() twice?

    Thanks!
    Last edited by wexwarez; Jul 3rd, 2013, 12:32 PM.
Working...
X