INT-1363 JmsSendingMessageHandler no longer extends from AbstractJmsTemplateBasedAdapter
This commit is contained in:
@@ -35,8 +35,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectSupport {
|
||||
|
||||
private volatile boolean extractPayload = true;
|
||||
|
||||
private volatile ConnectionFactory connectionFactory;
|
||||
|
||||
private volatile Destination destination;
|
||||
@@ -87,18 +85,7 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
public AbstractJmsTemplateBasedAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether the payload should be extracted from each received JMS
|
||||
* Message to be used as the Spring Integration Message payload.
|
||||
*
|
||||
* <p>The default value is <code>true</code>. To force creation of Spring
|
||||
* Integration Messages whose payload is the actual JMS Message, set this
|
||||
* to <code>false</code>.
|
||||
*/
|
||||
public void setExtractPayload(boolean extractPayload) {
|
||||
this.extractPayload = extractPayload;
|
||||
}
|
||||
|
||||
|
||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
@@ -228,8 +215,4 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
protected boolean shouldExtractPayload() {
|
||||
return extractPayload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@ package org.springframework.integration.jms;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.history.TrackableComponent;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.MessagePostProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A MessageConsumer that sends the converted Message payload within a JMS Message.
|
||||
@@ -33,63 +31,68 @@ import org.springframework.jms.core.MessagePostProcessor;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class JmsSendingMessageHandler extends AbstractJmsTemplateBasedAdapter implements MessageHandler, TrackableComponent, Ordered {
|
||||
public class JmsSendingMessageHandler extends AbstractMessageHandler {
|
||||
|
||||
private volatile int order = Ordered.LOWEST_PRECEDENCE;
|
||||
private final JmsTemplate jmsTemplate;
|
||||
|
||||
private volatile boolean shouldTrack;
|
||||
private volatile Destination destination;
|
||||
|
||||
private volatile String destinationName;
|
||||
|
||||
private volatile JmsHeaderMapper headerMapper = new DefaultJmsHeaderMapper();
|
||||
|
||||
private volatile boolean extractPayload = true;
|
||||
|
||||
|
||||
public JmsSendingMessageHandler(JmsTemplate jmsTemplate) {
|
||||
super(jmsTemplate);
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
public void setDestination(Destination destination) {
|
||||
Assert.isNull(this.destinationName, "The 'destination' and 'destinationName' properties are mutually exclusive.");
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public void setDestinationName(String destinationName) {
|
||||
Assert.isNull(this.destination, "The 'destination' and 'destinationName' properties are mutually exclusive.");
|
||||
this.destinationName = destinationName;
|
||||
}
|
||||
|
||||
public void setHeaderMapper(JmsHeaderMapper headerMapper) {
|
||||
this.headerMapper = headerMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* No-arg constructor provided for convenience when configuring with
|
||||
* setters. Note that the initialization callback will validate.
|
||||
* Specify whether the payload should be extracted from each integration
|
||||
* Message to be used as the JMS Message body.
|
||||
*
|
||||
* <p>The default value is <code>true</code>. To force passing of the full
|
||||
* Spring Integration Message instead, set this to <code>false</code>.
|
||||
*/
|
||||
public JmsSendingMessageHandler() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setShouldTrack(boolean shouldTrack) {
|
||||
this.shouldTrack = shouldTrack;
|
||||
public void setExtractPayload(boolean extractPayload) {
|
||||
this.extractPayload = extractPayload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentType() {
|
||||
return "jms:outbound-channel-adapter";
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public final void handleMessage(Message<?> message) {
|
||||
@Override
|
||||
protected void handleMessageInternal(final Message<?> message) throws Exception {
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException("message must not be null");
|
||||
}
|
||||
final Message<?> messageToSend = (this.shouldTrack) ? MessageHistory.write(message, this) : message;
|
||||
Object objectToSend = messageToSend;
|
||||
if (this.shouldExtractPayload()) {
|
||||
objectToSend = messageToSend.getPayload();
|
||||
Object objectToSend = (this.extractPayload) ? message.getPayload() : message;
|
||||
MessagePostProcessor messagePostProcessor = new HeaderMappingMessagePostProcessor(message, this.headerMapper);
|
||||
if (this.destination != null) {
|
||||
this.jmsTemplate.convertAndSend(this.destination, objectToSend, messagePostProcessor);
|
||||
}
|
||||
MessagePostProcessor messagePostProcessor = new HeaderMappingMessagePostProcessor(messageToSend, this.getHeaderMapper());
|
||||
Destination destination = this.getDestination();
|
||||
if (destination != null) {
|
||||
this.getJmsTemplate().convertAndSend(destination, objectToSend, messagePostProcessor);
|
||||
else if (this.destinationName != null) {
|
||||
this.jmsTemplate.convertAndSend(this.destinationName, objectToSend, messagePostProcessor);
|
||||
}
|
||||
else {
|
||||
String destinationName = this.getDestinationName();
|
||||
if (destinationName != null) {
|
||||
this.getJmsTemplate().convertAndSend(destinationName, objectToSend, messagePostProcessor);
|
||||
}
|
||||
else { // fallback to default destination of the template
|
||||
this.getJmsTemplate().convertAndSend(objectToSend, messagePostProcessor);
|
||||
}
|
||||
else { // fallback to default destination of the template
|
||||
this.jmsTemplate.convertAndSend(objectToSend, messagePostProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +114,5 @@ public class JmsSendingMessageHandler extends AbstractJmsTemplateBasedAdapter im
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,10 @@ abstract class JmsAdapterParserUtils {
|
||||
|
||||
static final String HEADER_MAPPER_PROPERTY = "headerMapper";
|
||||
|
||||
private static final String[] JMS_TEMPLATE_ATTRIBUTES = { "destination", "destination-name",
|
||||
"connection-factory", "message-converter", "destination-resolver", "time-to-live", "priority", "delivery-persistent", "explicit-qos-enabled" };
|
||||
private static final String[] JMS_TEMPLATE_ATTRIBUTES = {
|
||||
"connection-factory", "message-converter", "destination-resolver", "pub-sub-domain",
|
||||
"time-to-live", "priority", "delivery-persistent", "explicit-qos-enabled"
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
@@ -116,6 +118,7 @@ abstract class JmsAdapterParserUtils {
|
||||
JmsAdapterParserUtils.determineConnectionFactoryBeanName(element, parserContext));
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "pub-sub-domain");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "time-to-live");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "priority");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "delivery-persistent");
|
||||
|
||||
@@ -90,7 +90,6 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne
|
||||
}
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "selector", "messageSelector");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver");
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
String beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, parserContext.getRegistry());
|
||||
|
||||
Reference in New Issue
Block a user