Skip to content

Commit e0c6d62

Browse files
authored
Fix compatibility issue with Spring Boot 3.4 (#155)
Fixes #153.
1 parent 1b1b614 commit e0c6d62

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

belgif-rest-problem-spring/src/main/java/io/github/belgif/rest/problem/spring/ProblemResponseErrorHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.github.belgif.rest.problem.spring;
22

33
import java.io.IOException;
4+
import java.net.URI;
45

56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
8+
import org.springframework.http.HttpMethod;
79
import org.springframework.http.MediaType;
810
import org.springframework.http.client.ClientHttpResponse;
911
import org.springframework.stereotype.Component;
@@ -29,7 +31,7 @@ public ProblemResponseErrorHandler(ObjectMapper objectMapper) {
2931
}
3032

3133
@Override
32-
public void handleError(ClientHttpResponse response) throws IOException, Problem {
34+
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
3335
if (ProblemMediaType.INSTANCE.isCompatibleWith(response.getHeaders().getContentType())
3436
|| response.getStatusCode().isError()
3537
&& MediaType.APPLICATION_JSON.isCompatibleWith(response.getHeaders().getContentType())) {
@@ -39,6 +41,6 @@ public void handleError(ClientHttpResponse response) throws IOException, Problem
3941
}
4042
throw problem;
4143
}
42-
super.handleError(response);
44+
super.handleError(url, method, response);
4345
}
4446
}

belgif-rest-problem-spring/src/test/java/io/github/belgif/rest/problem/spring/ProblemResponseErrorHandlerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.mockito.InjectMocks;
1414
import org.mockito.Mock;
1515
import org.mockito.junit.jupiter.MockitoExtension;
16+
import org.springframework.http.HttpMethod;
1617
import org.springframework.http.MediaType;
1718
import org.springframework.mock.http.client.MockClientHttpResponse;
1819
import org.springframework.web.client.HttpClientErrorException;
@@ -42,7 +43,7 @@ void problemMediaType() throws Exception {
4243
Problem problem = new BadRequestProblem();
4344
when(objectMapper.readValue(entityStream, Problem.class)).thenReturn(problem);
4445
assertThatExceptionOfType(BadRequestProblem.class)
45-
.isThrownBy(() -> handler.handleError(response))
46+
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response))
4647
.isEqualTo(problem);
4748
}
4849

@@ -55,7 +56,7 @@ void jsonMediaTypeErrorStatus() throws Exception {
5556
Problem problem = new BadRequestProblem();
5657
when(objectMapper.readValue(entityStream, Problem.class)).thenReturn(problem);
5758
assertThatExceptionOfType(BadRequestProblem.class)
58-
.isThrownBy(() -> handler.handleError(response))
59+
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response))
5960
.isEqualTo(problem);
6061
}
6162

@@ -66,7 +67,7 @@ void jsonMediaTypeNoErrorStatus() {
6667
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
6768

6869
assertThatExceptionOfType(UnknownHttpStatusCodeException.class)
69-
.isThrownBy(() -> handler.handleError(response));
70+
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response));
7071
}
7172

7273
@Test
@@ -78,7 +79,7 @@ void defaultProblem() throws Exception {
7879
Problem problem = new DefaultProblem(URI.create("type"), URI.create("href"), "Title", 400);
7980
when(objectMapper.readValue(entityStream, Problem.class)).thenReturn(problem);
8081
assertThatExceptionOfType(DefaultProblem.class)
81-
.isThrownBy(() -> handler.handleError(response))
82+
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response))
8283
.isEqualTo(problem);
8384
}
8485

@@ -89,7 +90,7 @@ void differentMediaType() {
8990
response.getHeaders().setContentType(MediaType.APPLICATION_XML);
9091

9192
assertThatExceptionOfType(HttpClientErrorException.BadRequest.class)
92-
.isThrownBy(() -> handler.handleError(response));
93+
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response));
9394
}
9495

9596
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- Aligns with version used on JBoss EAP 7.4 -->
2323
<version.jackson.minimal>2.12.7</version.jackson.minimal>
2424
<version.spring.boot.2>2.7.18</version.spring.boot.2>
25-
<version.spring.boot.3>3.3.4</version.spring.boot.3>
25+
<version.spring.boot.3>3.4.1</version.spring.boot.3>
2626
</properties>
2727

2828
<dependencyManagement>

src/main/asciidoc/release-notes.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ by standardized `urn:problem-type:belgif:input-validation:referencedResourceNotF
2828
** Support setting the "realm" attribute
2929
** Add "error_description" and "scope" attributes for missing_scope
3030

31+
*belgif-rest-problem-spring:*
32+
33+
* Fix compatibility issue with Spring Boot 3.4
34+
3135
*belgif-rest-problem-quarkus:*
3236

3337
* New module for https://quarkus.io/[Quarkus] support (only in JVM mode)

0 commit comments

Comments
 (0)