Class ServerSentEventRequestResult.HandshakeAccepted
java.lang.Object
com.soklet.ServerSentEventRequestResult.HandshakeAccepted
- All Implemented Interfaces:
ServerSentEventRequestResult
- Enclosing interface:
ServerSentEventRequestResult
@ThreadSafe
public static final class ServerSentEventRequestResult.HandshakeAccepted
extends Object
implements ServerSentEventRequestResult
Represents the result of an SSE accepted handshake (connection stays open) when simulated by
Simulator.performServerSentEventRequest(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 getHandshakeResult(), and the final data sent to the client is available via getRequestResult().
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from interface ServerSentEventRequestResult
ServerSentEventRequestResult.HandshakeAccepted, ServerSentEventRequestResult.HandshakeRejected, ServerSentEventRequestResult.RequestFailed -
Method Summary
Modifier and TypeMethodDescriptionGets the data provided when the handshake was accepted by theServerSentEventSource-annotated Resource Method.The initial result of the handshake, as written back to the client (note that the connection remains open).voidregisterCommentConsumer(Consumer<String> commentConsumer) Registers a Server-Sent comment "consumer" for this connection - similar to how a real client would listen for Server-Sent comment payloads.voidregisterEventConsumer(Consumer<ServerSentEvent> eventConsumer) Registers aServerSentEvent"consumer" for this connection - similar to how a real client would listen for Server-Sent Events.toString()
-
Method Details
-
registerEventConsumer
Registers aServerSentEvent"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
-
getHandshakeResult
Gets the data provided when the handshake was accepted by theServerSentEventSource-annotated Resource Method.- Returns:
- the data provided when the handshake was accepted
-
toString
-
getRequestResult
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
RequestResult.getMarshaledResponse().- Returns:
- the result of this request
-