Skip to content

GH-3004: Fix MMIH argument resolution #3006

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

Merged
merged 1 commit into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.config.RuntimeBeanReference;
Expand Down Expand Up @@ -517,6 +518,8 @@ private void registerMessageHandlerMethodFactory() {
if (!this.beanFactory.containsBean(IntegrationContextUtils.MESSAGE_HANDLER_FACTORY_BEAN_NAME)) {
BeanDefinitionBuilder messageHandlerMethodFactoryBuilder =
createMessageHandlerMethodFactoryBeanDefinition(false);
// TODO: https://github.com/spring-projects/spring-framework/issues/23352
messageHandlerMethodFactoryBuilder.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
this.registry.registerBeanDefinition(IntegrationContextUtils.MESSAGE_HANDLER_FACTORY_BEAN_NAME,
messageHandlerMethodFactoryBuilder.getBeanDefinition());
}
Expand All @@ -526,6 +529,8 @@ private void registerListMessageHandlerMethodFactory() {
if (!this.beanFactory.containsBean(IntegrationContextUtils.LIST_MESSAGE_HANDLER_FACTORY_BEAN_NAME)) {
BeanDefinitionBuilder messageHandlerMethodFactoryBuilder =
createMessageHandlerMethodFactoryBeanDefinition(true);
// TODO: https://github.com/spring-projects/spring-framework/issues/23352
messageHandlerMethodFactoryBuilder.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
this.registry.registerBeanDefinition(IntegrationContextUtils.LIST_MESSAGE_HANDLER_FACTORY_BEAN_NAME,
messageHandlerMethodFactoryBuilder.getBeanDefinition());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.handler.support;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.Map;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.handler.GenericHandler;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

/**
* @author Gary Russell
* @since 5.2
*
*/
@SpringJUnitConfig
@DirtiesContext
public class MessagingMethodInvocableHelperTests {

@Autowired
private Config config;

@Test
void cachedHandler() {
this.config.sampleFlow().getInputChannel().send(new GenericMessage<>(Collections.singletonMap("key", "value")));
Message<?> received = this.config.queue().receive(0);
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo("Hello value World!");
}

@Configuration
@EnableIntegration
public static class Config {

@Bean
public IntegrationFlow sampleFlow() {
return f -> f
.handle(new MapHandler())
.handle(new StringHandler())
.channel(queue());
}

@Bean
public QueueChannel queue() {
return new QueueChannel();
}

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

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

public static class StringHandler implements GenericHandler<String> {

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

}

}