INT-1698 GlobalChannelInterceptorBeanPostProcessor now does its processing *after* initialization so that it can apply to the results of FactoryBeans (as in the JMS Channel case)

This commit is contained in:
Mark Fisher
2010-12-17 16:15:40 -05:00
parent 96aab9bf28
commit 3131d217d1
3 changed files with 17 additions and 34 deletions

View File

@@ -73,6 +73,10 @@ final class GlobalChannelInterceptorBeanPostProcessor implements BeanPostProcess
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof MessageChannel) {
if (logger.isDebugEnabled()) {
logger.debug("Applying global interceptors on channel '" + beanName + "'");
@@ -82,10 +86,6 @@ final class GlobalChannelInterceptorBeanPostProcessor implements BeanPostProcess
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
/**
* Adds any interceptor whose pattern matches against the channel's name.
*/

View File

@@ -13,7 +13,6 @@
<int-jms:channel id="jmsChannel" queue="jmsQueue"/>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
@@ -23,8 +22,9 @@
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="jmsQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="jmsQueue.queue"/>
</bean>
</beans>

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.jms.config;
import static junit.framework.Assert.assertEquals;
@@ -21,54 +22,36 @@ import static junit.framework.Assert.assertTrue;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
*
* @author Mark Fisher
* @since 2.0.1
*/
public class GlobalChannelInterceptorTests {
@SuppressWarnings("rawtypes")
@Test
@Ignore
public void testJmsChannel(){
public void testJmsChannel() {
ActiveMqTestUtils.prepare();
ApplicationContext context = new ClassPathXmlApplicationContext("GlobalChannelInterceptorTests-context.xml",
GlobalChannelInterceptorTests.class);
ApplicationContext context = new ClassPathXmlApplicationContext(
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
AbstractMessageChannel jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
Object interceptors = TestUtils.getPropertyValue((TestUtils.getPropertyValue(jmsChannel, "interceptors")), "interceptors");
assertNotNull(interceptors);
assertTrue(interceptors instanceof List);
assertEquals(1, ((List)interceptors).size());
assertTrue(((List)interceptors).get(0) instanceof SampleInterceptor);
assertEquals(1, ((List<?>) interceptors).size());
assertTrue(((List<?>) interceptors).get(0) instanceof SampleInterceptor);
}
public static class SampleInterceptor implements ChannelInterceptor{
public Message<?> preSend(Message<?> message, MessageChannel channel) {
return message;
}
public void postSend(Message<?> message, MessageChannel channel,
boolean sent) {
}
public boolean preReceive(MessageChannel channel) {
return true;
}
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
return message;
}
public static class SampleInterceptor extends ChannelInterceptorAdapter {
}
}