Skip to content

Instantly share code, notes, and snippets.

View deepakmehra10's full-sized avatar
🎯
Focusing

Deepak Mehra deepakmehra10

🎯
Focusing
View GitHub Profile
{
"guests": [{
"guestInformation": {
"guestReservationId": {
"guestId": "977828506",
"bookingId": "8502991"
},
"personalInfo": {
"guestTitle": "MR",
"firstName": "GUE",
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
public interface ContentService {
public Mono<Post> getPost(int id);
}
@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)
.retrieve()
.onStatus(HttpStatus::is4xxClientError, response ->
Mono.error(new MyCustomException())
)
.onStatus(HttpStatus::is5xxServerError, response ->
Mono.error(new MyCustomException())
)
.bodyToFlux(Post.class);
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
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\"}"));
private final MockWebServer mockWebServer = new MockWebServer();
<dependencies>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.9.3</version>
</dependency>
</dependencies>