From 928b6b8bc37b73bafa28fa2ff62d22fa256cbe4a Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 29 Oct 2013 10:19:21 +0200 Subject: [PATCH] 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. --- .../integration/amqp/outbound/AmqpOutboundEndpoint.java | 7 +++---- .../springframework/integration/filter/MessageFilter.java | 3 +-- .../handler/AbstractReplyProducingMessageHandler.java | 7 ++++++- .../springframework/integration/handler/DelayHandler.java | 3 +-- .../integration/handler/ServiceActivatingHandler.java | 3 +-- .../splitter/AbstractMessageProcessingSplitter.java | 7 +++---- .../integration/transformer/ContentEnricher.java | 3 +-- .../transformer/MessageTransformingHandler.java | 5 ++--- .../integration/file/FileWritingMessageHandler.java | 4 +--- .../remote/gateway/AbstractRemoteFileOutboundGateway.java | 3 +-- .../remote/gateway/RemoteFileOutboundGatewayTests.java | 4 ++-- .../http/outbound/HttpRequestExecutingMessageHandler.java | 3 +-- .../integration/jdbc/JdbcOutboundGateway.java | 6 ++---- .../integration/jdbc/StoredProcOutboundGateway.java | 5 ++--- .../integration/jdbc/JdbcOutboundGatewayTests.java | 7 +++---- .../integration/jms/JmsOutboundGateway.java | 3 +-- .../integration/jmx/OperationInvokingMessageHandler.java | 3 +-- .../integration/jpa/outbound/JpaOutboundGateway.java | 6 +----- .../integration/ws/AbstractWebServiceOutboundGateway.java | 3 +-- 19 files changed, 34 insertions(+), 51 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java index 5387b7c2e6..52d6b038fe 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java @@ -82,8 +82,7 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler private volatile MessageChannel returnChannel; @Override - protected void onInit() { - super.onInit(); + protected void doInit() { Assert.state(exchangeNameExpression == null || exchangeName == null, "Either an exchangeName or an exchangeNameExpression can be provided, but not both"); Assert.state(this.confirmCorrelationExpression == null || !this.expectReply, @@ -116,7 +115,7 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler } if (this.returnChannel != null) { 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, 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(); Object returnedObject = converter.fromMessage(message); MessageBuilder builder = (returnedObject instanceof Message) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java index a40e1fe12a..3bc0829ea0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -98,8 +98,7 @@ public class MessageFilter extends AbstractReplyProducingPostProcessingMessageHa } @Override - public final void onInit() { - super.onInit(); + protected void doInit() { if (this.selector instanceof AbstractMessageProcessingSelector) { ((AbstractMessageProcessingSelector) this.selector).setConversionService(this.getConversionService()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java index a16f66d383..fff0d7d976 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java @@ -19,6 +19,7 @@ package org.springframework.integration.handler; import java.util.List; import org.aopalliance.aop.Advice; + import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.integration.Message; @@ -114,7 +115,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa @Override - protected void onInit() { + protected final void onInit() { if (this.getBeanFactory() != null) { this.messagingTemplate.setBeanFactory(getBeanFactory()); } @@ -125,6 +126,10 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa } this.advisedRequestHandler = (RequestHandler) proxyFactory.getProxy(this.beanClassLoader); } + this.doInit(); + } + + protected void doInit() { } /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java index 304fdb9edb..0b2ed9a966 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java @@ -196,8 +196,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement } @Override - protected void onInit() { - super.onInit(); + protected void doInit() { if (this.messageStore == null) { this.messageStore = new SimpleMessageStore(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java index 5f8ea86936..124365c945 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java @@ -55,8 +55,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl } @Override - public final void onInit() { - super.onInit(); + protected void doInit() { if (processor instanceof AbstractMessageProcessor) { ((AbstractMessageProcessor) this.processor).setConversionService(this.getConversionService()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java index 2966fc1773..ad7b8e90be 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java @@ -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"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.util.Assert; /** * Base class for Message Splitter implementations that delegate to a * {@link MessageProcessor} instance. - * + * * @author Mark Fisher * @since 2.0 */ @@ -43,8 +43,7 @@ abstract class AbstractMessageProcessingSplitter extends AbstractMessageSplitter } @Override - public void onInit() { - super.onInit(); + protected void doInit() { ConversionService conversionService = this.getConversionService(); if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) { ((AbstractMessageProcessor) this.messageProcessor).setConversionService(conversionService); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java index 51800b2cca..b6d18c5173 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java @@ -194,8 +194,7 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem * the requestChannel is set. */ @Override - public void onInit() { - super.onInit(); + protected void doInit() { if (this.replyChannel != null) { Assert.notNull(this.requestChannel, "If the replyChannel is set, then the requestChannel must not be null"); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java index cb6289ea49..e742497118 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java @@ -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"); * you may not use this file except in compliance with the License. @@ -54,8 +54,7 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan } @Override - protected void onInit() { - super.onInit(); + protected void doInit() { if (this.getBeanFactory() != null && this.transformer instanceof BeanFactoryAware) { ((BeanFactoryAware) this.transformer).setBeanFactory(this.getBeanFactory()); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 35fe06a475..07db3a3ac4 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -218,9 +218,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand } @Override - public final void onInit() { - - super.onInit(); + protected void doInit() { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index a67874d05b..50c72d1698 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -286,8 +286,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply @Override - protected void onInit() { - super.onInit(); + protected void doInit() { Assert.notNull(this.command, "command must not be null"); if (Command.RM.equals(this.command) || Command.GET.equals(this.command)) { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java index eca3f97fa3..16a6171622 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java @@ -78,7 +78,7 @@ public class RemoteFileOutboundGatewayTests { (sessionFactory, "get", "payload"); gw.setFilter(new TestPatternFilter("")); try { - gw.onInit(); + gw.afterPropertiesSet(); fail("Exception expected"); } catch (IllegalArgumentException e) { @@ -93,7 +93,7 @@ public class RemoteFileOutboundGatewayTests { (sessionFactory, "rm", "payload"); gw.setFilter(new TestPatternFilter("")); try { - gw.onInit(); + gw.afterPropertiesSet(); fail("Exception expected"); } catch (IllegalArgumentException e) { diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java index d3c5e9b956..c83f7d45a7 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java @@ -291,8 +291,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe } @Override - public void onInit() { - super.onInit(); + protected void doInit() { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); ConversionService conversionService = this.getConversionService(); diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java index cd884207d3..b3f759a81c 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java @@ -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"); * you may not use this file except in compliance with the License. @@ -107,9 +107,7 @@ public class JdbcOutboundGateway extends AbstractReplyProducingMessageHandler im } @Override - protected void onInit() { - super.onInit(); - + protected void doInit() { if (this.maxRowsPerPoll != null) { Assert.notNull(poller, "If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'."); poller.setMaxRowsPerPoll(this.maxRowsPerPoll); diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcOutboundGateway.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcOutboundGateway.java index e396e67fc3..df4b076548 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcOutboundGateway.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcOutboundGateway.java @@ -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"); * 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. */ @Override - protected void onInit() { - super.onInit(); + protected void doInit() { }; @Override diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java index f8f128a658..955e6aa016 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java @@ -12,15 +12,14 @@ */ package org.springframework.integration.jdbc; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import javax.sql.DataSource; import org.junit.Assert; - -import static org.junit.Assert.assertEquals; - import org.junit.Test; + import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; @@ -42,7 +41,7 @@ public class JdbcOutboundGatewayTests { try { jdbcOutboundGateway.setMaxRowsPerPoll(10); - jdbcOutboundGateway.onInit(); + jdbcOutboundGateway.afterPropertiesSet(); } catch (IllegalArgumentException e) { assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage()); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index 9dd7cdb4ba..38a05ac5da 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -459,7 +459,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } @Override - public final void onInit() { + protected void doInit() { synchronized (this.initializationMonitor) { if (this.initialized) { return; @@ -469,7 +469,6 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp ^ this.requestDestinationName != null ^ this.requestDestinationExpressionProcessor != null, "Exactly one of 'requestDestination', 'requestDestinationName', or 'requestDestinationExpression' is required."); - super.onInit(); if (this.requestDestinationExpressionProcessor != null) { this.requestDestinationExpressionProcessor.setBeanFactory(getBeanFactory()); this.requestDestinationExpressionProcessor.setConversionService(getConversionService()); diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java index 7b2232c304..8f5c8ecc5b 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java @@ -102,9 +102,8 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa } @Override - public final void onInit() { + protected void doInit() { Assert.notNull(this.server, "MBeanServer is required."); - super.onInit(); } @Override diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java index d6b01970ad..96bdc790be 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/outbound/JpaOutboundGateway.java @@ -62,12 +62,8 @@ public class JpaOutboundGateway extends AbstractReplyProducingMessageHandler { } - /** - * - */ @Override - protected void onInit() { - super.onInit(); + protected void doInit() { this.jpaExecutor.setBeanFactory(this.getBeanFactory()); } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java index d56cafd855..14c23c9a55 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java @@ -144,8 +144,7 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro } @Override - public void onInit() { - super.onInit(); + protected void doInit() { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); Assert.state(this.destinationProvider == null || CollectionUtils.isEmpty(this.uriVariableExpressions), "uri variables are not supported when a DestinationProvider is supplied.");