Skip to content

Commit adebbb8

Browse files
authored
Create InterceptingClientHttpRequestTest.java BAEL-8373 Support Request Attributes in RestClient (#18384)
* Create InterceptingClientHttpRequestTest.java * Update pom.xml * Update InterceptingClientHttpRequestTest.java * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update InterceptingClientHttpRequestTest.java * Update InterceptingClientHttpRequestTest.java * Update InterceptingClientHttpRequestTest.java
1 parent 672d947 commit adebbb8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spring-boot-modules/spring-boot-3-2/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
</parent>
1616

1717
<dependencies>
18+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-web</artifactId>
22+
<version>6.2.3</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-core</artifactId>
27+
<version>6.2.3</version>
28+
</dependency>
1829
<dependency>
1930
<groupId>org.springframework.boot</groupId>
2031
<artifactId>spring-boot-starter-web</artifactId>
32+
<version>3.4.3</version>
2133
</dependency>
2234
<dependency>
2335
<groupId>org.springframework.boot</groupId>
@@ -93,6 +105,7 @@
93105
<dependency>
94106
<groupId>org.springframework.boot</groupId>
95107
<artifactId>spring-boot-starter-test</artifactId>
108+
<version>3.4.3</version>
96109
</dependency>
97110
<dependency>
98111
<groupId>org.postgresql</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.restclient;
2+
3+
4+
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
6+
7+
import org.springframework.http.HttpMethod;
8+
import org.springframework.http.HttpRequest;
9+
import org.springframework.http.client.ClientHttpRequestInterceptor;
10+
import org.springframework.http.client.ClientHttpResponse;
11+
import org.springframework.http.client.ClientHttpRequest;
12+
import org.springframework.http.client.support.HttpRequestWrapper;
13+
14+
15+
class InterceptingClientHttpRequestTest {
16+
17+
@Test
18+
void updateRequestAttribute() throws Exception {
19+
String attrName = "attr1";
20+
String attrValue = "value1";
21+
22+
assertDoesNotThrow(() -> {
23+
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
24+
request.getAttributes().put(attrName, attrValue);
25+
return execution.execute(request, body);
26+
};
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)