Package org.astrogrid.samp.httpd
Class URLMapperHandler
java.lang.Object
org.astrogrid.samp.httpd.URLMapperHandler
- All Implemented Interfaces:
HttpServer.Handler
Handler implementation which allows the server to serve resources which
are available to it as URLs. The main use for this is if the URLs
are jar:-type ones which are available to the JVM in which the server
is running, but not to it's clients.
Either a single resource or a whole tree may be served.
- Since:
- 8 Jan 2009
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionURLMapperHandler
(HttpServer server, String basePath, URL sourceUrl, boolean includeRelatives) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the base URL for this handler.static HttpServer.Response
mapUrlResponse
(String method, URL targetUrl) Repackages a resource from a given target URL as an HTTP response.serveRequest
(HttpServer.Request request) Provides a response to an HTTP request.
-
Constructor Details
-
URLMapperHandler
public URLMapperHandler(HttpServer server, String basePath, URL sourceUrl, boolean includeRelatives) throws MalformedURLException Constructor.- Parameters:
server
- server within which this handler will be usedbasePath
- path of served resources relative to the base path of the server itselfsourceUrl
- URL of the resource which is to be made available at the basePath by this handlerincludeRelatives
- if true, relative URLs based atbasePath
may be requested (potentially giving access to for instance the entire tree of classpath resources); if false, only the exact resource named bysourceUrl
is served- Throws:
MalformedURLException
-
-
Method Details
-
getBaseUrl
Returns the base URL for this handler. If not including relatives, this will be the only URL served.- Returns:
- URL
-
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
-
mapUrlResponse
Repackages a resource from a given target URL as an HTTP response. The data and relevant headers are copied straight through. GET and HEAD methods are served.- Parameters:
method
- HTTP methodtargetUrl
- URL containing the resource to forward- Returns:
- response redirecting to the given target URL
-