Spring Integration - Invoking Methods in Application Code
Asked Answered
B

2

3

I have a outbound-channel-adapter, where the relevant configuration is shown below.

<int:outbound-channel-adapter channel="foo-fileChannel" ref="foo-handlerTarget" method="handleFeedFile">
    <int:poller fixed-delay="5000" receive-timeout="1000" max-messages-per-poll="10" />
</int:outbound-channel-adapter>
<int:channel id="foo-fileChannel">
    <int:queue />
</int:channel>


<bean id="foo-handlerTarget" class="com.abc.FooFeedHandlerImpl">
    <property name="fooDescriptorFile" value="${feed.foo.fooDescriptorFile}" />
    <property name="fileIdRegex" ref="foo-fileRegex" />
    <property name="processId" value="${feed.processId}" />
    <property name="workingLocation" value="${feed.foo.workingLocation}" />
    <property name="remoteLocation" value="${feed.foo.remoteLocation}" />
    <property name="stalenessThreshold" value="${feed.foo.stalenessThreshold}" />
</bean>

And in FooFeedHandlerImpl...

public void handleFeedFile(File retrievedFile) {
    handleFeedFile(retrievedFile, null);
}


public void handleFeedFile(File retrievedFile, String processKey) {
    if (isHandlerForFileName(retrievedFile.getName())) {
        processFeed(retrievedFile, processKey);
    }
}

Questions:

Which handleFeedFile method gets invoked by the channel adapter?

When I invoke a method in the application code using Spring integration, how are the method parameters determined?

Thanks for any help!

Edit:

I ran my process locally (downloaded a local SFTP server - http://www.coreftp.com/server/index.html) and determined that the handleFeedFile(File file) method was invoked.

Blackface answered 1/5, 2015 at 20:2 Comment(1)
what currently happens?Ranchman
E
3

You probably want to refer to F.6 Message Mapping rules and conventions.

Multiple parameters could create a lot of ambiguity with regards to determining the appropriate mappings. The general advice is to annotate your method parameters with @Payload and/or @Header/@Headers Below are some of the examples of ambiguous conditions which result in an Exception being raised.

and:

Multiple methods:

Message Handlers with multiple methods are mapped based on the same rules that are described above, however some scenarios might still look confusing.

If you're not in a position to annotate your target methods, then you might be able to use a SpEL expression to call your intended method:

3.3.2 Configuring An Outbound Channel Adapter

Like many other Spring Integration components, the and also provide support for SpEL expression evaluation. To use SpEL, provide the expression string via the 'expression' attribute instead of providing the 'ref' and 'method' attributes that are used for method-invocation on a bean. When an Expression is evaluated, it follows the same contract as method-invocation where: the expression for an will generate a message anytime the evaluation result is a non-null value, while the expression for an must be the equivalent of a void returning method invocation.

Europa answered 2/5, 2015 at 23:45 Comment(2)
Thanks ninj. I definitely have a better understanding of what is going on now from your help. However, I'm still not sure which method would be invoked in my case. It looks awfully similar to the second to last example provided in the message mapping rules, e.g. foo(String str, Map m) vs foo(String str), but I am not getting an Exception... Do you know the rule for my case?Blackface
I edited my answer after debugging the process and determining the method. Not surprisingly, the method with just one parameter was invoked. In my case, the File is the payload so handleFeedFile(File file) is the only method that works, I guess.Blackface
R
1

According to the documentation on Spring integration, the POJO (bean foo-handlerTarget) in your case will get called with a Message object containing the payload. Have you executed your code? I'd expect it generates a NoSuchMethodError.

You need a

public void handleFeedFile(Message<?> message);

method.

Ranchman answered 1/5, 2015 at 21:45 Comment(1)
Thanks for the reply. Yes the code has been executed. It has actually been run in our production environment for several years without issue.Blackface

© 2022 - 2024 — McMap. All rights reserved.