Skip to content

Commit 113716e

Browse files
committed
INT-3526 Used Expanded URI In Exception Message
JIRA: https://jira.spring.io/browse/INT-3526 Previously, the URI in the exception message is the raw URI with placeholders, if present. Use the expanded URI in the message instead.
1 parent a7b5158 commit 113716e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ public String convert(Object source) {
397397
protected Object handleRequestMessage(Message<?> requestMessage) {
398398
String uri = this.uriExpression.getValue(this.evaluationContext, requestMessage, String.class);
399399
Assert.notNull(uri, "URI Expression evaluation cannot result in null");
400+
URI realUri = null;
400401
try {
401402
HttpMethod httpMethod = this.determineHttpMethod(requestMessage);
402403

@@ -412,7 +413,7 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
412413
HttpEntity<?> httpRequest = this.generateHttpRequest(requestMessage, httpMethod);
413414
Map<String, ?> uriVariables = this.determineUriVariables(requestMessage);
414415
UriComponents uriComponents = UriComponentsBuilder.fromUriString(uri).buildAndExpand(uriVariables);
415-
URI realUri = this.encodeUri ? uriComponents.toUri() : new URI(uriComponents.toUriString());
416+
realUri = this.encodeUri ? uriComponents.toUri() : new URI(uriComponents.toUriString());
416417
ResponseEntity<?> httpResponse;
417418
if (expectedResponseType instanceof ParameterizedTypeReference<?>) {
418419
httpResponse = this.restTemplate.exchange(realUri, httpMethod, httpRequest, (ParameterizedTypeReference<?>) expectedResponseType);
@@ -445,7 +446,9 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
445446
throw e;
446447
}
447448
catch (Exception e) {
448-
throw new MessageHandlingException(requestMessage, "HTTP request execution failed for URI [" + uri + "]", e);
449+
throw new MessageHandlingException(requestMessage, "HTTP request execution failed for URI ["
450+
+ (realUri == null ? uri : realUri.toString())
451+
+ "]", e);
449452
}
450453
}
451454

spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package org.springframework.integration.http.outbound;
1818

19+
import static org.hamcrest.Matchers.containsString;
1920
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertThat;
2022
import static org.junit.Assert.fail;
2123
import static org.mockito.Mockito.mock;
2224

@@ -71,6 +73,7 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
7173
}
7274
catch (Exception e) {
7375
assertEquals("intentional", e.getCause().getMessage());
76+
assertThat(e.getMessage(), containsString("http://test/bar"));
7477
}
7578
assertEquals("http://test/bar", uriHolder.get().toString());
7679
}

0 commit comments

Comments
 (0)