INT-3323: Add poller element to HTTP-outbound

JIRA: https://jira.spring.io/browse/INT-3323

Poller is internally supported in the bean definition of an http outbound gateway and outbound adapter, but it is not supported by their schema. This change attempts to fix the schema.

* Added in schema element for base poller, in both outbound adapter and outbound gateway
* Added in tests to ensure that a PollingConsumer is the instance type
* Polishing `import` for test classes
This commit is contained in:
Biju Kunjummen
2014-03-11 22:32:28 -04:00
committed by Artem Bilan
parent b12312114a
commit 98b46c61f3
5 changed files with 103 additions and 4 deletions

View File

@@ -317,7 +317,7 @@
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="2">
<xsd:choice minOccurs="0" maxOccurs="3">
<xsd:element name="uri-variable" type="uriVariableType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
@@ -327,6 +327,7 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType" minOccurs="0" maxOccurs="1" />
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>
<xsd:attributeGroup ref="httpOutboundCommonAttributes"/>
@@ -352,7 +353,7 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="gatewayType">
<xsd:choice minOccurs="0" maxOccurs="2">
<xsd:choice minOccurs="0" maxOccurs="3">
<xsd:element name="uri-variable" type="uriVariableType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
@@ -361,6 +362,7 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType" minOccurs="0" maxOccurs="1" />
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
<xsd:attribute name="request-channel" type="xsd:string">
<xsd:annotation>

View File

@@ -32,6 +32,7 @@
order="77"
auto-startup="false">
<uri-variable name="foo" expression="headers.bar"/>
</outbound-channel-adapter>
<util:map id="uriVariables">
@@ -56,6 +57,41 @@
url-expression="'http://localhost/test1'" channel="requests"
rest-template="customRestTemplate"/>
<si:channel id="queueChannel">
<si:queue capacity="10"/>
</si:channel>
<outbound-channel-adapter id="withPoller1" url="http://localhost/test1" channel="queueChannel">
<si:poller fixed-delay="5000"/>
</outbound-channel-adapter>
<outbound-channel-adapter id="withPoller2" url="http://localhost/test1" channel="queueChannel">
<request-handler-advice-chain/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<si:poller fixed-delay="5000"/>
</outbound-channel-adapter>
<outbound-channel-adapter id="withPoller3" url="http://localhost/test1" channel="queueChannel">
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<request-handler-advice-chain/>
<si:poller fixed-delay="5000"/>
</outbound-channel-adapter>
<outbound-channel-adapter id="withPoller4" url="http://localhost/test1" channel="queueChannel">
<si:poller fixed-delay="5000"/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<request-handler-advice-chain/>
</outbound-channel-adapter>
<outbound-channel-adapter id="withPoller5" url="http://localhost/test1" channel="queueChannel">
<si:poller fixed-delay="5000"/>
<request-handler-advice-chain/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
</outbound-channel-adapter>
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<beans:bean id="testErrorHandler" class="org.springframework.integration.http.config.HttpOutboundChannelAdapterParserTests$StubErrorHandler"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -21,11 +21,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +43,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.integration.endpoint.AbstractEndpoint;
@@ -59,6 +62,7 @@ import org.springframework.web.client.RestTemplate;
* @author Gary Russell
* @author Gunnar Hillert
* @author Artem Bilan
* @author Biju Kunjummen
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -88,6 +92,9 @@ public class HttpOutboundChannelAdapterParserTests {
@Autowired @Qualifier("withUrlExpressionAndTemplate")
private AbstractEndpoint withUrlExpressionAndTemplate;
@Autowired @Qualifier("withPoller1")
private AbstractEndpoint withPoller1;
@Autowired
private ApplicationContext applicationContext;
@@ -250,6 +257,11 @@ public class HttpOutboundChannelAdapterParserTests {
assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
@Test
public void withPoller() {
assertThat(this.withPoller1, Matchers.instanceOf(PollingConsumer.class));
}
@Test(expected=BeanDefinitionParsingException.class)
public void failWithUrlAndExpression() {
new ClassPathXmlApplicationContext("HttpOutboundChannelAdapterParserTests-url-fail-context.xml", this.getClass());

View File

@@ -40,6 +40,7 @@
<uri-variable name="foo" expression="headers.bar"/>
</outbound-gateway>
<util:map id="uriVariables">
<beans:entry key="foo1" value="bar1"/>
<beans:entry key="foo2" value="bar2"/>
@@ -54,6 +55,42 @@
</request-handler-advice-chain>
</outbound-gateway>
<si:channel id="queueChannel">
<si:queue capacity="10"/>
</si:channel>
<outbound-gateway id="withPoller1" request-channel="queueChannel" url="http://localhost/test1">
<si:poller fixed-delay="5000"/>
</outbound-gateway>
<outbound-gateway id="withPoller2" url="http://localhost/test1" request-channel="queueChannel">
<request-handler-advice-chain/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<si:poller fixed-delay="5000"/>
</outbound-gateway>
<outbound-gateway id="withPoller3" url="http://localhost/test1" request-channel="queueChannel">
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<request-handler-advice-chain/>
<si:poller fixed-delay="5000"/>
</outbound-gateway>
<outbound-gateway id="withPoller4" url="http://localhost/test1" request-channel="queueChannel">
<si:poller fixed-delay="5000"/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
<request-handler-advice-chain/>
</outbound-gateway>
<outbound-gateway id="withPoller5" url="http://localhost/test1" request-channel="queueChannel">
<si:poller fixed-delay="5000"/>
<request-handler-advice-chain/>
<uri-variable name="foo" expression="headers.bar"/>
<uri-variable name="bar" expression="headers.bar"/>
</outbound-gateway>
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<beans:bean id="testErrorHandler" class="org.springframework.integration.http.config.HttpOutboundGatewayParserTests$StubErrorHandler"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -19,12 +19,14 @@ package org.springframework.integration.http.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
@@ -40,6 +42,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
@@ -56,6 +59,7 @@ import org.springframework.web.client.ResponseErrorHandler;
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Biju Kunjummen
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -73,6 +77,9 @@ public class HttpOutboundGatewayParserTests {
@Autowired @Qualifier("withAdvice")
private AbstractEndpoint withAdvice;
@Autowired @Qualifier("withPoller1")
private AbstractEndpoint withPoller1;
@Autowired
private ApplicationContext applicationContext;
@@ -200,6 +207,11 @@ public class HttpOutboundGatewayParserTests {
}
}
@Test
public void withPoller() {
assertThat(this.withPoller1, Matchers.instanceOf(PollingConsumer.class));
}
public static class StubErrorHandler implements ResponseErrorHandler {