Class ReactiveRequest
public class ReactiveRequest extends Object
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 Classes Modifier and Type Class Description static class
ReactiveRequest.Builder
A Builder for ReactiveRequest.static interface
ReactiveRequest.Content
A Publisher of content chunks that also specifies the content length and type.static class
ReactiveRequest.Event
A ReactiveRequest event. -
Constructor Summary
Constructors Modifier Constructor Description protected
ReactiveRequest(org.eclipse.jetty.client.api.Request request)
-
Method Summary
Modifier and Type Method Description ReactiveResponse
getReactiveResponse()
org.eclipse.jetty.client.api.Request
getRequest()
static ReactiveRequest.Builder
newBuilder(org.eclipse.jetty.client.api.Request request)
static ReactiveRequest.Builder
newBuilder(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()
String
toString()
-
Constructor Details
-
ReactiveRequest
protected ReactiveRequest(org.eclipse.jetty.client.api.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.api.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<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.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.
- 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
-