INT-3054 URI Variable Mapping Improvements
Permit missing URI vars in HTTP outbound gateway Do not attempt to evaluate uri variables that are not in the URL The http gateway might not know what uri variables it might obtain in the URI. This patch makes sure that only the uri variables defined in the uri are parsed (the rest are ignored)
This commit is contained in:
committed by
Gary Russell
parent
0301f262e0
commit
3369d3f9b1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 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,10 +21,13 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
@@ -35,6 +38,7 @@ import org.springframework.integration.message.GenericMessage;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
* @author Wallace Wadge
|
||||
* @since 2.0
|
||||
*/
|
||||
public class UriVariableExpressionTests {
|
||||
@@ -65,4 +69,33 @@ public class UriVariableExpressionTests {
|
||||
assertEquals("http://test/bar", uriHolder.get().toString());
|
||||
}
|
||||
|
||||
/** Test for INT-3054: Do not break if there are extra uri variables defined in the http outbound gateway. */
|
||||
@Test
|
||||
public void testFromMessageWithSuperfluousExpressionsInt3054() throws Exception {
|
||||
final AtomicReference<URI> uriHolder = new AtomicReference<URI>();
|
||||
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://test/{foo}");
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Map<String, Expression> multipleExpressions = new HashMap<String, Expression>();
|
||||
multipleExpressions.put("foo", parser.parseExpression("payload"));
|
||||
multipleExpressions.put("extra-to-be-ignored", parser.parseExpression("headers.extra"));
|
||||
handler.setUriVariableExpressions(multipleExpressions);
|
||||
handler.setRequestFactory(new SimpleClientHttpRequestFactory() {
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user