INT-911, Created MessageHandling infrastructure around Gateway so it could be included in the <chain>
This commit is contained in:
@@ -27,12 +27,14 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.gateway.GatewayInvokingMessageHandler;
|
||||
|
||||
/**
|
||||
* Parser for the <chain> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ChainParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
@@ -47,7 +49,14 @@ public class ChainParser extends AbstractConsumerEndpointParser {
|
||||
Node child = children.item(i);
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE && !"poller".equals(child.getLocalName())) {
|
||||
String childBeanName = this.parseChild((Element) child, parserContext, builder.getBeanDefinition());
|
||||
handlerList.add(new RuntimeBeanReference(childBeanName));
|
||||
// INT-911 will create Gateway invoking MessageHandler, allowing 'gateway' to be included in the chain
|
||||
if ("gateway".equals(child.getLocalName())){
|
||||
BeanDefinitionBuilder gwBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayInvokingMessageHandler.class);
|
||||
gwBuilder.addConstructorArgValue(new RuntimeBeanReference(childBeanName));
|
||||
handlerList.add(gwBuilder.getBeanDefinition());
|
||||
} else {
|
||||
handlerList.add(new RuntimeBeanReference(childBeanName));
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.addPropertyValue("handlers", handlerList);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.gateway;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Will decorate 'gateway' as {@link MessageHandler} so it could be included in the chain.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GatewayInvokingMessageHandler extends
|
||||
AbstractReplyProducingMessageHandler {
|
||||
private GenericSendAndRecieveGateway gateway;
|
||||
/**
|
||||
*
|
||||
* @param gateway
|
||||
*/
|
||||
public GatewayInvokingMessageHandler(GenericSendAndRecieveGateway gateway){
|
||||
Assert.notNull(gateway, "gateway must not be null");
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will simply delegate to the original gateway
|
||||
*/
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
return gateway.sendAndRecieve(requestMessage);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.SimpleTypeConverter;
|
||||
@@ -74,7 +73,14 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
|
||||
private Map<String, GatewayMethodDefinition> methodToChannelMap;
|
||||
|
||||
|
||||
/**
|
||||
* Will initialize this Factory with he default instance of the 'gateway' interface
|
||||
* {@link GenericSendAndRecieveGateway} which will be used by this proxy if
|
||||
* 'service-interface' attribute is not set.
|
||||
*/
|
||||
public GatewayProxyFactoryBean(){
|
||||
this.serviceInterface = GenericSendAndRecieveGateway.class;
|
||||
}
|
||||
/**
|
||||
* Set the interface class that the generated proxy should implement.
|
||||
* If none is provided explicitly, the default is MessageHandler.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.gateway;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
|
||||
/**
|
||||
* Generic definition of the 'gateway' which will be used by {@link GatewayProxyFactoryBean}
|
||||
* if 'service-interface' property is not provided
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
interface GenericSendAndRecieveGateway {
|
||||
|
||||
public Message<?> sendAndRecieve(Message<?> message);
|
||||
}
|
||||
@@ -315,8 +315,8 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="required" />
|
||||
<xsd:attribute name="service-interface" type="xsd:string" use="required">
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional" />
|
||||
<xsd:attribute name="service-interface" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="direct">
|
||||
@@ -706,6 +706,7 @@
|
||||
<xsd:element ref="router" />
|
||||
<xsd:element ref="delayer" />
|
||||
<xsd:element ref="chain" />
|
||||
<xsd:element ref="gateway" />
|
||||
<xsd:element name="poller" type="innerPollerType" />
|
||||
</xsd:choice>
|
||||
</xsd:extension>
|
||||
|
||||
Reference in New Issue
Block a user