Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9321005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:46:13+00:00 2026-06-19T03:46:13+00:00

Is it possible to link a spring integration groovy script to the success /

  • 0

Is it possible to link a spring integration groovy script to the success / failure outcome on the ExpressionEvaluatingRequestHandlerAdvice bean? At the moment i have this config which delete’s the payload

<beans:bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
    <beans:property name="onSuccessExpression" value="new File(payload).delete()"/>
    <beans:property name="successChannel" ref="successChannel" />
    <beans:property name="onFailureExpression" value="new File(payload).delete()"/>
    <beans:property name="failureChannel" ref="failureChannel" />
</beans:bean>

but i’d like to run a number of actions using various Header details to delete the payload and also rename and change file permissions. The groovy script might look like

    <int-groovy:script>
    <![CDATA[
    def encryptedFile = new File(payload);
        encryptedFile.delete();
        def file = new File(headers['ORIGINAL_FILE']);
        def successFolder = new File(file.getParent(),'success');
        return file.renameTo(new File(successFolder, file.getName()));
        ]]>
    </int-groovy:script>
</int:transformer>

but i’m unsure how to link this config to the ‘successChannel’.

EDIT

OK i wired up the two expressions to pass through the original message, and the groovy logic is linked to the transformer

<!-- handle ftp outcome -->
        <beans:bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <beans:property name="onSuccessExpression" value="payload"/>
            <beans:property name="successChannel" ref="successChannel"/>
            <beans:property name="onFailureExpression" value="payload"/>
            <beans:property name="failureChannel" ref="failureChannel"/>
        </beans:bean>
    </int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>

<int:transformer input-channel="successChannel" output-channel="outputB">
    <int-groovy:script>
    <![CDATA[
        def encryptedFile = new File(payload);
        encryptedFile.delete();
        def file = new File(headers['ORIGINAL_FILE']);
        def successFolder = new File(file.getParent(),'success');
        return file.renameTo(new File(successFolder, file.getName()));
        ]]>
    </int-groovy:script>
</int:transformer>

but if i use ‘payload’ or ‘#root’ is get this exception

Caused by: org.springframework.integration.MessageHandlingException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException)
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:76)
    at org.springframework.integration.transformer.AbstractMessageProcessingTransformer.transform(AbstractMessageProcessingTransformer.java:56)
    at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:67)
    ... 56 more
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException)
    at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1459)
    at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1375)
    at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
    at groovy.lang.run(groovy.lang.Script:3)
    at org.springframework.scripting.groovy.GroovyScriptFactory.executeScript(GroovyScriptFactory.java:247)
    at org.springframework.scripting.groovy.GroovyScriptFactory.getScriptedObject(GroovyScriptFactory.java:185)
    at org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor.executeScript(GroovyScriptExecutingMessageProcessor.java:88)
    at org.springframework.integration.scripting.AbstractScriptExecutingMessageProcessor.processMessage(AbstractScriptExecutingMessageProcessor.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:69)
    at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:84)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:102)
    at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:227)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:127)
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:73)
    ... 58 more

which seems to indicate the the ‘ExpressionEvaluatingRequestHandlerAdvice’ bean reference is being passed rather than the file name?

EDIT- DAY 2

So i updated the example as per Gary’s remarks and used ‘inputMessage.payload’ for the success channel and ‘payload.failedMessage’ for the failed channel. The config looks like this

<int-ftp:outbound-channel-adapter 
    id="ftpOutbound" 
    channel="inputB"        
    cache-sessions="false"
    remote-directory="/"
    session-factory="ftpClientFactory">
    <int-ftp:request-handler-advice-chain>
        <!-- handle three retry attempts -->
        <beans:bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
            <beans:property name="retryTemplate">
                <beans:bean class="org.springframework.retry.support.RetryTemplate">
                    <beans:property name="backOffPolicy">
                        <beans:bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                            <beans:property name="initialInterval" value="5000" />
                            <beans:property name="multiplier" value="3" />
                        </beans:bean>
                    </beans:property>
                </beans:bean>
            </beans:property>
        </beans:bean>
        <!-- handle ftp outcome -->
        <beans:bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <beans:property name="onSuccessExpression" value="payload"/>
            <beans:property name="successChannel" ref="successChannel"/>
            <beans:property name="onFailureExpression" value="payload"/>
            <beans:property name="failureChannel" ref="failureChannel"/>
        </beans:bean>
    </int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>

<int:transformer input-channel="successChannel" output-channel="outputB">
    <int-groovy:script>
    <![CDATA[
        println('successChannel');
        def file = new File(inputMessage.headers['ORIGINAL_FILE']);
        def successFolder = new File(file.getParent(),'success');
        file.renameTo(new File(successFolder, file.getName()));

        def encryptedFile = inputMessage.payload;
        encryptedFile.delete();
        ]]>
    </int-groovy:script>
</int:transformer>

<int:transformer input-channel="failureChannel" output-channel="outputB">
    <int-groovy:script>
    <![CDATA[
        println('failChannel');
        def file = new File(payload.failedMessage.headers['ORIGINAL_FILE']);
        def failedFolder = new File(file.getParent(),'failed');
        file.renameTo(new File(failedFolder, file.getName()));

        def encryptedFile = payload.failedMessage.payload;
        encryptedFile.delete();
        ]]>
    </int-groovy:script>
</int:transformer>

But it seems that the advise handler is getting called three times, rather than stopping after the first successful FTP transfer. Is my ‘onSucessExpression’ logic incorrect?

2013-02-21 10:40:39,588 INFO  [org.springframework.integration.ftp.session.FtpSession] (main) File has been successfully transfered to: /SEPA.enc.writing
2013-02-21 10:40:39,591 INFO  [org.springframework.integration.ftp.session.FtpSession] (main) File has been successfully renamed from: /SEPA.enc.writing to /SEPA.enc
2013-02-21 10:40:39,591 DEBUG [org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice] (main) Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#2e1551b0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
2013-02-21 10:40:39,594 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'successChannel', message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443239593, id=3adf23f7-c428-485a-9da5-839923a915fd}]
2013-02-21 10:40:39,594 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@7219d6af received message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443239593, id=3adf23f7-c428-485a-9da5-839923a915fd}]
successChannel
2013-02-21 10:40:40,164 DEBUG [org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice] (main) Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#2e1551b0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
2013-02-21 10:40:40,165 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'failureChannel', message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443240165, id=596c3a78-493b-45bf-b9ca-c56dab15e318}]
2013-02-21 10:40:40,165 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@4c4b11e9 received message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443240165, id=596c3a78-493b-45bf-b9ca-c56dab15e318}]
failChannel
2013-02-21 10:40:45,218 DEBUG [org.springframework.integration.file.remote.handler.FileTransferringMessageHandler] (main) org.springframework.integration.file.remote.handler.FileTransferringMessageHandler#0 received message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443239551, id=73da6c1f-8658-4397-ab57-ea7591e284da, ORIGINAL_FILE=C:\projects\spring-integration\src\test\resources\citi\SEPA.xml}]
2013-02-21 10:40:45,218 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'successChannel', message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443245218, id=96c0ed36-0eb9-4bab-abff-84d63ff91d80}]
2013-02-21 10:40:45,218 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@7219d6af received message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443245218, id=96c0ed36-0eb9-4bab-abff-84d63ff91d80}]
successChannel
2013-02-21 10:40:45,220 DEBUG [org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice] (main) Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#2e1551b0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
2013-02-21 10:40:45,220 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'failureChannel', message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443245220, id=a63c7877-29f6-46b2-96fc-35ad84589a82}]
2013-02-21 10:40:45,220 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@4c4b11e9 received message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443245220, id=a63c7877-29f6-46b2-96fc-35ad84589a82}]
failChannel
2013-02-21 10:41:00,227 DEBUG [org.springframework.integration.file.remote.handler.FileTransferringMessageHandler] (main) org.springframework.integration.file.remote.handler.FileTransferringMessageHandler#0 received message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443239551, id=73da6c1f-8658-4397-ab57-ea7591e284da, ORIGINAL_FILE=C:\projects\spring-integration\src\test\resources\citi\SEPA.xml}]
2013-02-21 10:41:00,227 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'successChannel', message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443260227, id=e16fb6be-e2c6-4c6e-bc99-e2e4fda9f735}]
2013-02-21 10:41:00,227 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@7219d6af received message: [Payload=C:\projects\spring-integration\src\test\resources\citi\SEPA.enc][Headers={timestamp=1361443260227, id=e16fb6be-e2c6-4c6e-bc99-e2e4fda9f735}]
successChannel
2013-02-21 10:41:00,229 DEBUG [org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice] (main) Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice#2e1551b0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
2013-02-21 10:41:00,229 DEBUG [org.springframework.integration.channel.DirectChannel] (main) preSend on channel 'failureChannel', message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443260229, id=187a95ad-ffdd-4151-9e02-e94e684f6dec}]
2013-02-21 10:41:00,229 DEBUG [org.springframework.integration.transformer.MessageTransformingHandler] (main) org.springframework.integration.transformer.MessageTransformingHandler@4c4b11e9 received message: [Payload=org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice$MessageHandlingExpressionEvaluatingAdviceException: Handler Failed][Headers={timestamp=1361443260229, id=187a95ad-ffdd-4151-9e02-e94e684f6dec}]
failChannel
2013-02-21 10:41:00,242 INFO  [org.springframework.integration.endpoint.EventDrivenConsumer] (Thread-1) Removing {transformer} as a subscriber to the 'inputA' channel
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:46:14+00:00Added an answer on June 19, 2026 at 3:46 am

    The message sent on the onSuccessChannel is an AdviceMessage containing the result of the expression evaluation in the payload and the inbound message in inputMessage.

    Simply use "'foo'" as the onSuccessExpression.

    Then subscribe your <transformer/> to successChannel.

    You can use payload.inputMessage to get a reference to the message.

    Or, use "#root" as the expression, and the original message will be in the payload (as well as inputMessage).

    EDIT:

    The message on the failureChannel is an ErrorMessage with a MessageHandlingExpressionEvaluatingAdviceException payload. This exception has 3 properties failedMessage, cause, and evalResult.

    Note that in your ‘success’ transformer, this won’t work…

    def file = new File(headers['ORIGINAL_FILE']);

    because headers refers to the AdviceMessage headers; you’ll need inputMessage.headers[....

    On the failure transformer, you’d need payload.failedMessage.headers[....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have a link in a SSRS report appear differently when
Does anyone know if this is possible? I have a javascript which highlights the
Refering to this link http://msdn.microsoft.com/en-us/library/b1csw23d.aspx it seems that it is not possible with the
Possible Duplicate: URL Friendly Username in PHP? I have something like this: 'mrt1' =>
Is it possible to link a C++ library to a Java program statically, in
Is it possible to link to a line number in a html file? I
Is it possible to link a static library built with VS2005 into an application
Is it possible to link to another id further down the page with jQueryMobile?
Possible duplicate of: should-i-link-to-google-apis-cloud-for-js-libraries also many other discussions, including: Where do you include the
Possible Duplicate: Javascript force open a link in a browser I am working on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.