-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for RestClient API (#75)
Fixes #74.
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
public enum Client { | ||
|
||
REST_TEMPLATE, WEB_CLIENT | ||
REST_TEMPLATE, WEB_CLIENT, REST_CLIENT | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...oot-3/src/main/java/io/github/belgif/rest/problem/spring/ProblemRestClientCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.belgif.rest.problem.spring; | ||
|
||
import org.springframework.boot.web.client.RestClientCustomizer; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestClient; | ||
|
||
/** | ||
* RestClientCustomizer that registers the {@link ProblemResponseErrorHandler}. | ||
* | ||
* @see ProblemResponseErrorHandler | ||
*/ | ||
@Component | ||
public class ProblemRestClientCustomizer implements RestClientCustomizer { | ||
|
||
private final ProblemResponseErrorHandler errorHandler; | ||
|
||
public ProblemRestClientCustomizer(ProblemResponseErrorHandler errorHandler) { | ||
this.errorHandler = errorHandler; | ||
} | ||
|
||
@Override | ||
public void customize(RestClient.Builder restClientBuilder) { | ||
restClientBuilder.defaultStatusHandler(errorHandler); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...3/src/test/java/io/github/belgif/rest/problem/spring/ProblemRestClientCustomizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.belgif.rest.problem.spring; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
class ProblemRestClientCustomizerTest { | ||
|
||
@Test | ||
void customize() { | ||
ProblemResponseErrorHandler handler = new ProblemResponseErrorHandler(new ObjectMapper()); | ||
ProblemRestClientCustomizer customizer = new ProblemRestClientCustomizer(handler); | ||
RestClient.Builder builder = RestClient.builder(); | ||
customizer.customize(builder); | ||
|
||
List<?> statusHandlers = (List<?>) ReflectionTestUtils.getField(builder, "statusHandlers"); | ||
assertThat(statusHandlers).hasSize(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters