Class AcceptToken

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

class AcceptToken extends Object
The AcceptToken is used to create a unique token based on a random key sent by the client. This is used to prove that the handshake was received, the server has to take two pieces of information and combine them to form a response. The first piece of information comes from the Sec-WebSocket-Key header field in the client handshake, the second is the globally unique identifier 258EAFA5-E914-47DA-95CA-C5AB0DC85B11. Both are concatenated and an SHA-1 has is generated and used in the session initiating response.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
    This is the character encoding to decode the key with.
    private final MessageDigest
    This is used to generate the SHA-1 has from the user key.
    private static final byte[]
    This is the globally unique identifier used in the handshake.
    private final Request
    This is the original request used to initiate the session.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the AcceptToken object.
    AcceptToken(Request request, String algorithm)
    Constructor for the AcceptToken object.
    AcceptToken(Request request, String algorithm, String charset)
    Constructor for the AcceptToken object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This is used to create the required accept token for the session initiating response.

    Methods inherited from class java.lang.Object

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

    • MAGIC

      private static final byte[] MAGIC
      This is the globally unique identifier used in the handshake.
    • digest

      private final MessageDigest digest
      This is used to generate the SHA-1 has from the user key.
    • request

      private final Request request
      This is the original request used to initiate the session.
    • charset

      private final String charset
      This is the character encoding to decode the key with.
  • Constructor Details

    • AcceptToken

      public AcceptToken(Request request) throws Exception
      Constructor for the AcceptToken object. This is to create an object that can generate a token from the client key available from the Sec-WebSocket-Key header.
      Parameters:
      request - this is the session initiating request
      Throws:
      Exception
    • AcceptToken

      public AcceptToken(Request request, String algorithm) throws Exception
      Constructor for the AcceptToken object. This is to create an object that can generate a token from the client key available from the Sec-WebSocket-Key header.
      Parameters:
      request - this is the session initiating request
      algorithm - the algorithm used to create the token
      Throws:
      Exception
    • AcceptToken

      public AcceptToken(Request request, String algorithm, String charset) throws Exception
      Constructor for the AcceptToken object. This is to create an object that can generate a token from the client key available from the Sec-WebSocket-Key header.
      Parameters:
      request - this is the session initiating request
      algorithm - the algorithm used to create the token
      charset - the encoding used to decode the client key
      Throws:
      Exception
  • Method Details

    • create

      public String create() throws IOException
      This is used to create the required accept token for the session initiating response. The resulting token is a SHA-1 digest of the Sec-WebSocket-Key a globally unique identifier defined in RFC 6455 all encoded in base64.
      Returns:
      the accept token for the session initiating response
      Throws:
      IOException