Package org.astrogrid.samp.httpd

# Class ResourceHandler

java.lang.Object
org.astrogrid.samp.httpd.ResourceHandler

All Implemented Interfaces:
  `HttpServer.Handler`

public class ResourceHandler extends 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

## Constructor Summary

Constructors
Constructor
Description
`ResourceHandler(HttpServer server, String basePath)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`URL`
`addResource(String name, ServerResource resource)`
Adds a resource to this server.
`void`
`removeResource(URL url)`
Removes a resource from this server.
`HttpServer.Response`
`serveRequest(HttpServer.Request request)`
Provides a response to an HTTP request.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ResourceHandler

public ResourceHandler(HttpServer server, String basePath)
Constructor.

Parameters:
  `server` - HTTP server
  `basePath` - path from server root beneath which all resources provided by this handler will appear

## Method Details

### addResource

public URL addResource(String name, ServerResource resource)
Adds a resource to this server.

Parameters:
  `name` - resource name, for cosmetic purposes only
  `resource` - resource to make available
Returns:
  URL at which resource can be found

### removeResource

public void removeResource(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 interface `HttpServer.Handler`
Parameters:
  `request` - HTTP request
Returns:
  response response to request, or null