Added namespace support for <jms:outbound-gateway/> and updated the GatewayDemo sample (INT-429).
This commit is contained in:
@@ -18,19 +18,23 @@ package org.springframework.integration.jms;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.QueueRequestor;
|
||||
import javax.jms.QueueSession;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractReplyProducingMessageConsumer;
|
||||
import org.springframework.integration.endpoint.ReplyMessageHolder;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.SessionCallback;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -38,22 +42,31 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsOutboundGateway extends AbstractReplyProducingMessageConsumer {
|
||||
public class JmsOutboundGateway extends AbstractReplyProducingMessageConsumer implements InitializingBean {
|
||||
|
||||
private volatile Queue jmsQueue;
|
||||
|
||||
private volatile JmsTemplate jmsTemplate;
|
||||
|
||||
private volatile MessageConverter messageConverter;
|
||||
|
||||
private final JmsTemplate jmsTemplate = new JmsTemplate();
|
||||
|
||||
|
||||
public void setJmsQueue(Queue jmsQueue) {
|
||||
this.jmsQueue = jmsQueue;
|
||||
}
|
||||
|
||||
public void setJmsTemplate(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
this.messageConverter = new HeaderMappingMessageConverter(jmsTemplate.getMessageConverter());
|
||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
this.jmsTemplate.setConnectionFactory(connectionFactory);
|
||||
}
|
||||
|
||||
public void setReplyChannel(MessageChannel replyChannel) {
|
||||
this.setOutputChannel(replyChannel);
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
this.jmsTemplate.afterPropertiesSet();
|
||||
Assert.notNull(this.jmsQueue, "jmsQueue must not be null");
|
||||
this.messageConverter = new HeaderMappingMessageConverter(new SimpleMessageConverter());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +76,6 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageConsumer {
|
||||
public Object doInJms(Session session) throws JMSException {
|
||||
Assert.state(session instanceof QueueSession,
|
||||
"QueueSession is required for the outbound JMS Gateway");
|
||||
Assert.state(jmsQueue != null, "Queue is required");
|
||||
javax.jms.Message jmsRequest = (messageConverter != null)
|
||||
? messageConverter.toMessage(requestMessage, session)
|
||||
: session.createObjectMessage((Serializable) requestMessage);
|
||||
|
||||
@@ -30,6 +30,7 @@ public class JmsNamespaceHandler extends NamespaceHandlerSupport {
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("inbound-gateway", new JmsInboundGatewayParser());
|
||||
this.registerBeanDefinitionParser("inbound-channel-adapter", new JmsInboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("outbound-gateway", new JmsOutboundGatewayParser());
|
||||
this.registerBeanDefinitionParser("outbound-channel-adapter", new JmsOutboundChannelAdapterParser());
|
||||
this.registerBeanDefinitionParser("header-enricher", new SimpleHeaderEnricherParser(
|
||||
JmsHeaders.TRANSPORT_PREFIX, new String[] { "reply-to" }));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jms.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.jms.JmsOutboundGateway;
|
||||
|
||||
/**
|
||||
* Parser for the <outbound-gateway> element of the integration 'jms' namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class JmsOutboundGatewayParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
@Override
|
||||
protected String getInputChannelAttributeName() {
|
||||
return "request-channel";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BeanDefinitionBuilder parseConsumer(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JmsOutboundGateway.class);
|
||||
builder.addPropertyReference("connectionFactory", element.getAttribute("connection-factory"));
|
||||
builder.addPropertyReference("jmsQueue", element.getAttribute("jms-queue"));
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel");
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@
|
||||
<xsd:element name="inbound-gateway">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a JMS-based gateway adapter.
|
||||
Defines an inbound JMS-based Messaging Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
@@ -62,6 +62,23 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="outbound-gateway">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an outbound JMS-based Messaging Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="jms-queue" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="connection-factory" type="xsd:string" default="connectionFactory"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="outbound-channel-adapter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
|
||||
@@ -19,19 +19,7 @@
|
||||
|
||||
<channel id="stdinToJmsoutChannel"/>
|
||||
|
||||
<beans:bean class="org.springframework.integration.endpoint.SubscribingConsumerEndpoint">
|
||||
<beans:constructor-arg ref="jmsOutGateway"/>
|
||||
<beans:constructor-arg ref="stdinToJmsoutChannel"/>
|
||||
</beans:bean>
|
||||
<beans:bean id="jmsOutGateway" class="org.springframework.integration.jms.JmsOutboundGateway">
|
||||
<beans:property name="jmsTemplate">
|
||||
<beans:bean class="org.springframework.jms.core.JmsTemplate">
|
||||
<beans:property name="connectionFactory" ref="connectionFactory"/>
|
||||
</beans:bean>
|
||||
</beans:property>
|
||||
<beans:property name="jmsQueue" ref="demoQueue"/>
|
||||
<beans:property name="outputChannel" ref="jmsReplyToStdoutChannel"/>
|
||||
</beans:bean>
|
||||
<jms:outbound-gateway request-channel="stdinToJmsoutChannel" jms-queue="demoQueue" reply-channel="jmsReplyToStdoutChannel"/>
|
||||
|
||||
<channel id="jmsReplyToStdoutChannel"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user