*
Metamerge logo
Search

Advanced Search
*
*
*
* HOME DOCUMENTS & RESOURCES DOWNLOADS EARLY TECH ACCESS SUPPORT FAQ KNOWN ISSUES OLD VERSIONS
*

HTTP EventHandler

Overview

The HTTP EventHandler listens for incoming HTTP requests and handles each request by parsing the HTTP headers and data into an entry object which is then passed on to the EventHandler code. Upon return from the EventHandler code a reply is generated based on the properties in the event/conn object.

When the EventHandler is started it will start listening for incoming TCP connections on the port specified in the configuration. For each incoming request, a new instance of the EventHandler is spawned to handle the request. This thread then continues to server the client until the client closes the connection. This behavior requires that the client sends the Connection: Keep-Alive header.

Incoming requests is parsed and the event/conn object is populated with properties/attributes. The naming convention is that every HTTP header is prefixed with "http.". Thus, the "Connection" header shown above would be available as "http.Connection". A few special properties exists:

Property/Attribute Description
http.body If the client posted data in the request this property will hold the value. Note that this property will not hold a value if the content-type header is application/x-www-form-urlencoded. In this case the posted data is treated as query string parameters and entered as such.
http.qs.* Query string. Parameters from either a post or get is placed here. Each parameter name is prefixed by http.qs.
http.method The request method (get,post,head,put etc..)
http.base The base document
http.remote_user If authentication mode is turned on this will hold the username
http.remote_pass If authentication mode is turned on this will hold the password
http.user If authentication mode is turned on, this property will contain the entry found in the Auth Connector Connector.

When user code has finished processing the event, the EventHandler will generate a reply to the HTTP client based on the properties in the event/conn object.

Property/Attribute Description
http.status The HTTP response code. If not specified OK is assumed. You can either specify the complete status response on the form response-code <space> response-text, or you can use one of the following value:
  • OK  --> 200 OK
  • FORBIDDEN --> 401 Forbidden
  • NOT FOUND --> 404 File not found
http.redirect If this property has a value, the client is redirected to the URL specified by it's value.
http.content-type If not specified "text/plain" is used.
http.body This property may be null in which case a "content-lenth: 0" is generated. You can provide a value for this property either as a string or a Java InputStream/Reader object. This means you can implement a very basic web server simply by setting this property to a file object as in:
var request = conn.getProperty("http.base");
if ( request == "" ) {
	request = "index.html";
}
var file = new java.io.FileReader ( request );
event.setProperty ("http.body", file );

By doing this in your EventHandler code you will end up with a web server providing static web pages.

http.* All headers, except those above, are sent asis on the connection.
http.qs.* These headers are ignored on output.

Configuration

Parameter Value
HTTP Port The TCP port on which the handler listens
Auth Connector If specified, this Connector is used to authenticate access to the EventHandler. What happens is this: the EventHandler will check for an A header provided by the client and parse the username/password. Then it will use those values in a lookup using the Auth Connectorl. The EventHandler provides username and password attributes in the lookup operation so you must at least configure the Connector's Link criteria. If the Connector returns a single entry the EventHandler continues to process the request assuming the client is granted access.

If the client does not send the authorization header the EventHandler will return a forbidden status along with a request for basic authentication in the "metamerge-

Headers as properties If true, all http headers and data is populated as properties, otherwise the data is made available as attributes in the event/conn object.
Comment Not used by handler
Auto-Start service If true, this handler will be started when the MI server is started
Debug Mode Enables additional logging

Downloads

Included in base product since 4.5.4

See Also

HTTPServer Connector, HTTPClient Connector, HTTPParser

 
*
  Metamerge Integrator version 4.5 ©Copyright Metamerge AS 2000-2002 Last edited 2002-04-30 contact us