Class SimpleSessionHandler

  • All Implemented Interfaces:
    Handler

    public class SimpleSessionHandler
    extends java.lang.Object
    implements Handler
    Handler for creating browser sessions based on information found in the http request. This handler provides a single session-id that may be used by other handlers.

    The following server properties are used:

    prefix, suffix, glob, match
    Specify the URL that triggers this handler (See MatchString).
    session
    The name of the request property that the Session ID will be stored in, to be passed to downstream handlers. The default value is "SessionID". If the property already exists, and is not empty, no session will be defined (unless force=true).
    extract
    If specified, a string to use as the session-id. ${...} values will be searched for first in the HTTP header values, and then in the request properties.

    In addition to the actual HTTP headers, the pseudo http headers ipaddress, url, method, and query are made available for ${...} substitutions.

    re
    If specified, a regular expression that the extracted data must match. if it doesn't match, no session id is installed. The default is ".", which matches any non-empty string. If the first character is "!" then the sense of the match is inverted, But only for determining whether a match "succeeded" or not. no sub-matches may be used in computing the key value in this case.
    value
    The value of the session ID. May contain & or \n (n=0,1,2...) constructs to substitute matched sub-expressions of re. The default is "&" , which uses the entire string "extract" as the session id. ${...} are substituted (but not \'s) for value before looking for '\n' sequences that are part of the regular expression matches.
    digest
    If set, the "value" is replaced by the base64 encoding of the MD5 checksum of value.
    force
    If set (to anything), a session ID is set even if one already exists.
    If no options are provided, the client's IP address is used as the session ID.

    Examples:

    Pick the session based on the browser
     [prefix].extract=${user-agent}
     [prefix].re=.*(Netscape|Lynx|MSIE).*
     [prefix].value=\\1
     
    This is similar to the "old" behavior.
     [prefix].extract=${user-agent}${ipaddress}
     [prefix].digest=true
     
    Look for a special authorization token, and set a request property to the value
     [prefix].extract=${Authorization}
     [prefix].re=code:([0-9]+)
     [prefix].value=id\\1
     
    Version:
    Author:
    Stephen Uhler
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean init​(Server server, java.lang.String prefix)
      Initializes the handler.
      boolean respond​(Request request)
      Responds to an HTTP request.
      • Methods inherited from class java.lang.Object

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

      • valueTemplate

        public java.lang.String valueTemplate
      • regexp

        public Regexp regexp
    • Constructor Detail

      • SimpleSessionHandler

        public SimpleSessionHandler()
    • Method Detail

      • init

        public boolean init​(Server server,
                            java.lang.String prefix)
        Description copied from interface: Handler
        Initializes the handler.
        Specified by:
        init in interface Handler
        Parameters:
        server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
        prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
        Returns:
        true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.
      • respond

        public boolean respond​(Request request)
                        throws java.io.IOException
        Description copied from interface: Handler
        Responds to an HTTP request.
        Specified by:
        respond in interface Handler
        Parameters:
        request - The Request object that represents the HTTP request.
        Returns:
        true if the request was handled. A request was handled if a response was supplied to the client, typically by calling Request.sendResponse() or Request.sendError.
        Throws:
        java.io.IOException - if there was an I/O error while sending the response to the client. Typically, in that case, the Server will (try to) send an error message to the client and then close the client's connection.

        The IOException should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting a FileNotFoundException due to not being able to open a file). In that case, the Handler's duty is to turn that IOException into a HTTP response indicating, in this case, that a file could not be found.