INT-1349 Added support for <uri-variable name="x" expression="y"/> sub-elements within the HTTP outbound adapters. Map payloads no longer provide values for the URI template placeholder replacements.
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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.http;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.Message;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class DefaultParameterExtractor implements ParameterExtractor {
|
||||
|
||||
private static Log logger = LogFactory.getLog(DefaultParameterExtractor.class);
|
||||
|
||||
private SpelExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
private Map<String, Expression> dynamicParameterExpressions = new HashMap<String, Expression>();
|
||||
|
||||
/**
|
||||
* A map of parameter name to SpEL expressions on the message.
|
||||
*
|
||||
* @param dynamicParameterExpressions the dynamic parameter expressions to set
|
||||
*/
|
||||
public void setDynamicParameterExpressions(Map<String, String> dynamicParameterExpressions) {
|
||||
this.dynamicParameterExpressions.clear();
|
||||
for (String key : dynamicParameterExpressions.keySet()) {
|
||||
this.dynamicParameterExpressions.put(key, parser.parseExpression(dynamicParameterExpressions.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, ?> fromMessage(Message<?> requestMessage) {
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
for (String key : dynamicParameterExpressions.keySet()) {
|
||||
Object value = dynamicParameterExpressions.get(key).getValue(requestMessage);
|
||||
params.put(key, value);
|
||||
}
|
||||
|
||||
if (requestMessage.getPayload() instanceof Map<?,?>) {
|
||||
Map<?,?> payloadMap = (Map<?,?>) requestMessage.getPayload();
|
||||
for (Object key : payloadMap.keySet()) {
|
||||
if (key instanceof String) {
|
||||
params.put((String) key, payloadMap.get(key).toString());
|
||||
}
|
||||
else if (logger.isDebugEnabled()) {
|
||||
logger.debug("ignoring Map value for non-String key: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,9 +17,17 @@
|
||||
package org.springframework.integration.http;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -29,11 +37,13 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.context.SimpleBeanResolver;
|
||||
import org.springframework.integration.core.MessageBuilder;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.mapping.HeaderMapper;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -46,6 +56,9 @@ import org.springframework.web.client.RestTemplate;
|
||||
*/
|
||||
public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private static final ExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
|
||||
private final String uri;
|
||||
|
||||
private volatile HttpMethod httpMethod = HttpMethod.POST;
|
||||
@@ -54,13 +67,16 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
|
||||
|
||||
private volatile Class<?> expectedResponseType;
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private final DefaultOutboundRequestMapper requestMapper = new DefaultOutboundRequestMapper();
|
||||
|
||||
private volatile HeaderMapper<HttpHeaders> headerMapper = new DefaultHttpHeaderMapper();
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
private final Map<String, Expression> uriVariableExpressions = new HashMap<String, Expression>();
|
||||
|
||||
private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
|
||||
private ParameterExtractor parameterExtractor = new DefaultParameterExtractor();
|
||||
|
||||
/**
|
||||
* Create a handler that will send requests to the provided URI.
|
||||
@@ -156,19 +172,41 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ParameterExtractor} for creating URI parameters from the outbound message.
|
||||
*
|
||||
* @param parameterExtractor the parameter extractor to set
|
||||
* Set the Map of URI variable expressions to evaluate against the outbound message
|
||||
* when replacing the variable placeholders in a URI template.
|
||||
*/
|
||||
public void setParameterExtractor(ParameterExtractor parameterExtractor) {
|
||||
this.parameterExtractor = parameterExtractor;
|
||||
public void setUriVariableExpressions(Map<String, String> uriVariableExpressions) {
|
||||
synchronized (this.uriVariableExpressions) {
|
||||
this.uriVariableExpressions.clear();
|
||||
if (!CollectionUtils.isEmpty(uriVariableExpressions)) {
|
||||
for (Map.Entry<String, String> entry : uriVariableExpressions.entrySet()) {
|
||||
this.uriVariableExpressions.put(entry.getKey(), PARSER.parseExpression(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
super.onInit();
|
||||
BeanFactory beanFactory = this.getBeanFactory();
|
||||
if (beanFactory != null) {
|
||||
this.evaluationContext.setBeanResolver(new SimpleBeanResolver(beanFactory));
|
||||
}
|
||||
ConversionService conversionService = this.getConversionService();
|
||||
if (conversionService != null) {
|
||||
this.evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
try {
|
||||
// TODO: allow a boolean flag for treating Map as queryParams vs. uriVariables?
|
||||
Map<String, ?> uriVariables = this.parameterExtractor.fromMessage(requestMessage);
|
||||
Map<String, Object> uriVariables = new HashMap<String, Object>();
|
||||
for (Map.Entry<String, Expression> entry : this.uriVariableExpressions.entrySet()) {
|
||||
Object value = entry.getValue().getValue(this.evaluationContext, requestMessage, String.class);
|
||||
uriVariables.put(entry.getKey(), value);
|
||||
}
|
||||
HttpEntity<?> httpRequest = this.requestMapper.fromMessage(requestMessage);
|
||||
ResponseEntity<?> httpResponse = this.restTemplate.exchange(this.uri, this.httpMethod, httpRequest, this.expectedResponseType, uriVariables);
|
||||
if (this.expectReply) {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.http;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public interface ParameterExtractor {
|
||||
|
||||
/**
|
||||
* @param requestMessage
|
||||
* @return a map of parameters
|
||||
*/
|
||||
Map<String, ?> fromMessage(Message<?> requestMessage);
|
||||
|
||||
}
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.integration.http.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -23,6 +27,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Parser for the 'outbound-channel-adapter' element of the http namespace.
|
||||
@@ -43,11 +49,20 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "parameter-extractor");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expected-response-type");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory");
|
||||
List<Element> uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable");
|
||||
if (!CollectionUtils.isEmpty(uriVariableElements)) {
|
||||
Map<String, String> uriVariableExpressions = new HashMap<String, String>();
|
||||
for (Element uriVariableElement : uriVariableElements) {
|
||||
String name = uriVariableElement.getAttribute("name");
|
||||
String expression = uriVariableElement.getAttribute("expression");
|
||||
uriVariableExpressions.put(name, expression);
|
||||
}
|
||||
builder.addPropertyValue("uriVariableExpressions", uriVariableExpressions);
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,18 @@
|
||||
|
||||
package org.springframework.integration.http.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Parser for the 'outbound-gateway' element of the http namespace.
|
||||
@@ -46,13 +52,22 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "parameter-extractor");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-request-payload", "extractPayload");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expected-response-type");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout", "sendTimeout");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel", "outputChannel");
|
||||
List<Element> uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable");
|
||||
if (!CollectionUtils.isEmpty(uriVariableElements)) {
|
||||
Map<String, String> uriVariableExpressions = new HashMap<String, String>();
|
||||
for (Element uriVariableElement : uriVariableElements) {
|
||||
String name = uriVariableElement.getAttribute("name");
|
||||
String expression = uriVariableElement.getAttribute("expression");
|
||||
uriVariableExpressions.put(name, expression);
|
||||
}
|
||||
builder.addPropertyValue("uriVariableExpressions", uriVariableExpressions);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,9 @@
|
||||
Defines an outbound HTTP-based Channel Adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="uri-variable" type="uriVariableType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="url" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
@@ -134,15 +137,6 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="parameter-extractor" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.http.ParameterExtractor"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="http-method">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -228,6 +222,9 @@
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="uri-variable" type="uriVariableType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="url" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -235,15 +232,6 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="parameter-extractor" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.http.ParameterExtractor"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="http-method">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -307,6 +295,31 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="uriVariableType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Expression to be evaluated against the Message to replace a URI {placeholder} with the evaluation result.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="name" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Name of the placeholder to be replaced.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="expression" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Expression to be evaluated to determine the replacement value.
|
||||
The Message is the root object of the expression, therefore
|
||||
the 'payload' and 'headers' are available directly. Any bean
|
||||
may be resolved if the bean name is preceded with '@'.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:simpleType name="httpMethodEnumeration">
|
||||
<xsd:restriction base="xsd:token">
|
||||
<xsd:enumeration value="GET" />
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.http;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class DefaultParameterExtractorTests {
|
||||
|
||||
@Test
|
||||
public void testFromMessage() throws Exception {
|
||||
DefaultParameterExtractor mapper = new DefaultParameterExtractor();
|
||||
Map<String, ?> params = mapper.fromMessage(new GenericMessage<Object>(Collections.singletonMap("foo", "bar")));
|
||||
assertEquals(1, params.size());
|
||||
assertEquals("bar", params.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithExpressions() throws Exception {
|
||||
DefaultParameterExtractor mapper = new DefaultParameterExtractor();
|
||||
mapper.setDynamicParameterExpressions(Collections.singletonMap("foo", "payload"));
|
||||
Map<String, ?> params = mapper.fromMessage(new GenericMessage<Object>("bar"));
|
||||
assertEquals(1, params.size());
|
||||
assertEquals("bar", params.get("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class UriVariableExpressionTests {
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithExpressions() throws Exception {
|
||||
final AtomicReference<URI> uriHolder = new AtomicReference<URI>();
|
||||
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://test/{foo}");
|
||||
handler.setUriVariableExpressions(Collections.singletonMap("foo", "payload"));
|
||||
handler.setRequestFactory(new SimpleClientHttpRequestFactory() {
|
||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||
uriHolder.set(uri);
|
||||
throw new RuntimeException("intentional");
|
||||
}
|
||||
});
|
||||
Message<?> message = new GenericMessage<Object>("bar");
|
||||
Exception exception = null;
|
||||
try {
|
||||
handler.handleMessage(message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
assertEquals("intentional", exception.getCause().getMessage());
|
||||
assertEquals("http://test/bar", uriHolder.get().toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,22 +15,21 @@
|
||||
<outbound-channel-adapter id="minimalConfig" url="http://localhost/test1" channel="requests"/>
|
||||
|
||||
<outbound-channel-adapter id="fullConfig"
|
||||
url="http://localhost/test2"
|
||||
parameter-extractor="testParameterMapper"
|
||||
http-method="GET"
|
||||
channel="requests"
|
||||
charset="UTF-8"
|
||||
message-converters="converterList"
|
||||
extract-payload="false"
|
||||
expected-response-type="java.lang.Boolean"
|
||||
request-factory="testRequestFactory"
|
||||
order="77"
|
||||
auto-startup="false"/>
|
||||
url="http://localhost/test2/{foo}"
|
||||
http-method="GET"
|
||||
channel="requests"
|
||||
charset="UTF-8"
|
||||
message-converters="converterList"
|
||||
extract-payload="false"
|
||||
expected-response-type="java.lang.Boolean"
|
||||
request-factory="testRequestFactory"
|
||||
order="77"
|
||||
auto-startup="false">
|
||||
<uri-variable name="foo" expression="headers.bar"/>
|
||||
</outbound-channel-adapter>
|
||||
|
||||
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
|
||||
|
||||
<beans:bean id="testParameterMapper" class="org.springframework.integration.http.DefaultParameterExtractor"/>
|
||||
|
||||
<util:list id="converterList">
|
||||
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
|
||||
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
|
||||
|
||||
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -27,6 +29,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
@@ -34,7 +37,6 @@ import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.http.DefaultOutboundRequestMapper;
|
||||
import org.springframework.integration.http.HttpRequestExecutingMessageHandler;
|
||||
import org.springframework.integration.http.OutboundRequestMapper;
|
||||
import org.springframework.integration.http.ParameterExtractor;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -54,9 +56,6 @@ public class HttpOutboundChannelAdapterParserTests {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private ParameterExtractor parameterExtractor;
|
||||
|
||||
|
||||
@Test
|
||||
public void minimalConfig() {
|
||||
@@ -80,6 +79,7 @@ public class HttpOutboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fullConfig() {
|
||||
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.fullConfigEndpoint);
|
||||
HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
|
||||
@@ -101,11 +101,14 @@ public class HttpOutboundChannelAdapterParserTests {
|
||||
Object requestFactoryBean = this.applicationContext.getBean("testRequestFactory");
|
||||
assertEquals(requestFactoryBean, requestFactory);
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
|
||||
assertEquals("http://localhost/test2", handlerAccessor.getPropertyValue("uri"));
|
||||
assertEquals("http://localhost/test2/{foo}", handlerAccessor.getPropertyValue("uri"));
|
||||
assertEquals(HttpMethod.GET, handlerAccessor.getPropertyValue("httpMethod"));
|
||||
assertEquals("UTF-8", mapperAccessor.getPropertyValue("charset"));
|
||||
assertEquals(false, mapperAccessor.getPropertyValue("extractPayload"));
|
||||
assertEquals(parameterExtractor, handlerAccessor.getPropertyValue("parameterExtractor"));
|
||||
Map<String, Expression> uriVariableExpressions =
|
||||
(Map<String, Expression>) handlerAccessor.getPropertyValue("uriVariableExpressions");
|
||||
assertEquals(1, uriVariableExpressions.size());
|
||||
assertEquals("headers.bar", uriVariableExpressions.get("foo").getExpressionString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,24 +21,23 @@
|
||||
</si:channel>
|
||||
|
||||
<outbound-gateway id="fullConfig"
|
||||
url="http://localhost/test2"
|
||||
parameter-extractor="testParameterMapper"
|
||||
http-method="PUT"
|
||||
request-channel="requests"
|
||||
request-factory="testRequestFactory"
|
||||
request-timeout="1234"
|
||||
message-converters="converterList"
|
||||
extract-request-payload="false"
|
||||
expected-response-type="java.lang.String"
|
||||
reply-channel="replies"
|
||||
charset="UTF-8"
|
||||
order="77"
|
||||
auto-startup="false"/>
|
||||
url="http://localhost/test2"
|
||||
http-method="PUT"
|
||||
request-channel="requests"
|
||||
request-factory="testRequestFactory"
|
||||
request-timeout="1234"
|
||||
message-converters="converterList"
|
||||
extract-request-payload="false"
|
||||
expected-response-type="java.lang.String"
|
||||
reply-channel="replies"
|
||||
charset="UTF-8"
|
||||
order="77"
|
||||
auto-startup="false">
|
||||
<uri-variable name="foo" expression="headers.bar"/>
|
||||
</outbound-gateway>
|
||||
|
||||
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
|
||||
|
||||
<beans:bean id="testParameterMapper" class="org.springframework.integration.http.DefaultParameterExtractor"/>
|
||||
|
||||
<util:list id="converterList">
|
||||
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
|
||||
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
|
||||
|
||||
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -28,6 +30,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
@@ -36,7 +39,6 @@ import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.http.DefaultOutboundRequestMapper;
|
||||
import org.springframework.integration.http.HttpRequestExecutingMessageHandler;
|
||||
import org.springframework.integration.http.OutboundRequestMapper;
|
||||
import org.springframework.integration.http.ParameterExtractor;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -56,8 +58,6 @@ public class HttpOutboundGatewayParserTests {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private ParameterExtractor parameterExtractor;
|
||||
|
||||
@Test
|
||||
public void minimalConfig() {
|
||||
@@ -83,6 +83,7 @@ public class HttpOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fullConfig() throws Exception {
|
||||
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.fullConfigEndpoint);
|
||||
HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
|
||||
@@ -114,7 +115,10 @@ public class HttpOutboundGatewayParserTests {
|
||||
Object sendTimeout = new DirectFieldAccessor(
|
||||
handlerAccessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout");
|
||||
assertEquals(new Long("1234"), sendTimeout);
|
||||
assertEquals(parameterExtractor, handlerAccessor.getPropertyValue("parameterExtractor"));
|
||||
Map<String, Expression> uriVariableExpressions =
|
||||
(Map<String, Expression>) handlerAccessor.getPropertyValue("uriVariableExpressions");
|
||||
assertEquals(1, uriVariableExpressions.size());
|
||||
assertEquals("headers.bar", uriVariableExpressions.get("foo").getExpressionString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user