Class ResponseBuilder
java.lang.Object
org.simpleframework.http.socket.service.ResponseBuilder
The
ResponseBuilder object is used to build a response
to a WebSocket handshake. In order for a successful handshake to
complete a HTTP request must have a version of 13 referring
to RFC 6455, a WebSocket key, and the required HTTP connection
details. If any of these are missing the server is obliged to
respond with a HTTP 400 response indicating a bad request.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelThis is the underlying TCP channel for the request.private final ResponseThis is the response to the WebSocket handshake.private final AcceptTokenThis is the accept token generated for the request.private final TraceThis is used to trace the activity for the handshake.private final RequestValidatorThis is used to validate the initiating WebSocket request.private final ByteWriterThis is the sender used to send the WebSocket response. -
Constructor Summary
ConstructorsConstructorDescriptionResponseBuilder(Request request, Response response) Constructor for theResponseBuilderobject. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaccept()This is used to respond to the client with a HTTP 101 response to indicate that the WebSocket handshake succeeeded.voidcommit()This is used to determine if the client handshake request had all the required headers as dictated by RFC 6455 section 4.2.1.private voidreject()This is used to respond to the client with a HTTP 400 response indicating the WebSocket handshake failed.
-
Field Details
-
validator
This is used to validate the initiating WebSocket request. -
token
This is the accept token generated for the request. -
writer
This is the sender used to send the WebSocket response. -
response
This is the response to the WebSocket handshake. -
channel
This is the underlying TCP channel for the request. -
trace
This is used to trace the activity for the handshake.
-
-
Constructor Details
-
ResponseBuilder
Constructor for theResponseBuilderobject. In order to process the WebSocket handshake this requires the original request and the response as well as the underlying TCP channel which forms the basis of the WebSocket connection.- Parameters:
request- this is the request that initiated the handshakeresponse- this is the response for the handshake- Throws:
Exception
-
-
Method Details
-
commit
This is used to determine if the client handshake request had all the required headers as dictated by RFC 6455 section 4.2.1. If the request does not contain any of these parts then this will return false, indicating a HTTP 400 response is sent to the client, otherwise a HTTP 101 response is sent.- Throws:
IOException
-
reject
This is used to respond to the client with a HTTP 400 response indicating the WebSocket handshake failed. No response body is sent with the rejection message and the underlying TCP channel is closed to prevent further use of the connection.- Throws:
IOException
-
accept
This is used to respond to the client with a HTTP 101 response to indicate that the WebSocket handshake succeeeded. Once this response has been sent all traffic between the client and server will be with WebSocket frames as defined by RFC 6455.- Throws:
IOException
-