Package org.astrogrid.samp.httpd
Class ResourceHandler
- java.lang.Object
-
- org.astrogrid.samp.httpd.ResourceHandler
-
- All Implemented Interfaces:
HttpServer.Handler
public class ResourceHandler extends java.lang.Object implements HttpServer.Handler
Handler implementation which implements dynamic resource provision. HTTP HEAD and GET methods are implemented.- Since:
- 7 Jan 2009
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
basePath_
private static ServerResource
EXPIRED
Dummy resource indicating a withdrawn item.private int
iRes_
private static java.util.logging.Logger
logger_
private java.util.Map
resourceMap_
private java.net.URL
serverUrl_
-
Constructor Summary
Constructors Constructor Description ResourceHandler(HttpServer server, java.lang.String basePath)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.URL
addResource(java.lang.String name, ServerResource resource)
Adds a resource to this server.void
removeResource(java.net.URL url)
Removes a resource from this server.HttpServer.Response
serveRequest(HttpServer.Request request)
Provides a response to an HTTP request.
-
-
-
Field Detail
-
basePath_
private final java.lang.String basePath_
-
serverUrl_
private final java.net.URL serverUrl_
-
resourceMap_
private final java.util.Map resourceMap_
-
iRes_
private int iRes_
-
logger_
private static java.util.logging.Logger logger_
-
EXPIRED
private static final ServerResource EXPIRED
Dummy resource indicating a withdrawn item.
-
-
Constructor Detail
-
ResourceHandler
public ResourceHandler(HttpServer server, java.lang.String basePath)
Constructor.- Parameters:
server
- HTTP serverbasePath
- path from server root beneath which all resources provided by this handler will appear
-
-
Method Detail
-
addResource
public java.net.URL addResource(java.lang.String name, ServerResource resource)
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
public void removeResource(java.net.URL url)
Removes a resource from this server.- Parameters:
url
- URL returned by a previous addResource call
-
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 interfaceHttpServer.Handler
- Parameters:
request
- HTTP request- Returns:
- response response to request, or null
-
-