.exchange() // .onErrorReturn(ConnectException.class, ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE).build());
private Mono<ResponseEntity<T>> exchange(RequestEntity<?> requestEntity) { Type type = this.responseType; RequestBodySpec builder = rest.method(requestEntity.getMethod()) .uri(requestEntity.getUrl()) .headers(headers -> addHeaders(headers, requestEntity.getHeaders())); Mono<ClientResponse> result; if (requestEntity.getBody() instanceof Publisher) { @SuppressWarnings("unchecked") Publisher<Object> publisher = (Publisher<Object>) requestEntity.getBody(); result = builder.body(publisher, Object.class).exchange(); } else if (requestEntity.getBody() != null) { result = builder.body(BodyInserters.fromObject(requestEntity.getBody())) .exchange(); } else { if (hasBody) { result = builder.headers( headers -> addHeaders(headers, exchange.getRequest().getHeaders())) .body(exchange.getRequest().getBody(), DataBuffer.class) .exchange(); } else { result = builder.headers( headers -> addHeaders(headers, exchange.getRequest().getHeaders())) .exchange(); } } return result.flatMap(response -> response.toEntity(ParameterizedTypeReference.forType(type))); }
requestSpec.exchange() .flatMap(response -> { HttpStatus httpStatus = response.statusCode();
@Override public Mono<VaultResponse> write(String path, @Nullable Object body) { Assert.hasText(path, "Path must not be empty"); RequestBodySpec uri = sessionClient.post().uri(path); Mono<ClientResponse> exchange; if (body != null) { exchange = uri.syncBody(body).exchange(); } else { exchange = uri.exchange(); } return exchange.flatMap(mapResponse(VaultResponse.class, path)); }
private Mono<ResponseEntity<Void>> requestCar(Car car) { return bookClient.post() .uri("/cars/{id}/booking", car.getId()) .exchange() .flatMap(response -> response.toEntity(Void.class)); }