Class DirectoryMapperHandler

java.lang.Object
org.astrogrid.samp.httpd.DirectoryMapperHandler
All Implemented Interfaces:
HttpServer.Handler

public class DirectoryMapperHandler extends Object implements HttpServer.Handler
Handler implementation which allows the server to serve a directory full of resources. The URLMapperHandler class can sort of do the same thing, but it's difficult to get the path right.

For if an instance is initialised as new DirectoryMapperHandler("/files", "/data") and installed on a server running at http://localhost:8000/, then a server request for http://localhost:8000/data/xxx would be fulfilled by returning the content of the resource /files/xxx available to the JVM's classloader (for instance within a jar file on the classpath).

Since:
11 Mar 2016
Author:
Mark Taylor
  • Constructor Details

    • DirectoryMapperHandler

      public DirectoryMapperHandler(String localDocBase, String serverDocPath)
      Constructor.
      Parameters:
      localDocBase - prefix for resources available within the JVM
      serverDocPath - prefix for resources made available by this server
  • Method Details

    • serveRequest

      public HttpServer.Response serveRequest(HttpServer.Request request)
      Description copied from interface: HttpServer.Handler
      Provides a response to an HTTP request. A handler which does not recognise the URL should simply return null; in this case there may be another handler which is able to serve the request. If the URL appears to be in this handler's domain but the request cannot be served for some reason, an error response should be returned.
      Specified by:
      serveRequest in interface HttpServer.Handler
      Parameters:
      request - HTTP request
      Returns:
      response response to request, or null