Class SslPollHandler

  extended by java.lang.Thread
      extended by sunlabs.brazil.ssl.SslPollHandler (view source)
All Implemented Interfaces:
Runnable, Handler

public class SslPollHandler
extends Thread
implements Handler

Handler for periodically polling another web site, whose results are (optionally) added to the server's properties. This also includes the ability to request URL's on a cron-like schedule.

This version uses the built-in HTTP. It requires Java 1.4 or newer, doesn't cache connections, and doesn't support per connection proxies. However, it does support SSL. See also PollHandler. These should be combined by adding additional protocol support to HttpRequest.

The built-in HTTP stack now supports SSL (see sunlabs.brazil.util.http.HttpsRequest), so this class is deprecated.
The result of fetching the url is expected to be a text document in java Properties format.


URL to fetch periodically. any ${...} constructs are evaluated at each poll, with the values in the server properties object. If the URL starts with "/", then the current server is used.
The "post" data, if any. ${...} are evaluates as per url above.
A list of white space delimited tokens that refer to additional HTTP headers that are added onto the polled request. For each token the server properties [token].name and [token].value define a new http header.
The interval (in seconds) to fetch the url. Defaults to 10 seconds. If match is specified, this is the interval used to check for a time/date match. At each "interval", the current time format is computed, based on "format", below. If the computed format has not changed since the previous poll, then no poll is done. The interval is recalculated after each poll.
If set, don't wait "interval" before 1st poll.
The string to prepend to the properties. If not supplied no properties are loaded.
The namespace to use to store the properties to. If the sessionTable (see below)parameter is identical to the sessionTable parameter of the SetTemplate, then this specifies the namespace parameter that may be used with the SetTemplate "namespace" parameter to obtain the extracted data. Defaults to the "prepend" parameter.
If specified, a regular expression that must match the current time for this URL to run. The format to match is specified by the "format" parameter, below. "EEE-dd-HH-mm" (eg: Thu-Dec, 14, 14:12 pm).
a date format specifier to use for matching "match" patterns. Defaults to "EE-MM-dd-HH-mm".
The name of the SessionManager table to use for storing values. By default, properties are stored in server.props. The value should match the sessionTable used by the SetTemplate to allow values obtained by this handler to be accessable from within templates.

If the sessionTable is set, the namespace value is used to name the table (e.g. the namespace specified by SetTemplate. If no namespace parameter is given, then prepend is used as the namespace parameter.

If prepend is specified, the following additional properties are created, and added to the properties with the specified prefix.

The total number of polls attemped.
The total number of poll failures.
The poll attempt # for the last failure.
The message describing the last failure.
The timestamp of the last failure.
The timestamp for the last successful poll.

Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
Field Summary
 int interval
 String post
 String url
Fields inherited from class java.lang.Thread
Constructor Summary
Method Summary
 void fillProps(Properties props, HttpURLConnection target)
          Fill the properties from the Url Connection
 boolean init(Server server, String prefix)
          Set up the initial configuration, and kick off a thread to periodically fetch the url.
 boolean respond(Request request)
          This might allow control over the polling via requests at a later date.
 void run()
          Periodically poll the url, and copy the results into the server properties.
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


public String url


public String post


public int interval
Constructor Detail


public SslPollHandler()
Method Detail


public boolean init(Server server,
                    String prefix)
Set up the initial configuration, and kick off a thread to periodically fetch the url.

Specified by:
init in interface Handler
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.
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.


public boolean respond(Request request)
This might allow control over the polling via requests at a later date. For now, it always returns false.

Specified by:
respond in interface Handler
request - The Request object that represents the HTTP request.
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.


public void run()
Periodically poll the url, and copy the results into the server properties.

Specified by:
run in interface Runnable
run in class Thread


public void fillProps(Properties props,
                      HttpURLConnection target)
               throws IOException
Fill the properties from the Url Connection


Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.