The org.bzdev.ejws package

The org.bzdev.ejws package provides a class for configuring instances of HttpServer or HttpsServer, and several classes that are useful for implementing an embedded web server:

This package also includes partial support for WAR (Web ARchive) files and JSP (Java Server Pages). For WAR files, the WEB-INF/web.xml file is processed to find encodings for pages, media-types (MIME types) for file-name extensions, error pages for particular error codes or exceptions, and a welcome-file list. The use of the web.xml file is describe in the documentation for WebMap. JSP support is really minimal and is restricted to processing error messages. This is also describe in the documentation for WebMap.

For a simple coding example based on code in the EPTS program, consider the case of a web server embedded in an application for providing on-line help. The first step is to create an embedded web server:


        EmbeddedWebServer ews = new EmbeddedWebServer(8080, 48, 2, false);
The argument 8080 is the TCP port number to use, 48 is the TCP backlog, 2 is the number of threads the server uses, and 'false' indicates that HTTP is used rather than HTTPS. The next step is to map a path to some service.

        ews.add("/", ResourceWebMap.class, "org/bzdev/epts/manual/",
                null, true, false, true);
For these arguments, "/" indicates the common portion of the URL paths for the resources being added, ResourceWebMap.class and the following argument specify a mapping class that will find classes whose paths in the application's code base start with org/bzdev.epts/manual/, null indicates that an authenticator is not used, the first true indicates that a web.xml file should not be used , false indicates that the server should not display directories, and the final true indicates that any WEB-INF directory should not be visible.

The sequence of statements


        WebMap wmap = epts.getWebMap("/");
        wmap.addWelcome("index.html");
        webmap.addMapping("html", "text/html; charset=utf-8");
looks up a web map for the context "/", configures the web map so that "index.html" is the 'welcome' page, and configures the web map so that files ending in the suffix "html" will have a media type of "text/html; charset=utf-8".

Finally


        ews.start();
will start the web server. The URL http://localhost:8080/ can be typed into a browser to view this web page on the same computer as the server.