Skip to content

Commit

Permalink
Fix compatibility issue with Spring Boot 3.4 (#155)
Browse files Browse the repository at this point in the history
Fixes #153.
  • Loading branch information
jpraet authored Jan 8, 2025
1 parent 1b1b614 commit e0c6d62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.belgif.rest.problem.spring;

import java.io.IOException;
import java.net.URI;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
Expand All @@ -29,7 +31,7 @@ public ProblemResponseErrorHandler(ObjectMapper objectMapper) {
}

@Override
public void handleError(ClientHttpResponse response) throws IOException, Problem {
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
if (ProblemMediaType.INSTANCE.isCompatibleWith(response.getHeaders().getContentType())
|| response.getStatusCode().isError()
&& MediaType.APPLICATION_JSON.isCompatibleWith(response.getHeaders().getContentType())) {
Expand All @@ -39,6 +41,6 @@ public void handleError(ClientHttpResponse response) throws IOException, Problem
}
throw problem;
}
super.handleError(response);
super.handleError(url, method, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.mock.http.client.MockClientHttpResponse;
import org.springframework.web.client.HttpClientErrorException;
Expand Down Expand Up @@ -42,7 +43,7 @@ void problemMediaType() throws Exception {
Problem problem = new BadRequestProblem();
when(objectMapper.readValue(entityStream, Problem.class)).thenReturn(problem);
assertThatExceptionOfType(BadRequestProblem.class)
.isThrownBy(() -> handler.handleError(response))
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response))
.isEqualTo(problem);
}

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

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

assertThatExceptionOfType(UnknownHttpStatusCodeException.class)
.isThrownBy(() -> handler.handleError(response));
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response));
}

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

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

assertThatExceptionOfType(HttpClientErrorException.BadRequest.class)
.isThrownBy(() -> handler.handleError(response));
.isThrownBy(() -> handler.handleError(URI.create("test"), HttpMethod.GET, response));
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- Aligns with version used on JBoss EAP 7.4 -->
<version.jackson.minimal>2.12.7</version.jackson.minimal>
<version.spring.boot.2>2.7.18</version.spring.boot.2>
<version.spring.boot.3>3.3.4</version.spring.boot.3>
<version.spring.boot.3>3.4.1</version.spring.boot.3>
</properties>

<dependencyManagement>
Expand Down
4 changes: 4 additions & 0 deletions src/main/asciidoc/release-notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ by standardized `urn:problem-type:belgif:input-validation:referencedResourceNotF
** Support setting the "realm" attribute
** Add "error_description" and "scope" attributes for missing_scope

*belgif-rest-problem-spring:*

* Fix compatibility issue with Spring Boot 3.4

*belgif-rest-problem-quarkus:*

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

0 comments on commit e0c6d62

Please sign in to comment.