Class ReactiveRequest
- java.lang.Object
-
- org.eclipse.jetty.reactive.client.ReactiveRequest
-
public class ReactiveRequest extends Object
A reactive wrapper over Jetty's
HttpClientRequest.A ReactiveRequest can be obtained via a builder:
// Built with HttpClient and a string URI. ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri()).build(); // Built by wrapping a Request. Request req = httpClient.newRequest(...); ... ReactiveRequest request = ReactiveRequest.newBuilder(req).build();
Once created, a ReactiveRequest can be sent to obtain a
Publisherfor aReactiveResponsepassing a function that handles the response content:Publisher<T> response = request.response((response, content) -> { ... });
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReactiveRequest.BuilderA Builder for ReactiveRequest.static interfaceReactiveRequest.ContentA Publisher of content chunks that also specifies the content length and type.static classReactiveRequest.EventA ReactiveRequest event.
-
Constructor Summary
Constructors Modifier Constructor Description protectedReactiveRequest(org.eclipse.jetty.client.api.Request request)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ReactiveResponsegetReactiveResponse()org.eclipse.jetty.client.api.RequestgetRequest()static ReactiveRequest.BuildernewBuilder(org.eclipse.jetty.client.api.Request request)static ReactiveRequest.BuildernewBuilder(org.eclipse.jetty.client.HttpClient httpClient, String uri)org.reactivestreams.Publisher<ReactiveRequest.Event>requestEvents()org.reactivestreams.Publisher<ReactiveResponse>response()Creates a Publisher that sends the request when a Subscriber requests the response viaSubscription.request(long), discarding the response content.<T> org.reactivestreams.Publisher<T>response(BiFunction<ReactiveResponse,org.reactivestreams.Publisher<ContentChunk>,org.reactivestreams.Publisher<T>> contentFn)Creates a Publisher that sends the request when a Subscriber requests the response viaSubscription.request(long), processing the response content with the given function.org.reactivestreams.Publisher<ReactiveResponse.Event>responseEvents()StringtoString()
-
-
-
Method Detail
-
newBuilder
public static ReactiveRequest.Builder newBuilder(org.eclipse.jetty.client.HttpClient httpClient, String uri)
- Parameters:
httpClient- the HttpClient instanceuri- the target URI for the request - must be properly encoded already- Returns:
- a builder for a GET request for the given URI
-
newBuilder
public static ReactiveRequest.Builder newBuilder(org.eclipse.jetty.client.api.Request request)
- Parameters:
request- the request instance- Returns:
- a builder for the given Request
-
getReactiveResponse
public ReactiveResponse getReactiveResponse()
- Returns:
- the ReactiveResponse correspondent to this request, or null if the response is not available yet
-
getRequest
public org.eclipse.jetty.client.api.Request getRequest()
- Returns:
- the wrapped Jetty request
-
response
public org.reactivestreams.Publisher<ReactiveResponse> response()
Creates a Publisher that sends the request when a Subscriber requests the response via
Subscription.request(long), discarding the response content.- Returns:
- a Publisher for the response
-
response
public <T> org.reactivestreams.Publisher<T> response(BiFunction<ReactiveResponse,org.reactivestreams.Publisher<ContentChunk>,org.reactivestreams.Publisher<T>> contentFn)
Creates a Publisher that sends the request when a Subscriber requests the response via
Subscription.request(long), processing the response content with the given function.- Type Parameters:
T- the element type of the processed response content- Parameters:
contentFn- the function that processes the response content- Returns:
- a Publisher for the processed content
-
requestEvents
public org.reactivestreams.Publisher<ReactiveRequest.Event> requestEvents()
- Returns:
- a Publisher for request events
-
responseEvents
public org.reactivestreams.Publisher<ReactiveResponse.Event> responseEvents()
-
-