Server Smalltalk Guide

SstHttpServerExample

Tip icon
This section covers SstHttpServerExample, which is a servlet-based HTTP server which runs with a pooled dispatcher. You can specify the TCP address for the server as well as its root directory. The implementation of the server demonstrates many of the communications level features of SST such as message assemblers and hybrid marshaling and tunneling.

Rather than doing a straightforward web server, SST supplies a servlet-based server architecture as described in Server infrastructure. The HTTP server creates a server and installs some servlets as shown in the code below.

at: urlString path: directoryPath
   | configuration context result |
   configuration := SstSessionManagerConfiguration new
      sessionClass: SstHttpSession;
      yourself.
   (context := SstServletContext new) setAttribute: 'path' to: directoryPath.
   (result := self using: context)
      addHandlerUrl: urlString sstAsUrl;
      sessionConfiguration: configuration.
   result servletManager
      defaultServlet: #SstHttpFileServlet;
      loadServlet: #SstHttpExampleServlet as: 'cgi'.
   ^result

First, a session management configuration is built. Then you create a servlet context used for initializing servlets as needed. The using: instantiates a new server which executes according to the supplied context. To this you add an invocation handler based on the URL provided. This is the location at which the server looks for new requests. The server's session management is also set up (see Session management for more information).

The server's servletManager allows you to set the default behavior of the server. It discusses what to do with requests which no other servlet can handle. For HTTP, that is the file servlet which interprets the requested URL as a file path. In the example you also add a CGI servlet which is registered as cgi. As a result, URLs of the form:

http://server.com:80/cgi/myCgiRequst?this=that&then=5

are mapped onto the CGI servlet. The current implemention of this servlet simply returns a summary of the variable settings it was provided.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]