Results 1 to 10 of 14

Thread: Two advice in one request-handler-advice-chain

Hybrid View

  1. #1

    Default Two advice in one request-handler-advice-chain

    Hello,
    first of all thank you for developing request-handler-advice-chain.

    I have simply question. Is there possible to have combination of RequestHandlerRetryAdvice and ExpressionEvaluatingRequestHandlerAdvice in one request-handler-advice-chain?

    I would like to do 3 tries for some action (like for ftp otbound like in the following code) - in case of success invoke success-expression and in case of 3 failed tries invoke on error-expression but it seems to me that this configuration is doing only one try (in case of error) and then ExpressionEvaluatingRequestHandlerAdvice action (error-expression).

    Code:
    <int-ftp:outbound-channel-adapter id="ftpOutbound"
    		channel="ftpOutChannel"
    		session-factory="ftpOUT"
    		remote-directory="/foo"
    		<int-ftp:request-handler-advice-chain >
    			<bean id="retyrAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
    				<property name="retryTemplate">
    					<bean class="org.springframework.retry.support.RetryTemplate">
    						<property name="backOffPolicy">
    							<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
    								<property name="initialInterval" value="5000" />
    								<property name="multiplier" value="3" />
    							</bean>
    						</property>
    					</bean>
    				</property>
    			</bean>
    			<bean id="errorHandler" class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice" >
    				<property name="trapException" value="true"></property>
    				<property name="onSuccessExpression" value="payload.delete()" />
    				<property name="successChannel" ref="afterSuccessDeleteChannel" />
    				<property name="onFailureExpression" value="payload.renameTo(new java.io.File('/foo/failed/' + payload.getName() + '.failed'))" />
    				<property name="failureChannel" ref="afterFailRenameChannel" />
    			</bean>
    		</int-ftp:request-handler-advice-chain>
    	</int-ftp:outbound-channel-adapter>
    Thank you,
    Jakub

  2. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    637

    Default

    Hello, Jakub!

    Yes, it is: we already observed it and fixed: https://jira.springsource.org/browse/INT-2858.
    So, just get the latest 2.2.1.SNAPSHOT and have a good time!

    Take care,
    Artem

  3. #3

    Default

    Thank you :-),
    I have switched to 2.2.1.BUILD-SNAPSHOT and it works. Interesting note is that it works (3 attempts) only in case of definition in such order:
    Code:
    <int-ftp:request-handler-advice-chain >
       <bean id="errorHandler" class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"/>   
       <bean id="retyrAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
    </int-ftp:request-handler-advice-chain>
    for this one:
    Code:
    <int-ftp:request-handler-advice-chain >
       <bean id="retyrAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
       <bean id="errorHandler" class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"/>
    </int-ftp:request-handler-advice-chain>
    there are logged always only two tries <Retry: count=0>,<Retry: count=1> and then it goes to ExpressionEvaluatingRequestHandlerAdvice (even if I use 5 attempts in retryPolicy)

    ---------------------------------------------------------------------------------------------------
    I have also one question regarding Error message which is sent to failureChannel. Please let me know whether I should create new thread for this.

    Lets say that this ftp outbound action fails due to non-exsting target path. Without spring-integration or without ExpressionEvaluatingRequestHandlerAdvice I get full stack trace with many "causes" and root cause
    java.io.IOException: Failed to write.... Server replied with: 553 Could not create file. which is quite important information.

    In my failureChannel where I use following expression I get following message:
    Code:
    expression="payload.getMessage()+' cause: '+payload.getCause()"
    
    Handler Failed cause: org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice$ThrowableHolderException: org.springframework.integration.MessagingException: Failed to invoke handler
    which has only final Exception + cause. Is there somehow possible to get root cause? BTW payload.getCause().getStackTrace().toString() did not help.

    Thank you,
    Jakub

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    The advices are nested (chained); I am surprised to see any retries when the error handler (with trapException="true") is defined AFTER the retry advice. I'll run some tests.

    The exception should be in payload.cause.cause - but I don't think we should be exposing the ThrowableHolderException, we should be unwrapping it - again, I'll run some tests to see what's going on.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    I just ran some tests and it worked as expected for me; when the chain was defined with the retry advice first, and the errorHandler second (with trapException = true) I only see one attempt (count=0) because, from the perspective of the retry advice, the downstream calls were successful (the errorHandler trapped the exception).

    When I put the errorHandler first, I see the 3 attempts followed by the error going to the 'afterFailRenameChannel'.

    However, we should not be leaking the ThrowableHolderException to the outside world. I opened a new JIRA for that. https://jira.springsource.org/browse/INT-2894
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6

    Default

    Thank you Gary,
    you are right - I saw <Retry: count=0>,<Retry: count=1> (when the error handler is defined AFTER the retry advice) event when trapException="false".
    --------------------------------------------------------
    Also thank you for opening of JIRA regarding Exceptions - I am trying 2.2.1-RELEASE now and payload.cause.cause.cause.cause returns the root cause . However - is there any way how to get it directly - without nesting (since for some other type exceptions the value of expression: payload.cause.cause.cause.cause does not need to exist and it will throw Expression evaluation failed)

    Regards,
    Jakub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •