From 0b41c9a670f1ff7ec1e9618df5adadcdca9bdeec Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 4 May 2010 17:30:58 +0000 Subject: [PATCH] INT-8 added namespace support for Claim Check pattern --- .../config/xml/ClaimCheckInParser.java | 45 +++++++++ .../config/xml/ClaimCheckOutParser.java | 45 +++++++++ .../xml/IntegrationNamespaceHandler.java | 4 +- .../config/xml/spring-integration-2.0.xsd | 40 ++++++++ .../xml/ClaimCheckParserTests-context.xml | 32 +++++++ .../config/xml/ClaimCheckParserTests.java | 95 +++++++++++++++++++ 6 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java create mode 100644 org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java create mode 100644 org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests-context.xml create mode 100644 org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java new file mode 100644 index 0000000000..ee676e17ea --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2010 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.config.xml; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; + +/** + * Parser for the <claim-check-in/> element. + * + * @author Mark Fisher + * @since 2.0 + */ +public class ClaimCheckInParser extends AbstractTransformerParser { + + @Override + protected String getTransformerClassName() { + return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.ClaimCheckInTransformer"; + } + + @Override + protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + String messageStoreRef = element.getAttribute("message-store"); + Assert.hasText(messageStoreRef, "The 'message-store' attribute is required."); + builder.addConstructorArgReference(messageStoreRef); + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java new file mode 100644 index 0000000000..6ca5e3f719 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2010 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.config.xml; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; + +/** + * Parser for the <claim-check-out/> element. + * + * @author Mark Fisher + * @since 2.0 + */ +public class ClaimCheckOutParser extends AbstractTransformerParser { + + @Override + protected String getTransformerClassName() { + return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.ClaimCheckOutTransformer"; + } + + @Override + protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + String messageStoreRef = element.getAttribute("message-store"); + Assert.hasText(messageStoreRef, "The 'message-store' attribute is required."); + builder.addConstructorArgReference(messageStoreRef); + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java index 97cba5aef8..c55008e769 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -43,6 +43,8 @@ public class IntegrationNamespaceHandler extends AbstractIntegrationNamespaceHan registerBeanDefinitionParser("object-to-string-transformer", new ObjectToStringTransformerParser()); registerBeanDefinitionParser("payload-serializing-transformer", new PayloadSerializingTransformerParser()); registerBeanDefinitionParser("payload-deserializing-transformer", new PayloadDeserializingTransformerParser()); + registerBeanDefinitionParser("claim-check-in", new ClaimCheckInParser()); + registerBeanDefinitionParser("claim-check-out", new ClaimCheckOutParser()); registerBeanDefinitionParser("inbound-channel-adapter", new MethodInvokingInboundChannelAdapterParser()); registerBeanDefinitionParser("outbound-channel-adapter", new MethodInvokingOutboundChannelAdapterParser()); registerBeanDefinitionParser("logging-channel-adapter", new LoggingChannelAdapterParser()); diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index d6bcc7be0d..04aa91cf2c 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -1308,6 +1308,46 @@ + + + + Defines a Transformer that stores a Message and returns a new Message whose + payload is the id of the stored Message. + + + + + + + + Defines a Transformer that accepts a Message whose payload is a UUID and retrieves + the Message associated with that id from a MessageStore if available (else null). + + + + + + + + + + + + + + Reference to the MessageStore to be used by this Claim Check transformer. + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests-context.xml new file mode 100644 index 0000000000..430ebea0d3 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests-context.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java new file mode 100644 index 0000000000..288fde6602 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java @@ -0,0 +1,95 @@ +/* + * Copyright 2002-2010 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.config.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.channel.PollableChannel; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.endpoint.EventDrivenConsumer; +import org.springframework.integration.message.MessageBuilder; +import org.springframework.integration.store.MessageStore; +import org.springframework.integration.transformer.ClaimCheckInTransformer; +import org.springframework.integration.transformer.ClaimCheckOutTransformer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 2.0 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class ClaimCheckParserTests { + + @Autowired + private ApplicationContext context; + + @Autowired + private MessageChannel checkinChannel; + + @Autowired + private PollableChannel wiretap; + + @Autowired + private EventDrivenConsumer checkin; + + @Autowired + private EventDrivenConsumer checkout; + + + @Test + public void checkMessageStoreReferenceOnCheckIn() { + ClaimCheckInTransformer transformer = (ClaimCheckInTransformer) new DirectFieldAccessor( + new DirectFieldAccessor(checkin).getPropertyValue("handler")).getPropertyValue("transformer"); + MessageStore messageStore = (MessageStore) + new DirectFieldAccessor(transformer).getPropertyValue("messageStore"); + assertEquals(context.getBean("testMessageStore"), messageStore); + } + + @Test + public void checkMessageStoreReferenceOnCheckOut() { + ClaimCheckOutTransformer transformer = (ClaimCheckOutTransformer) new DirectFieldAccessor( + new DirectFieldAccessor(checkout).getPropertyValue("handler")).getPropertyValue("transformer"); + MessageStore messageStore = (MessageStore) + new DirectFieldAccessor(transformer).getPropertyValue("messageStore"); + assertEquals(context.getBean("testMessageStore"), messageStore); + } + + @Test + public void integrationTest() { + QueueChannel replyChannel = new QueueChannel(); + Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); + checkinChannel.send(message); + Message wiretapMessage = wiretap.receive(0); + assertNotNull(wiretapMessage); + assertEquals(message.getHeaders().getId(), wiretapMessage.getPayload()); + Message resultMessage = replyChannel.receive(0); + assertNotNull(resultMessage); + assertEquals("test", resultMessage.getPayload()); + } + +}