Package org.astrogrid.samp.httpd
Class DirectoryMapperHandler
java.lang.Object
org.astrogrid.samp.httpd.DirectoryMapperHandler
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDirectoryMapperHandler
(String localDocBase, String serverDocPath) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionserveRequest
(HttpServer.Request request) Provides a response to an HTTP request.
-
Constructor Details
-
DirectoryMapperHandler
Constructor.- Parameters:
localDocBase
- prefix for resources available within the JVMserverDocPath
- prefix for resources made available by this server
-
-
Method Details
-
serveRequest
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 interfaceHttpServer.Handler
- Parameters:
request
- HTTP request- Returns:
- response response to request, or null
-