Creating AppWeb URL HandlersMbedthis AppWeb supports extension handlers that can process any kind of HTTP content. The core AppWeb HTTP server cannot serve any pages or documents by itself. It relies on URL handlers delivered as modules to actually serve HTTP requests. AppWeb is itself comprised of 7 different handlers which serve all the content provided by an AppWeb server. This document describes the AppWeb URL Handler Interface and how to create AppWeb handlers. Handlers are usually delivered as stand-alone loadable modules. In this manner, users can decide for themselves if the functionality provided by the handler is needed or not. But the AppWeb Module interface is only a delivery option. Handlers can be statically linked and do not rely on the module mechanism to operate. OverviewTo create an AppWeb handler, you need to create an instance of a subclass of the MaHandlerService class and insert the instance into the Http service. This MaHandlerService class is the factory to create instances of your actual handler in response to incoming HTTP client requests. When a new HTTP request arrives, the newHandler method is called for the factory class to create a new MaHandler instance to process the request.If the handler is being packages as an AppWeb Module, it is often most convenient to create a new instance of the MaHandlerService class in the Module constructor. HandlerServiceThe class definition for an AppWeb Handler is described below. Note the start and stop methods are optional.class MyHandlerService : public MaHandlerService { The follow code demonstrates an AppWeb Module constructor that creates the handler service and inserts it into the applications Http service. Note that while AppWeb Handler services are global to the application, you can specify on a per server or virtual host basis whether the handler is active or not vi AppWeb configuration file directives. MyHandlerModule::MyHandlerModule(void *handle) : MaModule("MyHandler", handle) Handler ClassOnce the MaHandlerService instance is created it will be instances of the MaHandler class that will run actually service the HTTP client requests. The following is the class definition for our MyHandler class. class MyHandler : public MaHandler { The MaHandler class can optionally provide several methods which are run a various stages of the HTTP request processing. The matchRequest method is run to determine if the handler should be called to examine or process the request. If the handler matchRequest method returns TRUE, the run method will be called later to process the request. After matching the request, the setup method is called to allow the handler to do any required initialization. For maximum speed, the cloneHandler method is provided to allow the quick creating of new handler instances of the same configuration as the curren thandler instance. The postData method is called (may be prior to the run method), to process any incoming POST data. It is up to the handler to decide what to do with the data. The run method is called to actually process the request. If the handler is a terminal handler, then it is responsible for returning the resulting data back to the client's browser. If the handler is a non-terminal handler, then it must either abort the request by calling rq->requestError or it should zero to allow other handlers to process the request. Creating HandlersA handler specifies whether it is terminal or non-terminal when it is constructed. The constructor for MaHandler takes an options flag that can take the following values:
|