use of reactivefeign.client.ReactiveHttpRequest in project feign-reactive by kptfh.
the class ReactiveClientMethodHandler method buildRequest.
protected ReactiveHttpRequest buildRequest(Object[] argv) {
Map<String, ?> substitutionsMap = methodMetadata.indexToName().entrySet().stream().flatMap(e -> e.getValue().stream().map(v -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), v))).collect(Collectors.toMap(Map.Entry::getValue, entry -> argv[entry.getKey()]));
HttpMethod method = HttpMethod.resolve(methodMetadata.template().method());
URI uri = defaultUriBuilderFactory.uriString(methodMetadata.template().url()).queryParams(parameters(argv)).build(substitutionsMap);
return new ReactiveHttpRequest(method, uri, headers(argv, substitutionsMap), body(argv));
}
use of reactivefeign.client.ReactiveHttpRequest 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.ReactiveHttpRequest 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);
}
use of reactivefeign.client.ReactiveHttpRequest in project feign-reactive by kptfh.
the class RibbonPublisherClient method executeRequest.
@Override
public Publisher<?> executeRequest(ReactiveHttpRequest request) {
if (loadBalancerCommand != null) {
Observable<?> observable = loadBalancerCommand.submit(server -> {
ReactiveHttpRequest lbRequest = loadBalanceRequest(request, server);
Publisher<Object> publisher = (Publisher<Object>) publisherClient.executeRequest(lbRequest);
return RxReactiveStreams.toObservable(publisher);
});
Publisher<?> publisher = RxReactiveStreams.toPublisher(observable);
if (publisherType == Mono.class) {
return Mono.from(publisher);
} else if (publisherType == Flux.class) {
return Flux.from(publisher);
} else {
throw new IllegalArgumentException("Unknown publisherType: " + publisherType);
}
} else {
return publisherClient.executeRequest(request);
}
}
use of reactivefeign.client.ReactiveHttpRequest in project feign-reactive by kptfh.
the class PublisherClientMethodHandler method buildRequest.
protected ReactiveHttpRequest buildRequest(Object[] argv) {
Map<String, ?> substitutionsMap = methodMetadata.indexToName().entrySet().stream().flatMap(e -> e.getValue().stream().map(v -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), v))).collect(Collectors.toMap(Map.Entry::getValue, entry -> argv[entry.getKey()]));
try {
String path = pathExpander.apply(substitutionsMap);
Map<String, Collection<String>> queries = queries(argv, substitutionsMap);
Map<String, List<String>> headers = headers(argv, substitutionsMap);
URI uri = new URI(target.url() + path + queryLine(queries));
return new ReactiveHttpRequest(methodMetadata.template().method(), uri, headers, body(argv));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
Aggregations