use of com.fasterxml.jackson.core.async_.JsonFactory 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 com.fasterxml.jackson.core.async_.JsonFactory in project feign-reactive by kptfh.
the class JettyReactiveHttpResponse method body.
@Override
public Publisher<?> body() {
ReactorObjectReader reactorObjectReader = new ReactorObjectReader(jsonFactory);
Flux<ByteBuffer> content = directContent();
if (returnActualClass == ByteBuffer.class) {
return content;
} else if (returnActualClass.isAssignableFrom(String.class) && returnPublisherType == Mono.class) {
Charset charset = getCharset();
return content.map(byteBuffer -> charset.decode(byteBuffer).toString());
} else {
if (returnPublisherType == Mono.class) {
return reactorObjectReader.read(content, objectReader);
} else if (returnPublisherType == Flux.class) {
return reactorObjectReader.readElements(content, objectReader);
} else {
throw new IllegalArgumentException("Unknown returnPublisherType: " + returnPublisherType);
}
}
}
use of com.fasterxml.jackson.core.async_.JsonFactory in project feign-reactive by kptfh.
the class JettyReactiveFeign method builder.
public static <T> Builder<T> builder() {
try {
HttpClient httpClient = new HttpClient();
httpClient.start();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
return new Builder<>(httpClient, new JsonFactory(), objectMapper);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations