Package org.astrogrid.samp.httpd

# Class MultiURLMapperHandler

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

All Implemented Interfaces:
  `HttpServer.Handler`

public class MultiURLMapperHandler extends Object implements HttpServer.Handler
Handler implementation which allows the server to serve multiple separate resources which are available to it, but not necessarily to external clients, as URLs. The main use for this is if the URLs are jar:-type ones (not available to clients outside the current JVM) or file:-type ones (not available to clients on different hosts). Only single resources, not whole trees, can be exported in this way.

The functionality of this class overlaps with that of `URLMapperHandler`. They may be merged at some point.

Since:
  21 Jul 2009
Author:
  Mark Taylor

## Constructor Summary

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

## Method Summary

Modifier and Type
Method
Description
`URL`
`addLocalUrl(URL localUrl)`
Adds a local URL to the list of those which can be served by this handler, and returns the public URL at which it will be available.
`URL`
`getBaseUrl()`
Returns the base URL for resources served by this handler.
`void`
`removeServerUrl(URL url)`
Removes access to a resource which was publicised by a previous call to `addLocalUrl(java.net.URL)`.
`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

### MultiURLMapperHandler

public MultiURLMapperHandler(HttpServer server, String basePath) throws MalformedURLException
Constructor.

Parameters:
  `server` - server within which this handler will be used
  `basePath` - path of served resources relative to the base URL of the server itself
Throws:
  `MalformedURLException`

## Method Details

### getBaseUrl

public URL getBaseUrl()
Returns the base URL for resources served by this handler.

Returns:
  base URL for output

### addLocalUrl

public URL addLocalUrl(URL localUrl)
Adds a local URL to the list of those which can be served by this handler, and returns the public URL at which it will be available.

Parameters:
  `localUrl` - URL readable within this JVM
Returns:
  URL readable in principle by external agents with the same content as `localUrl`

### removeServerUrl

public void removeServerUrl(URL url)
Removes access to a resource which was publicised by a previous call to `addLocalUrl(java.net.URL)`.

Parameters:
  `url` - result of previous call to `addLocalUrl`

### 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