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
{ | |
"guests": [{ | |
"guestInformation": { | |
"guestReservationId": { | |
"guestId": "977828506", | |
"bookingId": "8502991" | |
}, | |
"personalInfo": { | |
"guestTitle": "MR", | |
"firstName": "GUE", |
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
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-webflux</artifactId> | |
</dependency> |
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
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-webflux</artifactId> | |
</dependency> |
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
public interface ContentService { | |
public Mono<Post> getPost(int id); | |
} |
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
@Service | |
public class ContentServiceImpl implements ContentService { | |
private static final Logger LOGGER = Logger.getLogger(ContentServiceImpl.class.getName()); | |
private final WebClient webClient; | |
public ContentServiceImpl(@Value("${content-service}") String baseURL) { | |
this.webClient = WebClient.builder().baseUrl(baseURL) | |
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) |
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
.retrieve() | |
.onStatus(HttpStatus::is4xxClientError, response -> | |
Mono.error(new MyCustomException()) | |
) | |
.onStatus(HttpStatus::is5xxServerError, response -> | |
Mono.error(new MyCustomException()) | |
) | |
.bodyToFlux(Post.class); |
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
<dependency> | |
<groupId>com.squareup.okhttp3</groupId> | |
<artifactId>mockwebserver</artifactId> | |
<version>3.8.0</version> | |
<scope>test</scope> | |
</dependency> |
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
mockWebServer.enqueue( | |
new MockResponse() | |
.setResponseCode(200) | |
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | |
.setBody("{\"userId\": 1,\"id\": 1, \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\", \"body\": \"quia et suscipit\"}")); |
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
private final MockWebServer mockWebServer = new MockWebServer(); |
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
<dependencies> | |
<dependency> | |
<groupId>io.vavr</groupId> | |
<artifactId>vavr</artifactId> | |
<version>0.9.3</version> | |
</dependency> | |
</dependencies> |
OlderNewer