INT-3402-3: Channels Late Resolution #3

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

* Add late resolution of channel names for the `MessagingGatewaySupport`
* Implement delegate logic for internal implementations like `ContentEnricher.Gateway`
This commit is contained in:
Artem Bilan
2014-08-21 11:16:01 +03:00
committed by Gary Russell
parent 1c051416ce
commit 7f74c571d4
6 changed files with 237 additions and 102 deletions

View File

@@ -56,9 +56,11 @@ import org.springframework.util.Assert;
* @author Mark Fisher
* @author Juergen Hoeller
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class ChannelPublishingJmsMessageListener
implements SessionAwareMessageListener<javax.jms.Message>, InitializingBean, TrackableComponent, BeanFactoryAware {
implements SessionAwareMessageListener<javax.jms.Message>, InitializingBean,
TrackableComponent, BeanFactoryAware {
protected final Log logger = LogFactory.getLog(getClass());
@@ -94,34 +96,45 @@ public class ChannelPublishingJmsMessageListener
/**
* Specify whether a JMS reply Message is expected.
*
* @param expectReply true if a reply is expected.
*/
public void setExpectReply(boolean expectReply) {
this.expectReply = expectReply;
}
public void setComponentName(String componentName){
public void setComponentName(String componentName) {
this.gatewayDelegate.setComponentName(componentName);
}
public void setRequestChannel(MessageChannel requestChannel){
public void setRequestChannel(MessageChannel requestChannel) {
this.gatewayDelegate.setRequestChannel(requestChannel);
}
public void setReplyChannel(MessageChannel replyChannel){
public void setRequestChannelName(String requestChannelName) {
gatewayDelegate.setRequestChannelName(requestChannelName);
}
public void setReplyChannel(MessageChannel replyChannel) {
this.gatewayDelegate.setReplyChannel(replyChannel);
}
public void setErrorChannel(MessageChannel errorChannel){
public void setReplyChannelName(String replyChannelName) {
gatewayDelegate.setReplyChannelName(replyChannelName);
}
public void setErrorChannel(MessageChannel errorChannel) {
this.gatewayDelegate.setErrorChannel(errorChannel);
}
public void setRequestTimeout(long requestTimeout){
public void setErrorChannelName(String errorChannelName) {
gatewayDelegate.setErrorChannelName(errorChannelName);
}
public void setRequestTimeout(long requestTimeout) {
this.gatewayDelegate.setRequestTimeout(requestTimeout);
}
public void setReplyTimeout(long replyTimeout){
public void setReplyTimeout(long replyTimeout) {
this.gatewayDelegate.setReplyTimeout(replyTimeout);
}
@@ -144,7 +157,6 @@ public class ChannelPublishingJmsMessageListener
* Set the default reply destination to send reply messages to. This will
* be applied in case of a request message that does not carry a
* "JMSReplyTo" field.
*
* @param defaultReplyDestination The default reply destination.
*/
public void setDefaultReplyDestination(Destination defaultReplyDestination) {
@@ -156,9 +168,7 @@ public class ChannelPublishingJmsMessageListener
* This will be applied in case of a request message that does not carry a
* "JMSReplyTo" field.
* <p>Alternatively, specify a JMS Destination object as "defaultReplyDestination".
*
* @param destinationName The default reply destination name.
*
* @see #setDestinationResolver
* @see #setDefaultReplyDestination(javax.jms.Destination)
*/
@@ -171,9 +181,7 @@ public class ChannelPublishingJmsMessageListener
* This will be applied in case of a request message that does not carry a
* "JMSReplyTo" field.
* <p>Alternatively, specify a JMS Destination object as "defaultReplyDestination".
*
* @param destinationName The default reply topic name.
*
* @see #setDestinationResolver
* @see #setDefaultReplyDestination(javax.jms.Destination)
*/
@@ -183,9 +191,7 @@ public class ChannelPublishingJmsMessageListener
/**
* Specify the time-to-live property for JMS reply Messages.
*
* @param replyTimeToLive The reply time to live.
*
* @see javax.jms.MessageProducer#setTimeToLive(long)
*/
public void setReplyTimeToLive(long replyTimeToLive) {
@@ -194,9 +200,7 @@ public class ChannelPublishingJmsMessageListener
/**
* Specify the priority value for JMS reply Messages.
*
* @param replyPriority The reply priority.
*
* @see javax.jms.MessageProducer#setPriority(int)
*/
public void setReplyPriority(int replyPriority) {
@@ -205,9 +209,7 @@ public class ChannelPublishingJmsMessageListener
/**
* Specify the delivery mode for JMS reply Messages.
*
* @param replyDeliveryPersistent true for a persistent reply message.
*
* @see javax.jms.MessageProducer#setDeliveryMode(int)
*/
public void setReplyDeliveryPersistent(boolean replyDeliveryPersistent) {
@@ -224,7 +226,6 @@ public class ChannelPublishingJmsMessageListener
* instead, then this value should be set to "JMSCorrelationID".
* Any other value will be treated as a JMS String Property to be copied as-is
* from the request Message into the reply Message with the same property name.
*
* @param correlationKey The correlation key.
*/
public void setCorrelationKey(String correlationKey) {
@@ -234,7 +235,6 @@ public class ChannelPublishingJmsMessageListener
/**
* Specify whether explicit QoS should be enabled for replies
* (for timeToLive, priority, and deliveryMode settings).
*
* @param explicitQosEnabledForReplies true to enable explicit QoS.
*/
public void setExplicitQosEnabledForReplies(boolean explicitQosEnabledForReplies) {
@@ -246,9 +246,7 @@ public class ChannelPublishingJmsMessageListener
* destination names for this listener.
* <p>The default resolver is a DynamicDestinationResolver. Specify a
* JndiDestinationResolver for resolving destination names as JNDI locations.
*
* @param destinationResolver The destination resolver.
*
* @see org.springframework.jms.support.destination.DynamicDestinationResolver
* @see org.springframework.jms.support.destination.JndiDestinationResolver
*/
@@ -262,7 +260,6 @@ public class ChannelPublishingJmsMessageListener
* converting between JMS Messages and Spring Integration Messages.
* If none is provided, a {@link SimpleMessageConverter} will
* be used.
*
* @param messageConverter The message converter.
*/
public void setMessageConverter(MessageConverter messageConverter) {
@@ -273,7 +270,6 @@ public class ChannelPublishingJmsMessageListener
* Provide a {@link JmsHeaderMapper} implementation to use when
* converting between JMS Messages and Spring Integration Messages.
* If none is provided, a {@link DefaultJmsHeaderMapper} will be used.
*
* @param headerMapper The header mapper.
*/
public void setHeaderMapper(JmsHeaderMapper headerMapper) {
@@ -285,7 +281,6 @@ public class ChannelPublishingJmsMessageListener
* to converting into a Spring Integration Message. This value is set to
* <code>true</code> by default. To send the JMS Message itself as a
* Spring Integration Message payload, set this to <code>false</code>.
*
* @param extractRequestPayload true if the request payload should be extracted.
*/
public void setExtractRequestPayload(boolean extractRequestPayload) {
@@ -297,7 +292,6 @@ public class ChannelPublishingJmsMessageListener
* extracted prior to converting into a JMS Message. This value is set to
* <code>true</code> by default. To send the Spring Integration Message
* itself as the JMS Message's body, set this to <code>false</code>.
*
* @param extractReplyPayload true if the reply payload should be extracted.
*/
public void setExtractReplyPayload(boolean extractReplyPayload) {
@@ -315,7 +309,8 @@ public class ChannelPublishingJmsMessageListener
if (this.extractRequestPayload) {
result = this.messageConverter.fromMessage(jmsMessage);
if (logger.isDebugEnabled()) {
logger.debug("converted JMS Message [" + jmsMessage + "] to integration Message payload [" + result + "]");
logger.debug("converted JMS Message [" + jmsMessage + "] to integration Message payload ["
+ result + "]");
}
}
@@ -356,7 +351,7 @@ public class ChannelPublishingJmsMessageListener
}
@Override
public void afterPropertiesSet() {
public void afterPropertiesSet() {
if (this.beanFactory != null) {
this.gatewayDelegate.setBeanFactory(this.beanFactory);
}
@@ -364,15 +359,16 @@ public class ChannelPublishingJmsMessageListener
this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory);
}
protected void start(){
protected void start() {
this.gatewayDelegate.start();
}
protected void stop(){
protected void stop() {
this.gatewayDelegate.stop();
}
private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage) throws JMSException {
private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage)
throws JMSException {
if (this.correlationKey != null) {
if (this.correlationKey.equals("JMSCorrelationID")) {
replyMessage.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
@@ -383,7 +379,8 @@ public class ChannelPublishingJmsMessageListener
replyMessage.setStringProperty(this.correlationKey, value);
}
else if (logger.isWarnEnabled()) {
logger.warn("No property value available on request Message for correlationKey '" + this.correlationKey + "'");
logger.warn("No property value available on request Message for correlationKey '"
+ this.correlationKey + "'");
}
}
}
@@ -442,7 +439,8 @@ public class ChannelPublishingJmsMessageListener
return null;
}
private void sendReply(javax.jms.Message replyMessage, Destination destination, Session session) throws JMSException {
private void sendReply(javax.jms.Message replyMessage, Destination destination, Session session)
throws JMSException {
MessageProducer producer = session.createProducer(destination);
try {
if (this.explicitQosEnabledForReplies) {
@@ -471,6 +469,7 @@ public class ChannelPublishingJmsMessageListener
this.name = name;
this.isTopic = isTopic;
}
}
private class GatewayDelegate extends MessagingGatewaySupport {
@@ -494,5 +493,7 @@ public class ChannelPublishingJmsMessageListener
return "jms:message-driven-channel-adapter";
}
}
}
}