INT-779 Added namespace support for 'send-timeout' on handlers.

This commit is contained in:
Mark Fisher
2009-12-23 04:37:34 +00:00
parent 3030f9c41c
commit a4e7fe36e6
9 changed files with 160 additions and 16 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.
@@ -30,19 +30,32 @@ import org.springframework.util.StringUtils;
*/
public class SplitterFactoryBean extends AbstractMessageHandlerFactoryBean {
private Long sendTimeout;
public void setSendTimeout(Long sendTimeout) {
this.sendTimeout = sendTimeout;
}
@Override
protected MessageHandler createHandler(Object targetObject, String targetMethodName) {
AbstractMessageSplitter splitter = null;
if (targetObject == null) {
Assert.isTrue(!StringUtils.hasText(targetMethodName),
"'method' should only be provided when 'ref' is also provided");
return new DefaultMessageSplitter();
splitter = new DefaultMessageSplitter();
}
if (targetObject instanceof AbstractMessageSplitter) {
return (AbstractMessageSplitter) targetObject;
else if (targetObject instanceof AbstractMessageSplitter) {
splitter = (AbstractMessageSplitter) targetObject;
}
return (StringUtils.hasText(targetMethodName))
? new MethodInvokingSplitter(targetObject, targetMethodName)
: new MethodInvokingSplitter(targetObject);
else {
splitter = (StringUtils.hasText(targetMethodName))
? new MethodInvokingSplitter(targetObject, targetMethodName)
: new MethodInvokingSplitter(targetObject);
}
if (this.sendTimeout != null) {
splitter.setSendTimeout(this.sendTimeout.longValue());
}
return splitter;
}
}

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.
@@ -30,6 +30,12 @@ import org.springframework.util.StringUtils;
*/
public class TransformerFactoryBean extends AbstractMessageHandlerFactoryBean {
private Long sendTimeout;
public void setSendTimeout(Long sendTimeout) {
this.sendTimeout = sendTimeout;
}
@Override
protected MessageHandler createHandler(Object targetObject, String targetMethodName) {
Assert.notNull(targetObject, "targetObject must not be null");
@@ -43,7 +49,11 @@ public class TransformerFactoryBean extends AbstractMessageHandlerFactoryBean {
else {
transformer = new MethodInvokingTransformer(targetObject);
}
return new MessageTransformingHandler(transformer);
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
if (this.sendTimeout != null) {
handler.setSendTimeout(this.sendTimeout.longValue());
}
return handler;
}
}

View File

@@ -38,7 +38,8 @@ public class FilterParser extends AbstractConsumerEndpointParser {
IntegrationNamespaceUtils.BASE_PACKAGE + ".filter.MessageFilter");
builder.addConstructorArgReference((String) this.parseSelector(element, parserContext));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "discard-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "throw-exception-on-rejection");
return builder;

View File

@@ -52,6 +52,7 @@ public class ServiceActivatorParser extends AbstractConsumerEndpointParser {
String method = element.getAttribute(METHOD_ATTRIBUTE);
builder.getRawBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(method, "java.lang.String");
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
return builder;
}

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.
@@ -38,7 +38,8 @@ public class SplitterParser extends AbstractConsumerEndpointParser {
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.SplitterFactoryBean");
if (innerDefinition != null){
builder.addPropertyValue("targetObject", innerDefinition);
} else if (element.hasAttribute(REF_ATTRIBUTE)) {
}
else if (element.hasAttribute(REF_ATTRIBUTE)) {
String ref = element.getAttribute(REF_ATTRIBUTE);
builder.addPropertyReference("targetObject", ref);
if (StringUtils.hasText(element.getAttribute(METHOD_ATTRIBUTE))) {
@@ -46,6 +47,7 @@ public class SplitterParser extends AbstractConsumerEndpointParser {
builder.addPropertyValue("targetMethodName", method);
}
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
return builder;
}

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.
@@ -38,7 +38,8 @@ public class TransformerParser extends AbstractConsumerEndpointParser {
if (innerDefinition != null){
builder.addPropertyValue("targetObject", innerDefinition);
} else {
}
else {
String ref = element.getAttribute(REF_ATTRIBUTE);
if (!StringUtils.hasText(ref)) {
parserContext.getReaderContext().error("Either \"ref\" attribute or inner bean (<bean/>) definition of concrete implementation of " +
@@ -52,6 +53,8 @@ public class TransformerParser extends AbstractConsumerEndpointParser {
if (StringUtils.hasText(method)) {
builder.addPropertyValue("targetMethodName", method);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
return builder;
}
}

View File

@@ -479,6 +479,14 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="method" type="xsd:string" />
<xsd:attribute name="send-timeout" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specify the maximum amount of time in milliseconds to wait when sending reply
Messages to the output channel. By default the send will block for one second.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -1251,7 +1259,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="send-timeout" type="xsd:string" />
<xsd:attribute name="send-partial-result-on-timeout"
type="xsd:string" />
<xsd:attribute name="tracked-correlation-id-capacity"
@@ -1293,7 +1300,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="send-timeout" type="xsd:string" />
<xsd:attribute name="release-partial-sequences" type="xsd:string" />
<xsd:attribute name="send-partial-result-on-timeout"
type="xsd:string" />

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<service-activator id="serviceActivator" input-channel="input" ref="testBean" method="echo" send-timeout="123"/>
<router id="router" input-channel="routerInput" ref="testBean" method="echo" timeout="123"/>
<filter id="filter" input-channel="filterInput" ref="testBean" method="filter" send-timeout="123"/>
<transformer id="transformer" input-channel="transformerInput" ref="testBean" method="echo" send-timeout="123"/>
<splitter id="splitter" input-channel="splitterInput" ref="testBean" method="echo" send-timeout="123"/>
<beans:bean id="testBean" class="org.springframework.integration.handler.SendTimeoutConfigurationTests$TestBean"/>
</beans:beans>

View File

@@ -0,0 +1,86 @@
/*
* 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.
* 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.handler;
import static org.junit.Assert.assertEquals;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SendTimeoutConfigurationTests {
@Autowired
private ApplicationContext context;
@Test
public void serviceActivator() {
assertEquals(123, this.getTimeout("serviceActivator"));
}
@Test
public void filter() {
assertEquals(123, this.getTimeout("filter"));
}
@Test
public void transformer() {
assertEquals(123, this.getTimeout("transformer"));
}
@Test
public void splitter() {
assertEquals(123, this.getTimeout("splitter"));
}
@Test
public void router() {
assertEquals(123, this.getTimeout("router"));
}
private long getTimeout(String endpointName) {
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(context.getBean(endpointName));
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(endpointAccessor.getPropertyValue("handler"));
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("channelTemplate"));
return ((Long) templateAccessor.getPropertyValue("sendTimeout")).longValue();
}
static class TestBean {
public boolean filter(String s) {
return true;
}
public String echo(String s) {
return s;
}
}
}