INT-911 created a separate XSD element for the 'gateway' used inside a chain, to avoid 'default' in the attribute names

This commit is contained in:
Mark Fisher
2009-12-24 15:09:49 +00:00
parent c8683b5ab4
commit a8f3edd52a
4 changed files with 73 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -37,6 +37,11 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser {
"default-request-channel", "default-reply-channel", "message-mapper"
};
private static String[] innerAttributes = new String[] {
"request-channel", "reply-channel", "request-timeout", "reply-timeout"
};
@Override
protected String getBeanClassName(Element element) {
return IntegrationNamespaceUtils.BASE_PACKAGE + ".gateway.GatewayProxyFactoryBean";
@@ -45,11 +50,28 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !ObjectUtils.containsElement(referenceAttributes, attributeName)
&& !ObjectUtils.containsElement(innerAttributes, attributeName)
&& super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
if ("chain".equals(element.getParentNode().getLocalName())) {
this.postProcessInnerGateway(builder, element);
}
else {
this.postProcessGateway(builder, element);
}
}
private void postProcessInnerGateway(BeanDefinitionBuilder builder, Element element) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel", "defaultRequestChannel");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel", "defaultReplyChannel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout", "defaultRequestTimeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout", "defaultReplyTimeout");
}
private void postProcessGateway(BeanDefinitionBuilder builder, Element element) {
for (String attributeName : referenceAttributes) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, attributeName);
}

View File

@@ -350,6 +350,36 @@
</xsd:complexType>
</xsd:element>
<xsd:complexType name="innerGatewayType">
<xsd:annotation>
<xsd:documentation>
Defines a Messaging Gateway to be used within a chain.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="request-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="reply-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="request-timeout" type="xsd:string" />
<xsd:attribute name="reply-timeout" type="xsd:string" />
</xsd:complexType>
<xsd:element name="inbound-channel-adapter" type="methodInvokingChannelAdapterType">
<xsd:annotation>
<xsd:documentation>
@@ -706,7 +736,7 @@
<xsd:element ref="router" />
<xsd:element ref="delayer" />
<xsd:element ref="chain" />
<xsd:element ref="gateway" />
<xsd:element name="gateway" type="innerGatewayType" />
<xsd:element name="poller" type="innerPollerType" />
</xsd:choice>
</xsd:extension>

View File

@@ -8,7 +8,7 @@
<si:gateway id="simpleGateway"
default-request-channel="inputA"
default-reply-channel="inputB"
service-interface="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleGateway"/>
service-interface="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleGateway"/>
<si:publish-subscribe-channel id="inputA" />
<si:publish-subscribe-channel id="inputB" />
@@ -19,9 +19,9 @@
<si:header name="foo" value="foo" />
</si:header-enricher>
<si:service-activator>
<bean class="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleService" />
<bean class="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleService" />
</si:service-activator>
<si:gateway default-request-channel="inputC"/>
<si:gateway request-channel="inputC"/>
</si:chain>
@@ -31,7 +31,7 @@
<si:header name="name" value="oleg" />
</si:header-enricher>
<si:service-activator>
<bean class="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleService" />
<bean class="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleService" />
</si:service-activator>
</si:chain>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -13,32 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.gateway;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.SubscribableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessageHandler;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessageRejectedException;
import org.springframework.integration.message.StringMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* TODO - insert COMMENT
* @author Oleg Zhurakousky
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class GatewayInvokingMessaheHandlerTests {
public class GatewayInvokingMessageHandlerTests {
@Autowired
@Qualifier("inputA")
SubscribableChannel channel;
@@ -52,11 +51,9 @@ public class GatewayInvokingMessaheHandlerTests {
SubscribableChannel output;
@Test
public void validateGatewayInTheChainViaChannel(){
public void validateGatewayInTheChainViaChannel() {
output.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
public void handleMessage(Message<?> message) {
Assert.assertEquals("echo:echo:hello", message.getPayload());
Assert.assertEquals("foo", message.getHeaders().get("foo"));
Assert.assertEquals("oleg", message.getHeaders().get("name"));
@@ -64,12 +61,11 @@ public class GatewayInvokingMessaheHandlerTests {
});
channel.send(new StringMessage("hello"));
}
@Test
public void validateGatewayInTheChainViaAnotherGateway(){
public void validateGatewayInTheChainViaAnotherGateway() {
output.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
public void handleMessage(Message<?> message) {
Assert.assertEquals("echo:echo:hello", message.getPayload());
Assert.assertEquals("foo", message.getHeaders().get("foo"));
Assert.assertEquals("oleg", message.getHeaders().get("name"));
@@ -78,14 +74,15 @@ public class GatewayInvokingMessaheHandlerTests {
String result = gateway.sendRecieve("hello");
Assert.assertEquals("echo:echo:hello", result);
}
public static interface SimpleGateway{
public static interface SimpleGateway {
public String sendRecieve(String str);
}
public static class SimpleService {
public String echo(String str){
public String echo(String str) {
return "echo:" + str;
}
}
}