Class SseRequestResult.HandshakeAccepted
java.lang.Object
com.soklet.SseRequestResult.HandshakeAccepted
- All Implemented Interfaces:
SseRequestResult
- Enclosing interface:
SseRequestResult
@ThreadSafe
public static final class SseRequestResult.HandshakeAccepted
extends Object
implements SseRequestResult
Represents the result of an SSE accepted handshake (connection stays open) when simulated by
Simulator.performSseRequest(Request).
The registerEventConsumer(Consumer) and registerCommentConsumer(Consumer) methods can be used to "listen" for Server-Sent Events and Comments, respectively.
The data provided when the handshake was accepted is available via getSseHandshakeResult(), and the final data sent to the client is available via getHttpRequestResult().
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from interface SseRequestResult
SseRequestResult.HandshakeAccepted, SseRequestResult.HandshakeRejected, SseRequestResult.RequestFailed -
Method Summary
Modifier and TypeMethodDescriptionThe initial result of the handshake, as written back to the client (note that the connection remains open).Gets the data provided when the handshake was accepted by theSseEventSource-annotated Resource Method.voidregisterCommentConsumer(@NonNull Consumer<SseComment> commentConsumer) Registers a Server-Sent comment "consumer" for this connection - similar to how a real client would listen for Server-Sent comment payloads.voidregisterEventConsumer(@NonNull Consumer<SseEvent> eventConsumer) Registers aSseEvent"consumer" for this connection - similar to how a real client would listen for Server-Sent Events.toString()
-
Method Details
-
registerEventConsumer
Registers aSseEvent"consumer" for this connection - similar to how a real client would listen for Server-Sent Events.Each connection may have at most 1 event consumer.
See documentation at https://www.soklet.com/docs/testing#server-sent-events.
- Parameters:
eventConsumer- function to be invoked when a Server-Sent Event has been unicast/broadcast on the Resource Path- Throws:
IllegalStateException- if you attempt to register more than 1 event consumer
-
registerCommentConsumer
Registers a Server-Sent comment "consumer" for this connection - similar to how a real client would listen for Server-Sent comment payloads.Each connection may have at most 1 comment consumer.
See documentation at https://www.soklet.com/docs/testing#server-sent-events.
- Parameters:
commentConsumer- function to be invoked when a Server-Sent comment has been unicast/broadcast on the Resource Path- Throws:
IllegalStateException- if you attempt to register more than 1 comment consumer
-
getSseHandshakeResult
Gets the data provided when the handshake was accepted by theSseEventSource-annotated Resource Method.- Returns:
- the data provided when the handshake was accepted
-
toString
-
getHttpRequestResult
The initial result of the handshake, as written back to the client (note that the connection remains open).Useful for examining headers/cookies written via
HttpRequestResult.getMarshaledResponse().- Returns:
- the result of this request
-