INT-1245, INT-1256 moved namespace support from old HttpInboundEndpoint to new HttpRequestHandlingMessagingGateway or, if the 'view-name' is present, HttpRequestHandlingController
This commit is contained in:
@@ -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.
|
||||
@@ -46,7 +46,9 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse
|
||||
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return "org.springframework.integration.http.HttpInboundEndpoint";
|
||||
return element.hasAttribute("view-name")
|
||||
? "org.springframework.integration.http.HttpRequestHandlingController"
|
||||
: "org.springframework.integration.http.HttpRequestHandlingMessagingGateway";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +66,7 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
builder.addConstructorArgValue(this.expectReply);
|
||||
String inputChannelAttributeName = this.getInputChannelAttributeName();
|
||||
String inputChannelRef = element.getAttribute(inputChannelAttributeName);
|
||||
if (!StringUtils.hasText(inputChannelRef)) {
|
||||
@@ -71,7 +74,6 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse
|
||||
"a '" + inputChannelAttributeName + "' reference is required", element);
|
||||
}
|
||||
builder.addPropertyReference("requestChannel", inputChannelRef);
|
||||
builder.addPropertyValue("expectReply", this.expectReply);
|
||||
if (this.expectReply) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout");
|
||||
@@ -83,10 +85,11 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(
|
||||
builder, element, "send-timeout", "requestTimeout");
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "supported-methods");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "view");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-key");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-mapper");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "supported-methods", "supportedMethodNames");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "conversion-target-type");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "view-name");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper");
|
||||
}
|
||||
|
||||
private String getInputChannelAttributeName() {
|
||||
|
||||
@@ -34,27 +34,38 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="conversion-target-type" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Target type for payload that is the conversion result of the request.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="send-timeout" type="xsd:string"/>
|
||||
<xsd:attribute name="supported-methods" type="xsd:string"/>
|
||||
<xsd:attribute name="view" type="xsd:string">
|
||||
<xsd:attribute name="view-name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
View name to be resolved when rendering a response.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="message-converters" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
List of HttpMessageConverters for this Channel Adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="header-mapper" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.web.servlet.View"/>
|
||||
<tool:expected-type type="org.springframework.integration.message.HeaderMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="request-mapper" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.http.InboundRequestMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="request-key" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
@@ -70,25 +81,36 @@
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="extract-reply-payload" type="xsd:string" default="true"/>
|
||||
<xsd:attribute name="supported-methods" type="xsd:string"/>
|
||||
<xsd:attribute name="view" type="xsd:string">
|
||||
<xsd:attribute name="view-name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
View name to be resolved when rendering a response.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="conversion-target-type" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Target type for payload that is the conversion result of the request.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="message-converters" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
List of HttpMessageConverters for this Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="header-mapper" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.web.servlet.View"/>
|
||||
<tool:expected-type type="org.springframework.integration.message.HeaderMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="request-mapper" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.http.InboundRequestMapper"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="request-key" type="xsd:string"/>
|
||||
<xsd:attribute name="reply-key" type="xsd:string"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/http
|
||||
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
|
||||
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
|
||||
|
||||
<si:channel id="requests">
|
||||
<si:queue capacity="1"/>
|
||||
|
||||
@@ -33,11 +33,11 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.http.HttpInboundEndpoint;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.integration.http.HttpRequestHandlingMessagingGateway;
|
||||
import org.springframework.integration.http.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -50,17 +50,17 @@ import org.springframework.util.MultiValueMap;
|
||||
@ContextConfiguration
|
||||
public class HttpInboundChannelAdapterParserTests {
|
||||
|
||||
@Autowired @Qualifier("requests")
|
||||
@Autowired
|
||||
private PollableChannel requests;
|
||||
|
||||
@Autowired @Qualifier("defaultAdapter")
|
||||
private HttpInboundEndpoint defaultAdapter;
|
||||
@Autowired
|
||||
private HttpRequestHandlingMessagingGateway defaultAdapter;
|
||||
|
||||
@Autowired @Qualifier("postOnlyAdapter")
|
||||
private HttpInboundEndpoint postOnlyAdapter;
|
||||
@Autowired
|
||||
private HttpRequestHandlingMessagingGateway postOnlyAdapter;
|
||||
|
||||
@Autowired @Qualifier("putOrDeleteAdapter")
|
||||
private HttpInboundEndpoint putOrDeleteAdapter;
|
||||
@Autowired
|
||||
private HttpRequestHandlingMessagingGateway putOrDeleteAdapter;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -133,8 +133,8 @@ public class HttpInboundChannelAdapterParserTests {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(putOrDeleteAdapter);
|
||||
List<String> supportedMethods = (List<String>) accessor.getPropertyValue("supportedMethods");
|
||||
assertEquals(2, supportedMethods.size());
|
||||
assertTrue(supportedMethods.contains("PUT"));
|
||||
assertTrue(supportedMethods.contains("DELETE"));
|
||||
assertTrue(supportedMethods.contains(HttpMethod.PUT));
|
||||
assertTrue(supportedMethods.contains(HttpMethod.DELETE));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
|
||||
|
||||
<si:publish-subscribe-channel id="requests"/>
|
||||
|
||||
<si:bridge output-channel="responses" input-channel="requests"/>
|
||||
|
||||
<si:channel id="responses"/>
|
||||
|
||||
<inbound-gateway id="inboundGateway" request-channel="requests"
|
||||
reply-channel="responses" />
|
||||
|
||||
<si:bridge input-channel="requests" output-channel="responses"/>
|
||||
|
||||
<si:channel id="responses">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<inbound-gateway id="inboundGateway" request-channel="requests" reply-channel="responses"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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.
|
||||
@@ -20,23 +20,24 @@ import static org.hamcrest.CoreMatchers.any;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
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.core.MessageChannel;
|
||||
import org.springframework.integration.http.HttpInboundEndpoint;
|
||||
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
|
||||
import static org.springframework.integration.test.util.TestUtils.handlerExpecting;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.http.HttpRequestHandlingMessagingGateway;
|
||||
import org.springframework.integration.http.MockHttpServletRequest;
|
||||
import org.springframework.integration.http.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
@@ -46,20 +47,20 @@ import javax.servlet.http.HttpServletResponse;
|
||||
public class HttpInboundGatewayParserTests {
|
||||
|
||||
@Autowired
|
||||
private HttpInboundEndpoint gateway;
|
||||
private HttpRequestHandlingMessagingGateway gateway;
|
||||
|
||||
@Qualifier("responses")
|
||||
@Autowired
|
||||
MessageChannel responses;
|
||||
private SubscribableChannel requests;
|
||||
|
||||
@Qualifier("requests")
|
||||
@Autowired
|
||||
SubscribableChannel requests;
|
||||
|
||||
private PollableChannel responses;
|
||||
|
||||
|
||||
@Test
|
||||
public void checkConfig() {
|
||||
assertNotNull(gateway);
|
||||
assertThat((Boolean) getPropertyValue(gateway, "expectReply"), is(true));
|
||||
assertThat((PollableChannel) getPropertyValue(gateway, "replyChannel"), is(responses));
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
@@ -67,10 +68,12 @@ public class HttpInboundGatewayParserTests {
|
||||
requests.subscribe(handlerExpecting(any(Message.class)));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setMethod("GET");
|
||||
request.addHeader("Accept", "application/x-java-serialized-object");
|
||||
request.setParameter("foo", "bar");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
gateway.handleRequest(request, response);
|
||||
assertThat(response.getStatus(), is(HttpServletResponse.SC_OK));
|
||||
assertThat(response.getContentType(), is("application/x-java-serialized-object"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user