Class ResponseBuilder

java.lang.Object
org.simpleframework.http.socket.service.ResponseBuilder

class ResponseBuilder extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private final Channel
    This is the underlying TCP channel for the request.
    private final Response
    This is the response to the WebSocket handshake.
    private final AcceptToken
    This is the accept token generated for the request.
    private final Trace
    This is used to trace the activity for the handshake.
    private final RequestValidator
    This is used to validate the initiating WebSocket request.
    private final ByteWriter
    This is the sender used to send the WebSocket response.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ResponseBuilder(Request request, Response response)
    Constructor for the ResponseBuilder object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    This is used to respond to the client with a HTTP 101 response to indicate that the WebSocket handshake succeeeded.
    void
    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 void
    This is used to respond to the client with a HTTP 400 response indicating the WebSocket handshake failed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • validator

      private final RequestValidator validator
      This is used to validate the initiating WebSocket request.
    • token

      private final AcceptToken token
      This is the accept token generated for the request.
    • writer

      private final ByteWriter writer
      This is the sender used to send the WebSocket response.
    • response

      private final Response response
      This is the response to the WebSocket handshake.
    • channel

      private final Channel channel
      This is the underlying TCP channel for the request.
    • trace

      private final Trace trace
      This is used to trace the activity for the handshake.
  • Constructor Details

    • ResponseBuilder

      public ResponseBuilder(Request request, Response response) throws Exception
      Constructor for the ResponseBuilder object. 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 handshake
      response - this is the response for the handshake
      Throws:
      Exception
  • Method Details

    • commit

      public void commit() throws IOException
      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

      private void reject() throws IOException
      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

      private void accept() throws IOException
      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