use of reactivefeign.client.ReactiveHttpResponse in project feign-reactive by kptfh.
the class RestTemplateFakeReactiveHttpClient method executeRequest.
@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
Mono<Object> bodyMono;
if (request.body() instanceof Mono) {
bodyMono = ((Mono<Object>) request.body());
} else if (request.body() instanceof Flux) {
bodyMono = ((Flux) request.body()).collectList();
} else {
bodyMono = Mono.just(request.body());
}
bodyMono = bodyMono.switchIfEmpty(Mono.just(new byte[0]));
return bodyMono.<ReactiveHttpResponse>flatMap(body -> {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(request.headers());
if (acceptGzip) {
headers.add("Accept-Encoding", "gzip");
}
ResponseEntity response = restTemplate.exchange(request.uri().toString(), HttpMethod.valueOf(request.method()), new HttpEntity<>(body, headers), responseType());
return Mono.just(new FakeReactiveHttpResponse(response, returnPublisherType));
}).onErrorMap(ex -> ex instanceof ResourceAccessException && ex.getCause() instanceof SocketTimeoutException, ReadTimeoutException::new).onErrorResume(HttpStatusCodeException.class, ex -> Mono.just(new ErrorReactiveHttpResponse(ex)));
}
use of reactivefeign.client.ReactiveHttpResponse in project feign-reactive by kptfh.
the class JettyReactiveHttpClient method executeRequest.
@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
Request jettyRequest = httpClient.newRequest(request.uri()).method(request.method());
setUpHeaders(request, jettyRequest.getHeaders());
if (requestTimeout > 0) {
jettyRequest.timeout(requestTimeout, TimeUnit.MILLISECONDS);
}
ReactiveRequest.Builder requestBuilder = ReactiveRequest.newBuilder(jettyRequest);
if (bodyActualClass != null) {
ReactiveRequest.Content content = provideBody(request);
requestBuilder.content(content);
jettyRequest.getHeaders().put(CONTENT_TYPE.asString(), singletonList(content.getContentType()));
}
return Mono.<ReactiveHttpResponse>from(requestBuilder.build().response((response, content) -> Mono.just(new JettyReactiveHttpResponse(response.getResponse(), postProcess(content, (contentChunk, throwable) -> {
if (throwable != null) {
contentChunk.callback.failed(throwable);
} else {
contentChunk.callback.succeeded();
}
}), returnPublisherClass, returnActualClass, jsonFactory, responseReader)))).onErrorMap(ex -> ex instanceof java.util.concurrent.TimeoutException, ReadTimeoutException::new);
}
Aggregations