HTTP EventHandler
Overview
The HTTP EventHandler is a simple web server that provides a simpler way to
deal with HTTP connections than the TCP EventHandler. The HTTP EventHandler will
automatically parse the client request into an event object using the HTTP Parser. In addition the EventHandler implements HTTP basic authentication if you specify an
authenticator connector.
In order to provide simple web server functionality you need to provide the http.body
and http.content-type Attributes/Properties that the EventHandler returns as the response
to a request. You can also add HTTP headers by setting any http.*
Attribute/Property. For example setting the value for http.my-header will cause
this EventHandler to generate a my-header: value in the response.
The http.body property can be set to any of the following
Type/Class |
Result |
Any string (java.lang.String) |
The string is sent as-is in the request. |
Any Input stream ( java.io.InputStream ) |
The input stream is buffered into memory to compute the content-length
HTTP header. The input stream data is sent as-is in the request. |
A Java file object (java.io.File) |
The content-length is generated by getting the
file size from the file object. Then the contents of the file is
sent as-is in the request. |
Example
The following example returns any file the client requests:
var base = event.getProperty("http.base");
if ( base == "/" )
base = "/index.html";
// Construct the full path
path = "/home/httpd/documents" + base;
// Construct the Java file object
file = new java.io.File ( path );
// Set the response property
event.setProperty ( "http.body", file );
Configuration
Parameter |
Description |
Port |
The TCP port on which this handler will be
listening |
AuthConnector |
The authenticator connector. If you specify a
connector it must exist in your connector library and be configured for
Lookup. This EventHandler will issue authentication requests to any client
(e.g. web browser) that tries to access this service. When the client
provides the username/password the EventHandler will call the auth
connector's lookup method providing the username and password
attributes. Hence, your auth connector must be configured using a Link
Criteria where you use the $username and $password. A typical link
criteria would be:
username |
equals |
$username |
password |
equals |
$password |
If the search fails the EventHandler denies the request and sends an
authentication request back to the client. If the search succeeds the
request is granted and your code in the EventHandler is executed. You
can access the username by retrieving the HTTP Attribute/Property http.remote_user.
You can access the entry returned by the authenticator connector by
retrieving the Property auth.entry, by using code like this:
var auth = event.getProperty("auth.entry");
var fullName = auth.getString("FullName");
|
AuthRealm |
The authentication realm sent to the client
when requesting authentication. This is the name you typically see in
the login dialog that the browser pops up. |
headersAsProperties |
If checked, all HTTP headers are accessible
using the getProperty method of the event object. If not, all
HTTP headers appear as Attributes (e.g. getAttribute) |
useSSL |
Check if you want to use SSL. Note that in order to use use
SSL, you have to generate your own certificate in your keystore (with
keytool). The client must then import this. See
Certificate management. |
userComment |
A comment for your own use. Not used anywhere |
See Also
Event Handler Overview,
HTTP Parser
|