INT-3319 Fix BeanFactory Propagation

JIRA: https://jira.spring.io/browse/INT-3319

The `MessageBuilderFactory` abstraction relies on the bean factory
being propagated to all classes that create messages.

Some classes were missed in the initial PR.
This commit is contained in:
Gary Russell
2014-03-11 16:24:29 -04:00
committed by Artem Bilan
parent 1c9bcaccee
commit 75af72a77c
39 changed files with 364 additions and 179 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-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.
@@ -16,16 +16,19 @@
package org.springframework.integration.file.config;
import org.springframework.integration.file.transformer.FileToByteArrayTransformer;
/**
* Parser for the <file-to-bytes-transformer> element.
*
*
* @author Mark Fisher
* @author Gary Russell
*/
public class FileToByteArrayTransformerParser extends AbstractFilePayloadTransformerParser {
@Override
protected String getTransformerClassName() {
return "org.springframework.integration.file.transformer.FileToByteArrayTransformer";
return FileToByteArrayTransformer.class.getName();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-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.
@@ -21,17 +21,19 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.file.transformer.FileToStringTransformer;
/**
* Parser for the <file-to-string-transformer> element.
*
*
* @author Mark Fisher
* @author Gary Russell
*/
public class FileToStringTransformerParser extends AbstractFilePayloadTransformerParser {
@Override
protected String getTransformerClassName() {
return "org.springframework.integration.file.transformer.FileToStringTransformer";
return FileToStringTransformer.class.getName();
}
@Override

View File

@@ -21,6 +21,10 @@ import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.support.DefaultMessageBuilderFactory;
import org.springframework.integration.support.MessageBuilderFactory;
@@ -34,7 +38,7 @@ import org.springframework.util.Assert;
*
* @author Mark Fisher
*/
public abstract class AbstractFilePayloadTransformer<T> implements Transformer {
public abstract class AbstractFilePayloadTransformer<T> implements Transformer, BeanFactoryAware {
private final Log logger = LogFactory.getLog(this.getClass());
@@ -52,9 +56,9 @@ public abstract class AbstractFilePayloadTransformer<T> implements Transformer {
this.deleteFiles = deleteFiles;
}
public void setMessageBuilderFactory(MessageBuilderFactory messageBuilderFactory) {
Assert.notNull(messageBuilderFactory, "'messageBuilderFactory' cannot be null");
this.messageBuilderFactory = messageBuilderFactory;
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.messageBuilderFactory = IntegrationContextUtils.getMessageBuilderFactory(beanFactory);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-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.
@@ -16,21 +16,25 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.transformer.FileToStringTransformer;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.integration.transformer.MessageTransformingHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
/**
* @author Mark Fisher
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -40,6 +44,9 @@ public class FileToStringTransformerParserTests {
@Qualifier("transformer")
EventDrivenConsumer endpoint;
@Autowired
MessageBuilderFactory messageBuilderFactory;
@Test
public void checkDeleteFilesValue() {
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint);
@@ -50,6 +57,7 @@ public class FileToStringTransformerParserTests {
handlerAccessor.getPropertyValue("transformer");
DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer);
assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles"));
assertSame(this.messageBuilderFactory, transformerAccessor.getPropertyValue("messageBuilderFactory"));
}
}