Skip to content

InvocableHandlerMethod fails to resolve Object payload after resolving Map payload #3004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
L00kian opened this issue Jul 24, 2019 · 1 comment · Fixed by #3006
Closed

InvocableHandlerMethod fails to resolve Object payload after resolving Map payload #3004

L00kian opened this issue Jul 24, 2019 · 1 comment · Fixed by #3006

Comments

@L00kian
Copy link

L00kian commented Jul 24, 2019

Hello,

I faced an issue using 5.2.0.M2 release that didn't appear in 5.1.6

When having two GenericHandler implementation sequentially handling the message if the first handler is a subtype of Map the second fails with ClassCastException due to attempted use of cached MapArgumentResolver which was used for the first invocation

I nailed the code facing the issue to a small program below.

I'm not 100% certain about that but in 5.1.6 the HandlerMethodArgumentResolverComposite didn't seem to have anything at all for the second invocation after the first one


@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args).getBean("inputChannel", DirectChannel.class)
                .send(new GenericMessage<>(Collections.singletonMap("key", "value")));
    }

    @Bean
    public DirectChannel inputChannel() {
        return MessageChannels.direct().get();
    }

    @Bean
    public IntegrationFlow sampleFlow() {
        return IntegrationFlows.from(inputChannel())
                .handle(new SampleMapHandler())
                .handle(new SampleHandler())
                .handle(message -> {
                }).get();
    }

    public static class SampleHandler implements GenericHandler<String> {

        @Override
        public String handle(String stringPayload, MessageHeaders messageHeaders) {
            return stringPayload + " World!";
        }
    }

    public static class SampleMapHandler implements GenericHandler<Map<String, String>> {

        @Override
        public String handle(Map<String, String> mapPayload, MessageHeaders messageHeaders) {
            return "Hello " + mapPayload.get("key");
        }
    }
}
@garyrussell
Copy link
Contributor

Thanks for trying the milestones and finding this; the fix will be in 5.2.0.M4 (due August 1).

artembilan pushed a commit that referenced this issue Jul 27, 2019
Fixes #3004

Change the `DefaultMessageHandlerMethodFactory` beans to prototype scope.

See spring-projects/spring-framework#23352
garyrussell added a commit that referenced this issue Jul 31, 2019
See #3004

spring-projects/spring-framework#23352
is now resolved so the `DefaultMessageHandlerMethodFactory` can be
singletons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants