use of org.eclipse.jetty.reactive.client.ContentChunk in project feign-reactive by kptfh.
the class JettyReactiveHttpClient method toCharSequenceChunk.
protected ContentChunk toCharSequenceChunk(Object data) {
CharBuffer charBuffer = CharBuffer.wrap((CharSequence) data);
ByteBuffer byteBuffer = UTF_8.encode(charBuffer);
return new ContentChunk(byteBuffer);
}
use of org.eclipse.jetty.reactive.client.ContentChunk 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 org.eclipse.jetty.reactive.client.ContentChunk in project feign-reactive by kptfh.
the class JettyReactiveHttpClient method toJsonChunk.
protected ContentChunk toJsonChunk(Object data, boolean stream) {
try {
ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
bodyWriter.writeValue(byteArrayBuilder, data);
if (stream) {
byteArrayBuilder.write(NEWLINE_SEPARATOR);
}
ByteBuffer buffer = ByteBuffer.wrap(byteArrayBuilder.toByteArray());
return new ContentChunk(buffer);
} catch (java.io.IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.eclipse.jetty.reactive.client.ContentChunk in project navajo by Dexels.
the class JettyClient method call.
public Flowable<ReactiveReply> call(String uri, UnaryOperator<Request> buildRequest, Optional<Flowable<byte[]>> requestBody, Optional<String> requestContentType) {
// Reque
Request req = httpClient.newRequest(uri);
Request reqProcessed = buildRequest.apply(req);
if (requestContentType.isPresent()) {
reqProcessed = reqProcessed.header("Content-Type", requestContentType.get());
}
ReactiveRequest.Builder requestBuilder = ReactiveRequest.newBuilder(reqProcessed);
if (requestBody.isPresent()) {
Publisher<ContentChunk> bb = requestBody.get().doOnNext(b -> this.sent.addAndGet(b.length)).map(e -> new ContentChunk(ByteBuffer.wrap(e)));
requestBuilder = requestBuilder.content(ReactiveRequest.Content.fromPublisher(bb, requestContentType.orElse("application/octet-stream")));
}
ReactiveRequest request = requestBuilder.build();
return Flowable.fromPublisher(request.response((response, content) -> Flowable.just(new ReactiveReply(response, content, b -> this.sent.addAndGet(b.length))))).doOnComplete(() -> logger.info("HTTP Client to {}: sent: {} received: {}", uri, sent.get(), received.get()));
}
Aggregations