INT-2961 Make ARPMH.onInit() Final; Add doInit()
https://jira.springsource.org/browse/INT-2961 onInit() relied on subclasses calling super.onInit() to apply the advice chain and add the BeanFactory to the MessagingTemplate. At least one extension (smpp) failed to do this, disabling these features. Make onInit() final and call doInit() for subclass initialization (no-op in ARPMH). INT-2961 Polishing - do not increase visibility of doInit in subclasses. - remove final modifiers from doInit so user subclasses can participate in initialization if needed.
This commit is contained in:
committed by
Artem Bilan
parent
182b232fda
commit
928b6b8bc3
@@ -82,8 +82,7 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
|
|||||||
private volatile MessageChannel returnChannel;
|
private volatile MessageChannel returnChannel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
Assert.state(exchangeNameExpression == null || exchangeName == null,
|
Assert.state(exchangeNameExpression == null || exchangeName == null,
|
||||||
"Either an exchangeName or an exchangeNameExpression can be provided, but not both");
|
"Either an exchangeName or an exchangeNameExpression can be provided, but not both");
|
||||||
Assert.state(this.confirmCorrelationExpression == null || !this.expectReply,
|
Assert.state(this.confirmCorrelationExpression == null || !this.expectReply,
|
||||||
@@ -116,7 +115,7 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
|
|||||||
}
|
}
|
||||||
if (this.returnChannel != null) {
|
if (this.returnChannel != null) {
|
||||||
Assert.isTrue(amqpTemplate instanceof RabbitTemplate, "RabbitTemplate implementation is required for publisher returns");
|
Assert.isTrue(amqpTemplate instanceof RabbitTemplate, "RabbitTemplate implementation is required for publisher returns");
|
||||||
( (RabbitTemplate) this.amqpTemplate).setReturnCallback(this);
|
((RabbitTemplate) this.amqpTemplate).setReturnCallback(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +288,7 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
|
|||||||
|
|
||||||
public void returnedMessage(org.springframework.amqp.core.Message message, int replyCode, String replyText,
|
public void returnedMessage(org.springframework.amqp.core.Message message, int replyCode, String replyText,
|
||||||
String exchange, String routingKey) {
|
String exchange, String routingKey) {
|
||||||
// safe to cast; we asserted we have a RabbitTemplate in onInit()
|
// safe to cast; we asserted we have a RabbitTemplate in doInit()
|
||||||
MessageConverter converter = ((RabbitTemplate) this.amqpTemplate).getMessageConverter();
|
MessageConverter converter = ((RabbitTemplate) this.amqpTemplate).getMessageConverter();
|
||||||
Object returnedObject = converter.fromMessage(message);
|
Object returnedObject = converter.fromMessage(message);
|
||||||
MessageBuilder<?> builder = (returnedObject instanceof Message)
|
MessageBuilder<?> builder = (returnedObject instanceof Message)
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ public class MessageFilter extends AbstractReplyProducingPostProcessingMessageHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
if (this.selector instanceof AbstractMessageProcessingSelector) {
|
if (this.selector instanceof AbstractMessageProcessingSelector) {
|
||||||
((AbstractMessageProcessingSelector) this.selector).setConversionService(this.getConversionService());
|
((AbstractMessageProcessingSelector) this.selector).setConversionService(this.getConversionService());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.springframework.integration.handler;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.integration.Message;
|
import org.springframework.integration.Message;
|
||||||
@@ -114,7 +115,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected final void onInit() {
|
||||||
if (this.getBeanFactory() != null) {
|
if (this.getBeanFactory() != null) {
|
||||||
this.messagingTemplate.setBeanFactory(getBeanFactory());
|
this.messagingTemplate.setBeanFactory(getBeanFactory());
|
||||||
}
|
}
|
||||||
@@ -125,6 +126,10 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
|
|||||||
}
|
}
|
||||||
this.advisedRequestHandler = (RequestHandler) proxyFactory.getProxy(this.beanClassLoader);
|
this.advisedRequestHandler = (RequestHandler) proxyFactory.getProxy(this.beanClassLoader);
|
||||||
}
|
}
|
||||||
|
this.doInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -196,8 +196,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
if (this.messageStore == null) {
|
if (this.messageStore == null) {
|
||||||
this.messageStore = new SimpleMessageStore();
|
this.messageStore = new SimpleMessageStore();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
if (processor instanceof AbstractMessageProcessor) {
|
if (processor instanceof AbstractMessageProcessor) {
|
||||||
((AbstractMessageProcessor<?>) this.processor).setConversionService(this.getConversionService());
|
((AbstractMessageProcessor<?>) this.processor).setConversionService(this.getConversionService());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -43,8 +43,7 @@ abstract class AbstractMessageProcessingSplitter extends AbstractMessageSplitter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
ConversionService conversionService = this.getConversionService();
|
ConversionService conversionService = this.getConversionService();
|
||||||
if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) {
|
if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) {
|
||||||
((AbstractMessageProcessor<?>) this.messageProcessor).setConversionService(conversionService);
|
((AbstractMessageProcessor<?>) this.messageProcessor).setConversionService(conversionService);
|
||||||
|
|||||||
@@ -194,8 +194,7 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem
|
|||||||
* the requestChannel is set.
|
* the requestChannel is set.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
if (this.replyChannel != null) {
|
if (this.replyChannel != null) {
|
||||||
Assert.notNull(this.requestChannel, "If the replyChannel is set, then the requestChannel must not be null");
|
Assert.notNull(this.requestChannel, "If the replyChannel is set, then the requestChannel must not be null");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -54,8 +54,7 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
if (this.getBeanFactory() != null && this.transformer instanceof BeanFactoryAware) {
|
if (this.getBeanFactory() != null && this.transformer instanceof BeanFactoryAware) {
|
||||||
((BeanFactoryAware) this.transformer).setBeanFactory(this.getBeanFactory());
|
((BeanFactoryAware) this.transformer).setBeanFactory(this.getBeanFactory());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,9 +218,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onInit() {
|
protected void doInit() {
|
||||||
|
|
||||||
super.onInit();
|
|
||||||
|
|
||||||
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
||||||
|
|
||||||
|
|||||||
@@ -286,8 +286,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
Assert.notNull(this.command, "command must not be null");
|
Assert.notNull(this.command, "command must not be null");
|
||||||
if (Command.RM.equals(this.command) ||
|
if (Command.RM.equals(this.command) ||
|
||||||
Command.GET.equals(this.command)) {
|
Command.GET.equals(this.command)) {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class RemoteFileOutboundGatewayTests {
|
|||||||
(sessionFactory, "get", "payload");
|
(sessionFactory, "get", "payload");
|
||||||
gw.setFilter(new TestPatternFilter(""));
|
gw.setFilter(new TestPatternFilter(""));
|
||||||
try {
|
try {
|
||||||
gw.onInit();
|
gw.afterPropertiesSet();
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
@@ -93,7 +93,7 @@ public class RemoteFileOutboundGatewayTests {
|
|||||||
(sessionFactory, "rm", "payload");
|
(sessionFactory, "rm", "payload");
|
||||||
gw.setFilter(new TestPatternFilter(""));
|
gw.setFilter(new TestPatternFilter(""));
|
||||||
try {
|
try {
|
||||||
gw.onInit();
|
gw.afterPropertiesSet();
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -291,8 +291,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
||||||
|
|
||||||
ConversionService conversionService = this.getConversionService();
|
ConversionService conversionService = this.getConversionService();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -107,9 +107,7 @@ public class JdbcOutboundGateway extends AbstractReplyProducingMessageHandler im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
|
|
||||||
if (this.maxRowsPerPoll != null) {
|
if (this.maxRowsPerPoll != null) {
|
||||||
Assert.notNull(poller, "If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.");
|
Assert.notNull(poller, "If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.");
|
||||||
poller.setMaxRowsPerPoll(this.maxRowsPerPoll);
|
poller.setMaxRowsPerPoll(this.maxRowsPerPoll);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -88,8 +88,7 @@ public class StoredProcOutboundGateway extends AbstractReplyProducingMessageHand
|
|||||||
* when {@link ProcedureParameter} are passed in.
|
* when {@link ProcedureParameter} are passed in.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,15 +12,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.integration.jdbc;
|
package org.springframework.integration.jdbc;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.jdbc.core.JdbcOperations;
|
import org.springframework.jdbc.core.JdbcOperations;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ public class JdbcOutboundGatewayTests {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jdbcOutboundGateway.setMaxRowsPerPoll(10);
|
jdbcOutboundGateway.setMaxRowsPerPoll(10);
|
||||||
jdbcOutboundGateway.onInit();
|
jdbcOutboundGateway.afterPropertiesSet();
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
|
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onInit() {
|
protected void doInit() {
|
||||||
synchronized (this.initializationMonitor) {
|
synchronized (this.initializationMonitor) {
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
return;
|
return;
|
||||||
@@ -469,7 +469,6 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp
|
|||||||
^ this.requestDestinationName != null
|
^ this.requestDestinationName != null
|
||||||
^ this.requestDestinationExpressionProcessor != null,
|
^ this.requestDestinationExpressionProcessor != null,
|
||||||
"Exactly one of 'requestDestination', 'requestDestinationName', or 'requestDestinationExpression' is required.");
|
"Exactly one of 'requestDestination', 'requestDestinationName', or 'requestDestinationExpression' is required.");
|
||||||
super.onInit();
|
|
||||||
if (this.requestDestinationExpressionProcessor != null) {
|
if (this.requestDestinationExpressionProcessor != null) {
|
||||||
this.requestDestinationExpressionProcessor.setBeanFactory(getBeanFactory());
|
this.requestDestinationExpressionProcessor.setBeanFactory(getBeanFactory());
|
||||||
this.requestDestinationExpressionProcessor.setConversionService(getConversionService());
|
this.requestDestinationExpressionProcessor.setConversionService(getConversionService());
|
||||||
|
|||||||
@@ -102,9 +102,8 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onInit() {
|
protected void doInit() {
|
||||||
Assert.notNull(this.server, "MBeanServer is required.");
|
Assert.notNull(this.server, "MBeanServer is required.");
|
||||||
super.onInit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -62,12 +62,8 @@ public class JpaOutboundGateway extends AbstractReplyProducingMessageHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
this.jpaExecutor.setBeanFactory(this.getBeanFactory());
|
this.jpaExecutor.setBeanFactory(this.getBeanFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInit() {
|
protected void doInit() {
|
||||||
super.onInit();
|
|
||||||
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
|
||||||
Assert.state(this.destinationProvider == null || CollectionUtils.isEmpty(this.uriVariableExpressions),
|
Assert.state(this.destinationProvider == null || CollectionUtils.isEmpty(this.uriVariableExpressions),
|
||||||
"uri variables are not supported when a DestinationProvider is supplied.");
|
"uri variables are not supported when a DestinationProvider is supplied.");
|
||||||
|
|||||||
Reference in New Issue
Block a user