INT-1212 added support for the "message-converters" (a ref to a list) attribute on <outbound-gateway> and <outbound-channel-adapter> elements in the http namespace

This commit is contained in:
Mark Fisher
2010-06-25 00:19:50 +00:00
parent d3fde86be3
commit c86e24cd34
8 changed files with 91 additions and 8 deletions

View File

@@ -41,6 +41,7 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda
builder.addPropertyValue("expectReply", false);
builder.addConstructorArgValue(element.getAttribute("url"));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory");

View File

@@ -44,6 +44,7 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser {
PACKAGE_PATH + ".HttpRequestExecutingMessageHandler");
builder.addConstructorArgValue(element.getAttribute("url"));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-request-payload", "extractPayload");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout", "sendTimeout");

View File

@@ -133,6 +133,14 @@
</xsd:attribute>
<xsd:attribute name="charset" type="xsd:string"/>
<xsd:attribute name="extract-payload" type="xsd:string"/>
<xsd:attribute name="message-converters" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Provide a reference to a list of HttpMessageConverter instances. If specified, these converters will replace
all of the default converters that would normally be present on the underlying RestTemplate.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="request-factory" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -185,6 +193,14 @@
<xsd:union memberTypes="httpMethodEnumeration xsd:string" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="message-converters" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Provide a reference to a list of HttpMessageConverter instances. If specified, these converters will replace
all of the default converters that would normally be present on the underlying RestTemplate.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extract-request-payload" type="xsd:string"/>
<xsd:attribute name="charset" type="xsd:string"/>
<xsd:attribute name="request-factory" type="xsd:string">

View File

@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/http"
<beans:beans
xmlns="http://www.springframework.org/schema/integration/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
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.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="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://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<si:channel id="requests"/>
@@ -19,6 +19,7 @@
http-method="GET"
channel="requests"
charset="UTF-8"
message-converters="converterList"
extract-payload="false"
request-factory="testRequestFactory"
order="77"
@@ -26,4 +27,9 @@
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<util:list id="converterList">
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
</util:list>
</beans:beans>

View File

@@ -91,6 +91,8 @@ public class HttpOutboundChannelAdapterParserTests {
templateAccessor.getPropertyValue("requestFactory");
assertTrue(mapper instanceof DefaultOutboundRequestMapper);
assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
Object converterListBean = this.applicationContext.getBean("converterList");
assertEquals(converterListBean, templateAccessor.getPropertyValue("messageConverters"));
Object requestFactoryBean = this.applicationContext.getBean("testRequestFactory");
assertEquals(requestFactoryBean, requestFactory);
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);

View File

@@ -3,12 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
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.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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<si:channel id="requests"/>
@@ -24,6 +26,7 @@
request-channel="requests"
request-factory="testRequestFactory"
request-timeout="1234"
message-converters="converterList"
extract-request-payload="false"
reply-channel="replies"
charset="UTF-8"
@@ -32,4 +35,9 @@
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<util:list id="converterList">
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
</util:list>
</beans:beans>

View File

@@ -98,6 +98,8 @@ public class HttpOutboundGatewayParserTests {
templateAccessor.getPropertyValue("requestFactory");
assertTrue(mapper instanceof DefaultOutboundRequestMapper);
assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
Object converterListBean = this.applicationContext.getBean("converterList");
assertEquals(converterListBean, templateAccessor.getPropertyValue("messageConverters"));
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
assertEquals("http://localhost/test2", handlerAccessor.getPropertyValue("uri"));
assertEquals(HttpMethod.PUT, handlerAccessor.getPropertyValue("httpMethod"));

View File

@@ -0,0 +1,47 @@
/*
* 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.
* 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.http.config;
import java.io.IOException;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
/**
* @author Mark Fisher
* @since 2.0
*/
public class StubHttpMessageConverter extends AbstractHttpMessageConverter<String> {
@Override
protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return null;
}
@Override
protected boolean supports(Class<?> clazz) {
return false;
}
@Override
protected void writeInternal(String t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
}
}