Package sunlabs.brazil.handler
Class SimpleSessionHandler
- java.lang.Object
-
- sunlabs.brazil.handler.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 thesession
id. ${...} are substituted (but not \'s) forvalue
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.
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
-
-
Field Summary
Fields Modifier and Type Field Description Regexp
regexp
java.lang.String
valueTemplate
-
Constructor Summary
Constructors Constructor Description SimpleSessionHandler()
-
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.
-
-
-
Field Detail
-
valueTemplate
public java.lang.String valueTemplate
-
regexp
public Regexp regexp
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Description copied from interface:Handler
Initializes the handler.- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
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 interfaceHandler
- Parameters:
request
- TheRequest
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 callingRequest.sendResponse()
orRequest.sendError
.- Throws:
java.io.IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
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 aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-
-