dbp::isapi_application Class Reference

ISAPI application class. More...

#include <isapi_application.h>

Inheritance diagram for dbp::isapi_application:
Inheritance graph
[legend]
Collaboration diagram for dbp::isapi_application:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void on_handle_request (on_request_handler handler)
 Register a custom web request handler.
virtual void on_exception (on_exception_handler handler)
 Register a custom exception handler.

Protected Member Functions

int handle_request ()
virtual http_request get_request ()
virtual void send_response (const http_response &response)

Detailed Description

ISAPI application class.

This class implements the web application as the ISAPI module (Microsoft IIS web server extension).

The IIS is a somewhat popular web server in the Windows environment. It supports extending with an own API by plugins (ISAPI modules), which are dynamic libraries by nature.

This class provides a wrapper on the isapi modules API, so you can use this class and link your program as dynamic library to create your isapi module extension:

/*
 * Classic "Hello, world!" example application (ISAPI module).
 *
 * This example shows how to write "skeleton" of the application with
 * DCL framework using dbp::isapi_application class.
 *
 * As the result, the simple ISAPI module will be produced.
 */

#include <iostream>
#include <string>

// include all classes from dclbase library
#include <dcl/dclbase.h>
#include <dcl/isapi_application.h>

// use the DCL default namespace by default
using namespace dbp;

// declare our own application class
class hello_world_app {
public:
        // the constructor of the hello_world_app class initializes the
        // console application by obtaining a link to the dbp::application class
        // via its instance() method call.
        hello_world_app() {
                // register the execute event handler
                app.on_handle_request(create_delegate(this,
                  &hello_world_app::process_request));
        }
        isapi_application& application_impl() {
                return app;
        };
private:
        // the link to the console application class
        isapi_application app;
        // execute event handler
        http_response process_request(const http_request &req) {
                // initialize the response
                http_response resp;
                // we are only support GET method in this demo
                if (req.get_method() == http_method::get) {
                        // initialize the response with greeting message
                        resp.set_content_type("text/plain");
                        resp.set_content("Hello, world!");
                } else {
                        // send the response with "405 Method Not Allowed" status code
                        resp.set_status(http_error::method_not_allowed);
                        resp.set_allow(http_method::get);
                }
                // send the response to the client
                return resp;
        };
};

// initialize and run the application via provided macros
IMPLEMENT_APP("Hello World ISAPI module", hello_world_app);

See the 'examples/hello_world/isapi_module' directory for the full ISAPI module skeleton application based on isapi_application class.


Member Function Documentation

virtual void dbp::isapi_application::on_exception ( on_exception_handler  handler  )  [inline, virtual]

Register a custom exception handler.

By default, the web application returns the '500 Internal Server Error' HTTP error code on exceptions occured, but you can customize the default exceptions handling by registering your handler.

Parameters:
handler the exception handler delegate.

Implements dbp::web_application_int.

virtual void dbp::isapi_application::on_handle_request ( on_request_handler  handler  )  [inline, virtual]

Register a custom web request handler.

To make your application doing something useful, you should register your web request handler.

This handler is a web application entry point. When client is passing the request, it comes to a web server, processed with it and delivers to the application. You can obtain web request fields via http_request parameter.

After processing of the request you should to deliver the appropriate response to a client via web server by returning initialized http_response object.

The 'examples/hello_world/cgi_application' directory contains the source code of the web request handler implementation example.

Parameters:
handler the request handler delegate.

Implements dbp::web_application_int.


The documentation for this class was generated from the following file:

 
Support This Project
SourceForge.net Logo