Class ReactiveRequest
A reactive wrapper over Jetty's HttpClient
Request
.
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 Publisher
for a ReactiveResponse
passing a function that handles the response
content:
Publisher<T> response = request.response((response, content) -> { ... });
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A Builder for ReactiveRequest.static interface
A Publisher of content chunks that also specifies the content length and type.static class
A ReactiveRequest event. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ReactiveRequest
(org.eclipse.jetty.client.Request request) -
Method Summary
Modifier and TypeMethodDescriptionorg.eclipse.jetty.client.Request
static ReactiveRequest.Builder
newBuilder
(org.eclipse.jetty.client.HttpClient httpClient, String uri) static ReactiveRequest.Builder
newBuilder
(org.eclipse.jetty.client.Request request) org.reactivestreams.Publisher<ReactiveRequest.Event>
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<org.eclipse.jetty.io.Content.Chunk>, 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 givenBiFunction
.org.reactivestreams.Publisher<ReactiveResponse.Event>
toString()
-
Constructor Details
-
ReactiveRequest
protected ReactiveRequest(org.eclipse.jetty.client.Request request)
-
-
Method Details
-
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
- Parameters:
request
- the request instance- Returns:
- a builder for the given Request
-
getReactiveResponse
- Returns:
- the ReactiveResponse correspondent to this request, or null if the response is not available yet
-
getRequest
public org.eclipse.jetty.client.Request getRequest()- Returns:
- the wrapped Jetty request
-
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<org.eclipse.jetty.io.Content.Chunk>, 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 givenBiFunction
.The given
BiFunction
is called by the implementation when the response arrives, with theReactiveResponse
and the response content Publisher as parameters.Applications must subscribe (possibly asynchronously) to the response content Publisher, even if it is known that the response has no content, to receive the response success/failure events.
The response content Publisher emits
Content.Chunk
objects that must be eventually released (possibly asynchronously at a later time) by callingRetainable.release()
.- 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
- Returns:
- a Publisher for request events
-
responseEvents
-
toString
-