Package org.astrogrid.samp.httpd
Class MultiURLMapperHandler
- java.lang.Object
-
- org.astrogrid.samp.httpd.MultiURLMapperHandler
-
- All Implemented Interfaces:
HttpServer.Handler
public class MultiURLMapperHandler extends java.lang.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
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
basePath_
private java.net.URL
baseUrl_
private int
resourceCount_
private HttpServer
server_
private java.util.Map
urlMap_
-
Constructor Summary
Constructors Constructor Description MultiURLMapperHandler(HttpServer server, java.lang.String basePath)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.URL
addLocalUrl(java.net.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.java.net.URL
getBaseUrl()
Returns the base URL for resources served by this handler.void
removeServerUrl(java.net.URL url)
Removes access to a resource which was publicised by a previous call toaddLocalUrl(java.net.URL)
.HttpServer.Response
serveRequest(HttpServer.Request request)
Provides a response to an HTTP request.
-
-
-
Field Detail
-
server_
private final HttpServer server_
-
basePath_
private final java.lang.String basePath_
-
baseUrl_
private final java.net.URL baseUrl_
-
urlMap_
private final java.util.Map urlMap_
-
resourceCount_
private int resourceCount_
-
-
Constructor Detail
-
MultiURLMapperHandler
public MultiURLMapperHandler(HttpServer server, java.lang.String basePath) throws java.net.MalformedURLException
Constructor.- Parameters:
server
- server within which this handler will be usedbasePath
- path of served resources relative to the base URL of the server itself- Throws:
java.net.MalformedURLException
-
-
Method Detail
-
getBaseUrl
public java.net.URL getBaseUrl()
Returns the base URL for resources served by this handler.- Returns:
- base URL for output
-
addLocalUrl
public java.net.URL addLocalUrl(java.net.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(java.net.URL url)
Removes access to a resource which was publicised by a previous call toaddLocalUrl(java.net.URL)
.- Parameters:
url
- result of previous call toaddLocalUrl
-
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
-
-