Package org.astrogrid.samp.httpd
Class ResourceHandler
java.lang.Object
org.astrogrid.samp.httpd.ResourceHandler
- All Implemented Interfaces:
HttpServer.Handler
Handler implementation which implements dynamic resource provision.
HTTP HEAD and GET methods are implemented.
- Since:
- 7 Jan 2009
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddResource
(String name, ServerResource resource) Adds a resource to this server.void
removeResource
(URL url) Removes a resource from this server.serveRequest
(HttpServer.Request request) Provides a response to an HTTP request.
-
Constructor Details
-
ResourceHandler
Constructor.- Parameters:
server
- HTTP serverbasePath
- path from server root beneath which all resources provided by this handler will appear
-
-
Method Details
-
addResource
Adds a resource to this server.- Parameters:
name
- resource name, for cosmetic purposes onlyresource
- resource to make available- Returns:
- URL at which resource can be found
-
removeResource
Removes a resource from this server.- Parameters:
url
- URL returned by a previous addResource call
-
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
-