Top Description Inners Fields Constructors Methods
org.eclipse.jetty.reactive.client

public Class ReactiveRequest

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.nio.charset.Charset, java.util.function.BiFunction, org.eclipse.jetty.client.HttpClient, .Request, org.eclipse.jetty.io.Content.Chunk, org.eclipse.jetty.reactive.client.internal.AdapterRequestContent, .PublisherContent, .RequestEventPublisher, .ResponseEventPublisher, .ResponseListenerProcessor, .StringContent, org.reactivestreams.Publisher, .Subscription

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
ReactiveRequest.Builder

A Builder for ReactiveRequest.

public static interface
ReactiveRequest.Content

A Publisher of content chunks that also specifies the content length and type.

public static class
ReactiveRequest.Event

A ReactiveRequest event.

Field Summary

Modifier and TypeField and Description
private final boolean
private final Request
private final RequestEventPublisher
private volatile ReactiveResponse
private final ResponseEventPublisher

Constructor Summary

AccessConstructor and Description
protected
private
ReactiveRequest(Request request, boolean abortOnCancel)

Method Summary

Modifier and TypeMethod and Description
public ReactiveResponse

Returns:

the ReactiveResponse correspondent to this request, or null if the response is not available yet
getReactiveResponse
()

public Request

Returns:

the wrapped Jetty request
getRequest
()

public static ReactiveRequest.Builder

Returns:

a builder for a GET request for the given URI
newBuilder
(HttpClient
the HttpClient instance
httpClient
,
String
the target URI for the request - must be properly encoded already
uri
)

public static ReactiveRequest.Builder

Returns:

a builder for the given Request
newBuilder
(Request
the request instance
request
)

public Publisher<ReactiveRequest.Event>

Returns:

a Publisher for request events
requestEvents
()

public Publisher<ReactiveResponse>

Returns:

a Publisher for the response
response
()

Creates a Publisher that sends the request when a Subscriber requests the response via Subscription#request(long), discarding the response content.

public <
the element type of the processed response content
T
>
Publisher<T>

Returns:

a Publisher for the processed content
response
(BiFunction<ReactiveResponse, Publisher<Content.Chunk>, Publisher<T>>
the function that processes the response content
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 BiFunction.

public Publisher<ReactiveResponse.Event>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

abortOnCancelback to summary
private final boolean abortOnCancel
requestback to summary
private final Request request
requestEventsback to summary
private final RequestEventPublisher requestEvents
responseback to summary
private volatile ReactiveResponse response
responseEventsback to summary
private final ResponseEventPublisher responseEvents

Constructor Detail

ReactiveRequestback to summary
protected ReactiveRequest(Request request)
ReactiveRequestback to summary
private ReactiveRequest(Request request, boolean abortOnCancel)

Method Detail

getReactiveResponseback to summary
public ReactiveResponse getReactiveResponse()
Returns:ReactiveResponse

the ReactiveResponse correspondent to this request, or null if the response is not available yet

getRequestback to summary
public Request getRequest()
Returns:Request

the wrapped Jetty request

newBuilderback to summary
public static ReactiveRequest.Builder newBuilder(HttpClient httpClient, String uri)
Parameters
httpClient:HttpClient

the HttpClient instance

uri:String

the target URI for the request - must be properly encoded already

Returns:ReactiveRequest.Builder

a builder for a GET request for the given URI

newBuilderback to summary
public static ReactiveRequest.Builder newBuilder(Request request)
Parameters
request:Request

the request instance

Returns:ReactiveRequest.Builder

a builder for the given Request

requestEventsback to summary
public Publisher<ReactiveRequest.Event> requestEvents()
Returns:Publisher<ReactiveRequest.Event>

a Publisher for request events

responseback to summary
public 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:Publisher<ReactiveResponse>

a Publisher for the response

responseback to summary
public <T> Publisher<T> response(BiFunction<ReactiveResponse, Publisher<Content.Chunk>, 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 BiFunction.

The given BiFunction is called by the implementation when the response arrives, with the ReactiveResponse 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 Chunk objects that must be eventually released (possibly asynchronously at a later time) by calling Chunk#release().

Parameters
<T>
the element type of the processed response content
contentFn:BiFunction<ReactiveResponse, Publisher<Content.Chunk>, Publisher<T>>

the function that processes the response content

Returns:Publisher<T>

a Publisher for the processed content

responseEventsback to summary
public Publisher<ReactiveResponse.Event> responseEvents()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.eclipse.jetty.reactive.client back to summary

public Class ReactiveRequest.Builder

extends Object
Class Inheritance

A Builder for ReactiveRequest.

Field Summary

Modifier and TypeField and Description
private boolean
private final Request

Constructor Summary

AccessConstructor and Description
public
Builder(HttpClient client, String uri)

public
Builder(Request request)

Method Summary

Modifier and TypeMethod and Description
public ReactiveRequest.Builder

Returns:

this instance
abortOnCancel
(boolean
whether a request should be aborted when the content subscriber cancels the subscription
abortOnCancel
)

public ReactiveRequest

Returns:

a built ReactiveRequest
build
()

public ReactiveRequest.Builder

Returns:

this instance
content
(ReactiveRequest.Content
the request content
content
)

Provides the request content via a Publisher.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

abortOnCancelback to summary
private boolean abortOnCancel
requestback to summary
private final Request request

Constructor Detail

Builderback to summary
public Builder(HttpClient client, String uri)
Builderback to summary
public Builder(Request request)

Method Detail

abortOnCancelback to summary
public ReactiveRequest.Builder abortOnCancel(boolean abortOnCancel)
Parameters
abortOnCancel:boolean

whether a request should be aborted when the content subscriber cancels the subscription

Returns:ReactiveRequest.Builder

this instance

buildback to summary
public ReactiveRequest build()
Returns:ReactiveRequest

a built ReactiveRequest

contentback to summary
public ReactiveRequest.Builder content(ReactiveRequest.Content content)

Provides the request content via a Publisher.

Parameters
content:ReactiveRequest.Content

the request content

Returns:ReactiveRequest.Builder

this instance

org.eclipse.jetty.reactive.client back to summary

public Interface ReactiveRequest.Content

extends Publisher<Content.Chunk>
Known Direct Implementers
org.eclipse.jetty.reactive.client.internal.PublisherContent, org.eclipse.jetty.reactive.client.internal.StringContent

A Publisher of content chunks that also specifies the content length and type.

Method Summary

Modifier and TypeMethod and Description
public static ReactiveRequest.Content

Returns:

a Content wrapping the given Chunks
fromPublisher
(Publisher<Content.Chunk>
the request content Chunks
publisher
,
String
the request content type
contentType
)

Creates a Content from the given Publisher of Chunks.

public static ReactiveRequest.Content

Returns:

a Content wrapping the given Chunks
fromPublisher
(Publisher<Content.Chunk>
the request content Chunks
publisher
,
String
the request content media type
mediaType
,
Charset
the request content charset
charset
)

Creates a Content from the given Publisher of Chunks.

public static ReactiveRequest.Content
fromString(String string, String mediaType, Charset charset)

public String

Returns:

the content type in the form media_type[;charset=<charset>]
getContentType
()

public long

Returns:

the content length
getLength
()

public default boolean

Returns:

whether this request content was rewound
rewind
()

Rewinds this content, if possible.

Inherited from org.reactivestreams.Publisher:
subscribe

Method Detail

fromPublisherback to summary
public static ReactiveRequest.Content fromPublisher(Publisher<Content.Chunk> publisher, String contentType)

Creates a Content from the given Publisher of Chunks.

The implementation will call Chunk#release() on each Chunk.

Parameters
publisher:Publisher<Content.Chunk>

the request content Chunks

contentType:String

the request content type

Returns:ReactiveRequest.Content

a Content wrapping the given Chunks

fromPublisherback to summary
public static ReactiveRequest.Content fromPublisher(Publisher<Content.Chunk> publisher, String mediaType, Charset charset)

Creates a Content from the given Publisher of Chunks.

The implementation will call Chunk#release() on each Chunk.

Parameters
publisher:Publisher<Content.Chunk>

the request content Chunks

mediaType:String

the request content media type

charset:Charset

the request content charset

Returns:ReactiveRequest.Content

a Content wrapping the given Chunks

fromStringback to summary
public static ReactiveRequest.Content fromString(String string, String mediaType, Charset charset)
getContentTypeback to summary
public String getContentType()
Returns:String

the content type in the form media_type[;charset=<charset>]

getLengthback to summary
public long getLength()
Returns:long

the content length

rewindback to summary
public default boolean rewind()

Rewinds this content, if possible.

Returns:boolean

whether this request content was rewound

org.eclipse.jetty.reactive.client back to summary

public Class ReactiveRequest.Event

extends Object
Class Inheritance

A ReactiveRequest event.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final Throwable
private final ReactiveRequest
private final ReactiveRequest.Event.Type

Constructor Summary

AccessConstructor and Description
public
public
public
private

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer

Returns:

the event content, or null if this is not a content event
getContent
()

public Throwable

Returns:

the event failure, or null if this is not a failure event
getFailure
()

public ReactiveRequest

Returns:

the request that generated this event
getRequest
()

public ReactiveRequest.Event.Type

Returns:

the event type
getType
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
private final ByteBuffer content
failureback to summary
private final Throwable failure
requestback to summary
private final ReactiveRequest request
typeback to summary
private final ReactiveRequest.Event.Type type

Constructor Detail

Eventback to summary
public Event(ReactiveRequest.Event.Type type, ReactiveRequest request)
Eventback to summary
public Event(ReactiveRequest.Event.Type type, ReactiveRequest request, ByteBuffer content)
Eventback to summary
public Event(ReactiveRequest.Event.Type type, ReactiveRequest request, Throwable failure)
Eventback to summary
private Event(ReactiveRequest.Event.Type type, ReactiveRequest request, ByteBuffer content, Throwable failure)

Method Detail

getContentback to summary
public ByteBuffer getContent()
Returns:ByteBuffer

the event content, or null if this is not a content event

getFailureback to summary
public Throwable getFailure()
Returns:Throwable

the event failure, or null if this is not a failure event

getRequestback to summary
public ReactiveRequest getRequest()
Returns:ReactiveRequest

the request that generated this event

getTypeback to summary
public ReactiveRequest.Event.Type getType()
Returns:ReactiveRequest.Event.Type

the event type

org.eclipse.jetty.reactive.client back to summary

public final Enum ReactiveRequest.Event.Type

extends Enum<ReactiveRequest.Event.Type>
Class Inheritance

The event types

Field Summary

Modifier and TypeField and Description
public static final ReactiveRequest.Event.Type
BEGIN

The request is ready to be sent

public static final ReactiveRequest.Event.Type
COMMIT

The request headers have been sent

public static final ReactiveRequest.Event.Type
CONTENT

A chunk of content has been sent

public static final ReactiveRequest.Event.Type
FAILURE

The request failed

public static final ReactiveRequest.Event.Type
HEADERS

The request headers have been prepared

public static final ReactiveRequest.Event.Type
QUEUED

The request has been queued

public static final ReactiveRequest.Event.Type
SUCCESS

The request succeeded

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public static ReactiveRequest.Event.Type
public static ReactiveRequest.Event.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BEGINback to summary
public static final ReactiveRequest.Event.Type BEGIN

The request is ready to be sent

COMMITback to summary
public static final ReactiveRequest.Event.Type COMMIT

The request headers have been sent

CONTENTback to summary
public static final ReactiveRequest.Event.Type CONTENT

A chunk of content has been sent

FAILUREback to summary
public static final ReactiveRequest.Event.Type FAILURE

The request failed

HEADERSback to summary
public static final ReactiveRequest.Event.Type HEADERS

The request headers have been prepared

QUEUEDback to summary
public static final ReactiveRequest.Event.Type QUEUED

The request has been queued

SUCCESSback to summary
public static final ReactiveRequest.Event.Type SUCCESS

The request succeeded

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static ReactiveRequest.Event.Type valueOf(String name)
valuesback to summary
public static ReactiveRequest.Event.Type[] values()