INT-3374 Fix Package Tangle; Part I
JIRA: https://jira.spring.io/browse/INT-3374 `DefaultDatatypeChannelMessageConverter` Move `getConversionService()` from `IntegrationContextUtils` to `IntegrationUtils` in `support.utils`.
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -71,8 +72,8 @@ public class IntegrationConverterInitializer implements IntegrationConfiguration
|
||||
registry.registerBeanDefinition(IntegrationContextUtils.CONVERTER_REGISTRAR_BEAN_NAME,
|
||||
converterRegistrarBuilder.getBeanDefinition());
|
||||
|
||||
if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)) {
|
||||
registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
if (!registry.containsBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)) {
|
||||
registry.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
new RootBeanDefinition(CONTEXT_PACKAGE + "CustomConversionServiceFactoryBean"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.expression.TypeLocator;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -119,7 +120,7 @@ public class IntegrationEvaluationContextFactoryBean implements FactoryBean<Stan
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.applicationContext != null) {
|
||||
this.beanResolver = new BeanFactoryResolver(this.applicationContext);
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(this.applicationContext);
|
||||
ConversionService conversionService = IntegrationUtils.getConversionService(this.applicationContext);
|
||||
if (conversionService != null) {
|
||||
this.typeConverter = new StandardTypeConverter(conversionService);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -46,18 +47,20 @@ class ConverterRegistrar implements InitializingBean, BeanFactoryAware {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(beanFactory, "BeanFactory is required");
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
ConversionService conversionService = IntegrationUtils.getConversionService(beanFactory);
|
||||
if (conversionService instanceof GenericConversionService) {
|
||||
ConversionServiceFactory.registerConverters(converters, (GenericConversionService) conversionService);
|
||||
}
|
||||
else {
|
||||
Assert.notNull(conversionService, "Failed to locate '" + IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME + "'");
|
||||
Assert.notNull(conversionService, "Failed to locate '" + IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.config.IntegrationConfigUtils;
|
||||
import org.springframework.integration.metadata.MetadataStore;
|
||||
@@ -54,8 +53,6 @@ public abstract class IntegrationContextUtils {
|
||||
|
||||
public static final String CONVERTER_REGISTRAR_BEAN_NAME = "converterRegistrar";
|
||||
|
||||
public static final String INTEGRATION_CONVERSION_SERVICE_BEAN_NAME = "integrationConversionService";
|
||||
|
||||
public static final String INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME = "integrationEvaluationContext";
|
||||
|
||||
public static final String INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME = "integrationHeaderChannelRegistry";
|
||||
@@ -126,14 +123,6 @@ public abstract class IntegrationContextUtils {
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param beanFactory BeanFactory for lookup, must not be null.
|
||||
* @return The {@link ConversionService} bean whose name is "integrationConversionService" if available.
|
||||
*/
|
||||
public static ConversionService getConversionService(BeanFactory beanFactory) {
|
||||
return getBeanOfType(beanFactory, INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param beanFactory BeanFactory for lookup, must not be null.
|
||||
* @return the instance of {@link StandardEvaluationContext} bean whose name is "integrationEvaluationContext" .
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.integration.support.DefaultMessageBuilderFactory;
|
||||
import org.springframework.integration.support.MessageBuilderFactory;
|
||||
import org.springframework.integration.support.context.NamedComponent;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -166,7 +167,7 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo
|
||||
if (this.conversionService == null && this.beanFactory != null) {
|
||||
synchronized (this) {
|
||||
if (this.conversionService == null) {
|
||||
this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory);
|
||||
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);
|
||||
}
|
||||
}
|
||||
if (this.conversionService == null && this.logger.isDebugEnabled()) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
|
||||
/**
|
||||
* Utility class with static methods for helping with establishing environments for
|
||||
@@ -88,7 +89,7 @@ public abstract class ExpressionUtils {
|
||||
}
|
||||
if (evaluationContext == null) {
|
||||
if (beanFactory != null) {
|
||||
conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
conversionService = IntegrationUtils.getConversionService(beanFactory);
|
||||
}
|
||||
evaluationContext = createStandardEvaluationContext(conversionService, beanFactory);
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.annotation.Gateway;
|
||||
import org.springframework.integration.annotation.GatewayHeader;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.history.TrackableComponent;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -67,7 +67,7 @@ import org.springframework.util.StringUtils;
|
||||
* with messaging components without application code being aware of them allowing
|
||||
* for POJO-style interaction.
|
||||
* This component is also aware of the {@link ConversionService} set on the enclosing {@link BeanFactory}
|
||||
* under the name {@link IntegrationContextUtils#INTEGRATION_CONVERSION_SERVICE_BEAN_NAME} to
|
||||
* under the name {@link IntegrationUtils#INTEGRATION_CONVERSION_SERVICE_BEAN_NAME} to
|
||||
* perform type conversions when necessary (thanks to Jon Schneider's contribution and suggestion in INT-1230).
|
||||
*
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
*/
|
||||
package org.springframework.integration.support.converter;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.converter.MessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Default message converter for datatype channels. Registered under bean name
|
||||
@@ -30,7 +35,12 @@ import org.springframework.messaging.converter.MessageConverter;
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class DefaultDatatypeChannelMessageConverter extends IntegrationObjectSupport implements MessageConverter {
|
||||
public class DefaultDatatypeChannelMessageConverter implements MessageConverter,
|
||||
BeanFactoryAware {
|
||||
|
||||
private volatile ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
private volatile boolean conversionServiceSet;
|
||||
|
||||
/**
|
||||
* Specify the {@link ConversionService} to use when trying to convert to
|
||||
@@ -40,9 +50,17 @@ public class DefaultDatatypeChannelMessageConverter extends IntegrationObjectSup
|
||||
*
|
||||
* @param conversionService The conversion service.
|
||||
*/
|
||||
@Override
|
||||
public void setConversionService(ConversionService conversionService) {
|
||||
super.setConversionService(conversionService);
|
||||
Assert.notNull(conversionService, "'conversionService' must not be null");
|
||||
this.conversionService = conversionService;
|
||||
this.conversionServiceSet = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
if (!this.conversionServiceSet && beanFactory != null) {
|
||||
this.conversionService = IntegrationUtils.getConversionService(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +68,7 @@ public class DefaultDatatypeChannelMessageConverter extends IntegrationObjectSup
|
||||
*/
|
||||
@Override
|
||||
public Object fromMessage(Message<?> message, Class<?> targetClass) {
|
||||
ConversionService conversionService = this.getConversionService();
|
||||
ConversionService conversionService = this.conversionService;
|
||||
if (conversionService != null) {
|
||||
if (conversionService.canConvert(message.getPayload().getClass(), targetClass)) {
|
||||
return conversionService.convert(message.getPayload(), targetClass);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.support.utils;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* General utility methods.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class IntegrationUtils {
|
||||
|
||||
public static final String INTEGRATION_CONVERSION_SERVICE_BEAN_NAME = "integrationConversionService";
|
||||
|
||||
/**
|
||||
* @param beanFactory BeanFactory for lookup, must not be null.
|
||||
* @return The {@link ConversionService} bean whose name is "integrationConversionService" if available.
|
||||
*/
|
||||
public static ConversionService getConversionService(BeanFactory beanFactory) {
|
||||
return getBeanOfType(beanFactory, INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
|
||||
}
|
||||
|
||||
private static <T> T getBeanOfType(BeanFactory beanFactory, String beanName, Class<T> type) {
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
if (!beanFactory.containsBean(beanName)) {
|
||||
return null;
|
||||
}
|
||||
return beanFactory.getBean(beanName, type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Provides global utility support classes for the runtime system.
|
||||
*/
|
||||
package org.springframework.integration.support.utils;
|
||||
@@ -24,6 +24,7 @@ import org.springframework.integration.handler.AbstractMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.support.DefaultMessageBuilderFactory;
|
||||
import org.springframework.integration.support.MessageBuilderFactory;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -52,7 +53,7 @@ public abstract class AbstractMessageProcessingTransformer implements Transforme
|
||||
if (this.messageProcessor instanceof BeanFactoryAware) {
|
||||
((BeanFactoryAware) this.messageProcessor).setBeanFactory(beanFactory);
|
||||
}
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
ConversionService conversionService = IntegrationUtils.getConversionService(beanFactory);
|
||||
if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) {
|
||||
((AbstractMessageProcessor<?>) this.messageProcessor).setConversionService(conversionService);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.channel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -35,6 +36,8 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -111,18 +114,22 @@ public class DatatypeChannelTests {
|
||||
BeanDefinitionBuilder conversionServiceBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(ConversionServiceFactoryBean.class);
|
||||
conversionServiceBuilder.addPropertyValue("converters", Collections.singleton(converter));
|
||||
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
context.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
conversionServiceBuilder.getBeanDefinition());
|
||||
BeanDefinition messageConverter = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
DefaultDatatypeChannelMessageConverter.class).getBeanDefinition();
|
||||
context.registerBeanDefinition(
|
||||
IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME, messageConverter);
|
||||
BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
|
||||
IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME,
|
||||
messageConverter);
|
||||
BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(QueueChannel.class);
|
||||
channelBuilder.addPropertyValue("datatypes", "java.lang.Integer, java.util.Date");
|
||||
context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition());
|
||||
context.refresh();
|
||||
|
||||
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
|
||||
assertSame(context.getBean(ConversionService.class),
|
||||
TestUtils.getPropertyValue(channel, "messageConverter.conversionService"));
|
||||
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
|
||||
assertEquals(1, channel.receive().getPayload());
|
||||
context.close();
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.integration.config.xml;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -25,7 +26,7 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -42,12 +43,12 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)
|
||||
@Qualifier(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)
|
||||
private ConversionService conversionService;
|
||||
|
||||
@Test
|
||||
public void testConversionServiceAvailability(){
|
||||
Assert.isTrue(applicationContext.getBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME).equals(conversionService));
|
||||
Assert.isTrue(applicationContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME).equals(conversionService));
|
||||
Assert.isTrue(conversionService.canConvert(TestBean1.class, TestBean2.class));
|
||||
Assert.isTrue(conversionService.canConvert(TestBean1.class, TestBean3.class));
|
||||
}
|
||||
@@ -60,8 +61,8 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
|
||||
childContext.refresh();
|
||||
|
||||
GenericConversionService conversionServiceParent = parentContext.getBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,GenericConversionService.class);
|
||||
GenericConversionService conversionServiceChild = childContext.getBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,GenericConversionService.class);
|
||||
GenericConversionService conversionServiceParent = parentContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,GenericConversionService.class);
|
||||
GenericConversionService conversionServiceChild = childContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,GenericConversionService.class);
|
||||
Assert.isTrue(conversionServiceParent == conversionServiceChild); // validating that they are pointing to the same object
|
||||
conversionServiceChild.addConverter(new TestConverter());
|
||||
conversionServiceChild.addConverter(new TestConverter3());
|
||||
@@ -72,7 +73,7 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
|
||||
private static class TestBean1 {
|
||||
|
||||
private String text;
|
||||
private final String text;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public TestBean1(String text) {
|
||||
@@ -83,26 +84,28 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
|
||||
private static class TestBean2 {
|
||||
|
||||
private String text;
|
||||
private final String text;
|
||||
|
||||
public TestBean2(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
// called by router for channel name
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.text.replace("-TEST", "_TARGET_CHANNEL");
|
||||
}
|
||||
}
|
||||
private static class TestBean3 {
|
||||
|
||||
private String text;
|
||||
private final String text;
|
||||
|
||||
public TestBean3(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
// called by router for channel name
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.text.replace("-TEST", "_TARGET_CHANNEL");
|
||||
}
|
||||
@@ -110,6 +113,7 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
|
||||
private static class TestConverter implements Converter<TestBean1, TestBean2> {
|
||||
|
||||
@Override
|
||||
public TestBean2 convert(TestBean1 source) {
|
||||
return new TestBean2(source.text.toUpperCase());
|
||||
}
|
||||
@@ -117,6 +121,7 @@ public class ConverterParserWithExistingConversionServiceTests {
|
||||
|
||||
private static class TestConverter3 implements Converter<TestBean1, TestBean3> {
|
||||
|
||||
@Override
|
||||
public TestBean3 convert(TestBean1 source) {
|
||||
return new TestBean3(source.text.toUpperCase());
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ public class ExpressionUtilsTests {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME,
|
||||
new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
|
||||
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
context.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
new RootBeanDefinition(ConversionServiceFactoryBean.class));
|
||||
context.refresh();
|
||||
StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context);
|
||||
@@ -71,7 +72,7 @@ public class ExpressionUtilsTests {
|
||||
@Test
|
||||
public void testEvaluationContextNoFactoryBean() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
context.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
new RootBeanDefinition(ConversionServiceFactoryBean.class));
|
||||
context.refresh();
|
||||
StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context);
|
||||
@@ -80,7 +81,7 @@ public class ExpressionUtilsTests {
|
||||
assertNotNull(typeConverter);
|
||||
assertNotSame(TestUtils.getPropertyValue(typeConverter, "defaultConversionService"),
|
||||
TestUtils.getPropertyValue(typeConverter, "conversionService"));
|
||||
assertSame(context.getBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME),
|
||||
assertSame(context.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME),
|
||||
TestUtils.getPropertyValue(typeConverter, "conversionService"));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
@@ -91,7 +91,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
cs.addConverter(stringToByteConverter);
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, cs);
|
||||
bf.registerSingleton(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, cs);
|
||||
|
||||
proxyFactory.setBeanFactory(bf);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
|
||||
@@ -36,9 +36,9 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
@@ -78,13 +78,14 @@ public class RouterConcurrencyTest {
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
doAnswer(new Answer<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (beanCounter.getAndIncrement() < 2) {
|
||||
semaphore.tryAcquire(4, TimeUnit.SECONDS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}).when(beanFactory).containsBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME);
|
||||
}).when(beanFactory).containsBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME);
|
||||
router.setBeanFactory(beanFactory);
|
||||
|
||||
ExecutorService exec = Executors.newFixedThreadPool(2);
|
||||
@@ -92,6 +93,7 @@ public class RouterConcurrencyTest {
|
||||
new ArrayList<ConversionService>());
|
||||
Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ConversionService requiredConversionService = router.getRequiredConversionService();
|
||||
returns.add(requiredConversionService);
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterRegistry;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class MapToObjectTransformerTests {
|
||||
MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class);
|
||||
BeanFactory beanFactory = this.getBeanFactory();
|
||||
ConverterRegistry conversionService =
|
||||
beanFactory.getBean(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConverterRegistry.class);
|
||||
beanFactory.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConverterRegistry.class);
|
||||
conversionService.addConverter(new StringToAddressConverter());
|
||||
transformer.setBeanFactory(beanFactory);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class MapToObjectTransformerTests {
|
||||
|
||||
private BeanFactory getBeanFactory() {
|
||||
GenericApplicationContext ctx = TestUtils.createTestApplicationContext();
|
||||
ctx.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
ctx.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
|
||||
new RootBeanDefinition("org.springframework.integration.context.CustomConversionServiceFactoryBean"));
|
||||
ctx.refresh();
|
||||
return ctx;
|
||||
@@ -183,6 +183,7 @@ public class MapToObjectTransformerTests {
|
||||
|
||||
public class StringToAddressConverter implements Converter<String, Address> {
|
||||
|
||||
@Override
|
||||
public Address convert(String source) {
|
||||
Address address = new Address();
|
||||
address.setStreet(source);
|
||||
|
||||
@@ -47,8 +47,8 @@ import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.mapping.HeaderMapper;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -402,7 +402,7 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.beanFactory != null){
|
||||
this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory);
|
||||
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.integration.transformer.support.HeaderValueMessageProcessor;
|
||||
import org.springframework.integration.util.BeanFactoryTypeConverter;
|
||||
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
|
||||
@@ -86,7 +86,7 @@ public class XPathExpressionEvaluatingHeaderValueMessageProcessor implements Hea
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
ConversionService conversionService = IntegrationUtils.getConversionService(beanFactory);
|
||||
if (conversionService != null) {
|
||||
this.typeConverter.setConversionService(conversionService);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user