Servlet Objects

To make the most of the HTTP servlet framework it will be necessary to create your own servlets for interacting with your application. Servlets can be written to handle basic requests against a resource, or requests where form data is supplied. Special purpose servlets which process arbitrary content as- sociated with a request may also be created. Having created a servlet, it can be integrated into an ap- plication by defining a custom HTTP server object, or by storing it as a file and using a plugin, in association with the file server object.

As the HTTP servlet framework is implemented on top of an event system and doesn’t rely upon threads, it is necessary to be mindful of how servlets are implemented to avoid a situation where the code blocks. If the code does block it will effectively stop the whole application. The event system should therefore be used as appropriate where concurrency is required. If communication with service objects in a remote process is required to obtain data to satisfy a request, this will be essential.

Processing a Request

In order to implement your own HTTP servlet, you need to create a new class which derives from the HttpServlet class. If the request your HTTP servlet is to handle does not have any content associ- ated with it, you will only need to override the "processRequest()" member function.

The "processRequest()" member function will be called immediately after the HTTP server ob- ject has returned a valid HTTP servlet. If the HTTP servlet doesn’t need to process any content asso- ciated with a request, it will typically be able to generate a response straight away and the servlet can then be destroyed.

class HttpServlet(netsvc.HttpServlet): def processRequest(self):

95

Page 95
Image 95
Python 7.0pl5, Python Manual manual Servlet Objects, Processing a Request