JmsTargetAdapter is now JmsTarget. JmsTargetParser (f.k.a. JmsTargetAdapterParser) no longer creates the endpoint (just the target).

This commit is contained in:
Mark Fisher
2008-04-29 21:20:30 +00:00
parent a263ad4451
commit 15ead1c3ad
11 changed files with 96 additions and 142 deletions

View File

@@ -6,7 +6,7 @@ ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
httpinvoker-source=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerSourceAdapterParser
httpinvoker-target=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerTargetAdapterParser
jms-source=org.springframework.integration.adapter.jms.config.JmsSourceAdapterParser
jms-target=org.springframework.integration.adapter.jms.config.JmsTargetAdapterParser
jms-target=org.springframework.integration.adapter.jms.config.JmsTargetParser
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
rmi-source=org.springframework.integration.adapter.rmi.config.RmiSourceAdapterParser
rmi-target=org.springframework.integration.adapter.rmi.config.RmiTargetAdapterParser

View File

@@ -95,7 +95,7 @@
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a jms-based target channel adapter.
Defines a target that sends JMS Messages.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
@@ -103,7 +103,6 @@
<xsd:attribute name="connection-factory" type="xsd:string"/>
<xsd:attribute name="destination" type="xsd:string"/>
<xsd:attribute name="destination-name" type="xsd:string"/>
<xsd:attribute name="channel" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -24,25 +24,25 @@ import org.springframework.integration.message.Target;
import org.springframework.jms.core.JmsTemplate;
/**
* A target adapter for sending JMS Messages.
* A target for sending JMS Messages.
*
* @author Mark Fisher
*/
public class JmsTargetAdapter extends AbstractJmsTemplateBasedAdapter implements Target {
public class JmsTarget extends AbstractJmsTemplateBasedAdapter implements Target {
public JmsTargetAdapter(JmsTemplate jmsTemplate) {
public JmsTarget(JmsTemplate jmsTemplate) {
super(jmsTemplate);
}
public JmsTargetAdapter(ConnectionFactory connectionFactory, Destination destination) {
public JmsTarget(ConnectionFactory connectionFactory, Destination destination) {
super(connectionFactory, destination);
}
public JmsTargetAdapter(ConnectionFactory connectionFactory, String destinationName) {
public JmsTarget(ConnectionFactory connectionFactory, String destinationName) {
super(connectionFactory, destinationName);
}
public JmsTargetAdapter() {
public JmsTarget() {
super();
}

View File

@@ -44,10 +44,6 @@ public abstract class JmsAdapterParserUtils {
public static final String DESTINATION_NAME_PROPERTY = "destinationName";
public static final String CHANNEL_ATTRIBUTE = "channel";
public static final String CHANNEL_PROPERTY = "channel";
public static String determineConnectionFactoryBeanName(Element element) {
String connectionFactoryBeanName = "connectionFactory";

View File

@@ -19,15 +19,10 @@ package org.springframework.integration.adapter.jms.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.adapter.jms.JmsTargetAdapter;
import org.springframework.integration.endpoint.TargetEndpoint;
import org.springframework.integration.scheduling.Subscription;
import org.springframework.integration.adapter.jms.JmsTarget;
import org.springframework.util.StringUtils;
/**
@@ -35,13 +30,10 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
private static final String SUBSCRIPTION_PROPERTY = "subscription";
public class JmsTargetParser extends AbstractSingleBeanDefinitionParser {
protected Class<?> getBeanClass(Element element) {
return TargetEndpoint.class;
return JmsTarget.class;
}
protected boolean shouldGenerateId() {
@@ -56,7 +48,6 @@ public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
String jmsTemplate = element.getAttribute(JmsAdapterParserUtils.JMS_TEMPLATE_ATTRIBUTE);
String destination = element.getAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
String destinationName = element.getAttribute(JmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
RootBeanDefinition adapterDef = new RootBeanDefinition(JmsTargetAdapter.class);
if (StringUtils.hasText(jmsTemplate)) {
if (element.hasAttribute(JmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
element.hasAttribute(JmsAdapterParserUtils.DESTINATION_ATTRIBUTE) ||
@@ -64,31 +55,22 @@ public class JmsTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
throw new BeanCreationException("when providing a 'jms-template' reference, none of " +
"'connection-factory', 'destination', or 'destination-name' should be provided.");
}
adapterDef.getPropertyValues().addPropertyValue(
JmsAdapterParserUtils.JMS_TEMPLATE_PROPERTY, new RuntimeBeanReference(jmsTemplate));
builder.addPropertyReference(JmsAdapterParserUtils.JMS_TEMPLATE_PROPERTY, jmsTemplate);
}
else if (StringUtils.hasText(destination) ^ StringUtils.hasText(destinationName)) {
adapterDef.getPropertyValues().addPropertyValue(JmsAdapterParserUtils.CONNECTION_FACTORY_PROPERTY,
new RuntimeBeanReference(JmsAdapterParserUtils.determineConnectionFactoryBeanName(element)));
builder.addPropertyReference(JmsAdapterParserUtils.CONNECTION_FACTORY_PROPERTY,
JmsAdapterParserUtils.determineConnectionFactoryBeanName(element));
if (StringUtils.hasText(destination)) {
adapterDef.getPropertyValues().addPropertyValue(
JmsAdapterParserUtils.DESTINATION_PROPERTY, new RuntimeBeanReference(destination));
builder.addPropertyReference(JmsAdapterParserUtils.DESTINATION_PROPERTY, destination);
}
else {
adapterDef.getPropertyValues().addPropertyValue(
JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
builder.addPropertyValue(JmsAdapterParserUtils.DESTINATION_NAME_PROPERTY, destinationName);
}
}
else {
throw new BeanCreationException("Either a 'jms-template' reference or " +
"one of 'destination' or 'destination-name' attributes must be provided.");
}
String channel = element.getAttribute(JmsAdapterParserUtils.CHANNEL_ATTRIBUTE);
Subscription subscription = new Subscription(channel);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
builder.addConstructorArgReference(adapterBeanName);
builder.addPropertyValue(SUBSCRIPTION_PROPERTY, subscription);
}
}

View File

@@ -1,75 +0,0 @@
/*
* 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.adapter.jms.config;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.adapter.jms.JmsTargetAdapter;
import org.springframework.integration.endpoint.TargetEndpoint;
/**
* @author Mark Fisher
*/
public class JmsTargetAdapterParserTests {
@Test
public void testTargetAdapterWithConnectionFactoryAndDestination() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetAdapterWithConnectionFactoryAndDestination.xml", this.getClass());
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
assertEquals("adapter", endpoint.getName());
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
}
@Test
public void testTargetAdapterWithConnectionFactoryAndDestinationName() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetAdapterWithConnectionFactoryAndDestinationName.xml", this.getClass());
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
assertEquals("adapter", endpoint.getName());
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
}
@Test
public void testTargetAdapterWithDefaultConnectionFactory() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetAdapterWithDefaultConnectionFactory.xml", this.getClass());
TargetEndpoint endpoint = (TargetEndpoint) context.getBean("adapter");
assertEquals(JmsTargetAdapter.class, endpoint.getTarget().getClass());
assertEquals("adapter", endpoint.getName());
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
}
@Test(expected=BeanDefinitionStoreException.class)
public void testTargetAdapterWithEmptyConnectionFactory() {
try {
new ClassPathXmlApplicationContext("targetAdapterWithEmptyConnectionFactory.xml", this.getClass());
}
catch (RuntimeException e) {
assertEquals(BeanCreationException.class, e.getCause().getClass());
throw e;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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.adapter.jms.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.adapter.jms.JmsTarget;
/**
* @author Mark Fisher
*/
public class JmsTargetParserTests {
@Test
public void testTargetWithConnectionFactoryAndDestination() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetWithConnectionFactoryAndDestination.xml", this.getClass());
JmsTarget target = (JmsTarget) context.getBean("target");
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
}
@Test
public void testTargetWithConnectionFactoryAndDestinationName() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetWithConnectionFactoryAndDestinationName.xml", this.getClass());
JmsTarget target = (JmsTarget) context.getBean("target");
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
}
@Test
public void testTargetWithDefaultConnectionFactory() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"targetWithDefaultConnectionFactory.xml", this.getClass());
JmsTarget target = (JmsTarget) context.getBean("target");
DirectFieldAccessor accessor = new DirectFieldAccessor(target);
assertNotNull(accessor.getPropertyValue("jmsTemplate"));
}
@Test(expected=BeanDefinitionStoreException.class)
public void testTargetWithEmptyConnectionFactory() {
try {
new ClassPathXmlApplicationContext("targetWithEmptyConnectionFactory.xml", this.getClass());
}
catch (RuntimeException e) {
assertEquals(BeanCreationException.class, e.getCause().getClass());
throw e;
}
}
}

View File

@@ -7,14 +7,9 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<si:message-bus/>
<si:channel id="testChannel"/>
<si:jms-target id="adapter"
<si:jms-target id="target"
connection-factory="testConnectionFactory"
destination="testDestination"
channel="testChannel"/>
destination="testDestination"/>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -7,14 +7,9 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<si:message-bus/>
<si:channel id="testChannel"/>
<si:jms-target id="adapter"
<si:jms-target id="target"
connection-factory="testConnectionFactory"
destination-name="queue.test"
channel="testChannel"/>
destination-name="queue.test"/>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -7,13 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<si:message-bus/>
<si:channel id="testChannel"/>
<si:jms-target id="adapter"
destination="testDestination"
channel="testChannel"/>
<si:jms-target id="target" destination="testDestination"/>
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg>

View File

@@ -7,14 +7,9 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<si:message-bus/>
<si:channel id="testChannel"/>
<si:jms-target id="adapter"
<si:jms-target id="target"
connection-factory=""
destination="testDestination"
channel="testChannel"/>
destination="testDestination"/>
<bean id="testDestination" class="org.springframework.integration.adapter.jms.StubDestination"/>