3
votes

I have http outbound gateway that post json message to rest service, now the rest will response with http error status with json message type in case if there is any error which should captured by our application. in happy scenario which post json message to that rest service and got http success status and json message also should captured with our application.

Now what I achieved through spring integration I was able to send message and got success response and capture it but in error status the spring behavior it throw an exception how can I change the behavior?

also how can make retry if there is any timeout ?

below the http outbound gateway configuration

    <int-http:outbound-gateway request-channel="aggregatorChannel" reply-channel="responseChannel" charset="UTF-8"
    url="http://localhost:8090/receiveGateway" http-method="POST" reply-timeout="180000">               
    <int-http:request-handler-advice-chain >
        <int:retry-advice max-attempts="5" recovery-channel="aggregatorChannel" >
            <int:exponential-back-off initial="1000" multiplier="5.0" maximum="600000" />
        </int:retry-advice>
    </int-http:request-handler-advice-chain>
</int-http:outbound-gateway>

the above configuration will retry on the error message which I don't want retry on that, I want to retry if there is only timeout.

1

1 Answers

3
votes

What do you want to change the behavior to (when there's an error)?

If you wire up the RetryTemplate for the retry interceptor manually, as a <bean/>, you can specify in the RetryPolicy which exceptions are retryable.

EDIT:

It's not entirely clear what you are trying to do, but maybe this will point you in the right direction...

<int-http:outbound-gateway request-channel="requestChannel" 
                           url="http://localhost:8080/http/receiveGateway"
                           http-method="POST"
                           request-factory="requestFactory"
                           expected-response-type="java.lang.String">
    <int-http:request-handler-advice-chain >
        <int:retry-advice max-attempts="5" recovery-channel="foo">
            <int:exponential-back-off initial="1000" multiplier="1.1" maximum="600000" />
        </int:retry-advice>
        <bean class="foo.MyExceptionAdvice" />
    </int-http:request-handler-advice-chain>
</int-http:outbound-gateway>

<bean id="requestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="connectTimeout" value="5000"/>
    <property name="readTimeout"    value="5000"/>
</bean>

If the custom exception advice throws an exception, the message will be retried and eventually sent to he recovery channel. If the custom advice consumes the error, it can send a return value. I have put a simple on this gist.