Class ResponseBuilder


  • class ResponseBuilder
    extends java.lang.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 Channel channel
      This is the underlying TCP channel for the request.
      private Response response
      This is the response to the WebSocket handshake.
      private AcceptToken token
      This is the accept token generated for the request.
      private Trace trace
      This is used to trace the activity for the handshake.
      private RequestValidator validator
      This is used to validate the initiating WebSocket request.
      private ByteWriter writer
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void accept()
      This is used to respond to the client with a HTTP 101 response to indicate that the WebSocket handshake succeeeded.
      void 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.
      private void reject()
      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 Detail

      • 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 Detail

      • ResponseBuilder

        public ResponseBuilder​(Request request,
                               Response response)
                        throws java.lang.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:
        java.lang.Exception
    • Method Detail

      • commit

        public void commit()
                    throws java.io.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:
        java.io.IOException
      • reject

        private void reject()
                     throws java.io.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:
        java.io.IOException
      • accept

        private void accept()
                     throws java.io.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:
        java.io.IOException