Class SocketWrapper

  • All Implemented Interfaces:
    Socket

    public class SocketWrapper
    extends java.lang.Object
    implements Socket
    This is a SocketWrapper objects that represents a TCP socket connections. This contains a map that allows attributes to be associated with the client connection. Attributes such as security certificates or other transport related details can be exposed to the Request using the socket attribute map.

    This provides the connected SocketChannel that can be used to receive and response to HTTP requests. The socket channel must be selectable and in non-blocking mode. If the socket is not in a non-blocking state the connection will not be processed.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.channels.SocketChannel channel
      This is the socket that provides the input and output.
      private javax.net.ssl.SSLEngine engine
      This is used to encrypt content for secure connections.
      private java.util.Map map
      This is used to store the attributes for the socket.
      private Trace trace
      This can be used to trace specific events for the socket.
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketWrapper​(java.nio.channels.SocketChannel channel, Trace trace)
      This creates a SocketWrapper from a socket channel.
      SocketWrapper​(java.nio.channels.SocketChannel channel, Trace trace, javax.net.ssl.SSLEngine engine)
      This creates a SecureSocket from a socket channel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map getAttributes()
      This method is used to get the Map of attributes by this socket.
      java.nio.channels.SocketChannel getChannel()
      This method is used to acquire the SocketChannel for the connection.
      javax.net.ssl.SSLEngine getEngine()
      This is used to acquire the SSL engine used for HTTPS.
      Trace getTrace()
      This is used to acquire the trace object that is associated with the socket.
      • Methods inherited from class java.lang.Object

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

      • channel

        private final java.nio.channels.SocketChannel channel
        This is the socket that provides the input and output.
      • engine

        private final javax.net.ssl.SSLEngine engine
        This is used to encrypt content for secure connections.
      • trace

        private final Trace trace
        This can be used to trace specific events for the socket.
      • map

        private final java.util.Map map
        This is used to store the attributes for the socket.
    • Constructor Detail

      • SocketWrapper

        public SocketWrapper​(java.nio.channels.SocketChannel channel,
                             Trace trace)
        This creates a SocketWrapper from a socket channel. Any implementations of the object may use this constructor to ensure that all the data is initialized.
        Parameters:
        channel - the socket channel that is used as the transport
        trace - used to trace specific events for the socket
      • SocketWrapper

        public SocketWrapper​(java.nio.channels.SocketChannel channel,
                             Trace trace,
                             javax.net.ssl.SSLEngine engine)
        This creates a SecureSocket from a socket channel. Any implementations of the object may use this constructor to ensure that all the data is initialized.
        Parameters:
        channel - the socket channel that is used as the transport
        trace - used to trace specific events for the socket
        engine - this is the SSL engine used for secure transport
    • Method Detail

      • getTrace

        public Trace getTrace()
        This is used to acquire the trace object that is associated with the socket. A trace object is used to collection details on what operations are being performed on the socket. For instance it may contain information relating to I/O events or more application specific events such as errors.
        Specified by:
        getTrace in interface Socket
        Returns:
        this returns the trace associated with this socket
      • getEngine

        public javax.net.ssl.SSLEngine getEngine()
        This is used to acquire the SSL engine used for HTTPS. If the socket is connected to an SSL transport this returns an SSL engine which can be used to establish the secure connection and send and receive content over that connection. If this is null then the socket represents a normal transport.
        Specified by:
        getEngine in interface Socket
        Returns:
        the SSL engine used to establish a secure transport
      • getChannel

        public java.nio.channels.SocketChannel getChannel()
        This method is used to acquire the SocketChannel for the connection. This allows the server to acquire the input and output streams with which to communicate. It can also be used to configure the connection and perform various network operations that could otherwise not be performed.
        Specified by:
        getChannel in interface Socket
        Returns:
        this returns the socket used by this HTTP socket
      • getAttributes

        public java.util.Map getAttributes()
        This method is used to get the Map of attributes by this socket. The attributes map is used to maintain details about the connection. Information such as security credentials to client details can be placed within the attribute map.
        Specified by:
        getAttributes in interface Socket
        Returns:
        this returns the map of attributes for this socket