Search in sources :

Example 1 with Buffer

use of io.vertx.rxjava3.core.buffer.Buffer in project julian-http-client by ljtfreitas.

the class VertxHTTPClientResponse method valueOf.

static Single<VertxHTTPClientResponse> valueOf(HttpClientResponse response) {
    HTTPStatus status = HTTPStatusCode.select(response.statusCode()).map(HTTPStatus::new).orElseGet(() -> new HTTPStatus(response.statusCode(), response.statusMessage()));
    HTTPHeaders headers = response.headers().names().stream().map(name -> HTTPHeader.create(name, response.headers().getAll(name))).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
    Maybe<byte[]> bodyAsBytes = response.body().map(Buffer::getBytes).toMaybe();
    return bodyAsBytes.map(body -> HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.some(body))).map(body -> new VertxHTTPClientResponse(HTTPClientResponse.create(status, headers, body))).switchIfEmpty(Single.fromCallable(() -> new VertxHTTPClientResponse(HTTPClientResponse.empty(status, headers))));
}
Also used : Single(io.reactivex.rxjava3.core.Single) Function(java.util.function.Function) HTTPResponseBody(com.github.ljtfreitas.julian.http.HTTPResponseBody) HTTPStatusCode(com.github.ljtfreitas.julian.http.HTTPStatusCode) Maybe(io.reactivex.rxjava3.core.Maybe) Response(com.github.ljtfreitas.julian.Response) HTTPHeader(com.github.ljtfreitas.julian.http.HTTPHeader) HTTPHeaders(com.github.ljtfreitas.julian.http.HTTPHeaders) HTTPStatus(com.github.ljtfreitas.julian.http.HTTPStatus) Optional(java.util.Optional) Buffer(io.vertx.rxjava3.core.buffer.Buffer) HTTPClientResponse(com.github.ljtfreitas.julian.http.client.HTTPClientResponse) HttpClientResponse(io.vertx.rxjava3.core.http.HttpClientResponse) HTTPHeaders(com.github.ljtfreitas.julian.http.HTTPHeaders) HTTPStatus(com.github.ljtfreitas.julian.http.HTTPStatus)

Example 2 with Buffer

use of io.vertx.rxjava3.core.buffer.Buffer in project julian-http-client by ljtfreitas.

the class RxVertxHTTPClient method request.

@Override
public HTTPClientRequest request(HTTPRequestDefinition request) {
    RequestOptions options = new RequestOptions().setAbsoluteURI(request.path().toString()).setMethod(HttpMethod.valueOf(request.method().name())).setHeaders(request.headers().all().stream().reduce(MultiMap.caseInsensitiveMultiMap(), (m, h) -> m.add(h.name(), h.values()), (a, b) -> b));
    Flowable<Buffer> bodyAsFlowable = request.body().map(b -> FlowAdapters.toPublisher(b.serialize())).map(Flowable::fromPublisher).orElseGet(Flowable::empty).map(buf -> Buffer.buffer(buf.array()));
    return new VertxHTTPClientRequest(client, options, bodyAsFlowable);
}
Also used : HTTPClient(com.github.ljtfreitas.julian.http.client.HTTPClient) HTTPClientRequest(com.github.ljtfreitas.julian.http.client.HTTPClientRequest) FlowAdapters(org.reactivestreams.FlowAdapters) Flowable(io.reactivex.rxjava3.core.Flowable) HttpMethod(io.vertx.core.http.HttpMethod) Closeable(java.io.Closeable) MultiMap(io.vertx.core.MultiMap) HttpClient(io.vertx.rxjava3.core.http.HttpClient) RequestOptions(io.vertx.core.http.RequestOptions) IOException(java.io.IOException) Buffer(io.vertx.rxjava3.core.buffer.Buffer) HTTPRequestDefinition(com.github.ljtfreitas.julian.http.HTTPRequestDefinition) Buffer(io.vertx.rxjava3.core.buffer.Buffer) RequestOptions(io.vertx.core.http.RequestOptions) Flowable(io.reactivex.rxjava3.core.Flowable)

Aggregations

Buffer (io.vertx.rxjava3.core.buffer.Buffer)2 Response (com.github.ljtfreitas.julian.Response)1 HTTPHeader (com.github.ljtfreitas.julian.http.HTTPHeader)1 HTTPHeaders (com.github.ljtfreitas.julian.http.HTTPHeaders)1 HTTPRequestDefinition (com.github.ljtfreitas.julian.http.HTTPRequestDefinition)1 HTTPResponseBody (com.github.ljtfreitas.julian.http.HTTPResponseBody)1 HTTPStatus (com.github.ljtfreitas.julian.http.HTTPStatus)1 HTTPStatusCode (com.github.ljtfreitas.julian.http.HTTPStatusCode)1 HTTPClient (com.github.ljtfreitas.julian.http.client.HTTPClient)1 HTTPClientRequest (com.github.ljtfreitas.julian.http.client.HTTPClientRequest)1 HTTPClientResponse (com.github.ljtfreitas.julian.http.client.HTTPClientResponse)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Maybe (io.reactivex.rxjava3.core.Maybe)1 Single (io.reactivex.rxjava3.core.Single)1 MultiMap (io.vertx.core.MultiMap)1 HttpMethod (io.vertx.core.http.HttpMethod)1 RequestOptions (io.vertx.core.http.RequestOptions)1 HttpClient (io.vertx.rxjava3.core.http.HttpClient)1 HttpClientResponse (io.vertx.rxjava3.core.http.HttpClientResponse)1 Closeable (java.io.Closeable)1