public class URLMapperHandler extends java.lang.Object implements HttpServer.Handler
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
basePath_ |
private java.net.URL |
baseUrl_ |
private boolean |
includeRelatives_ |
private java.net.URL |
sourceUrl_ |
| Constructor and Description |
|---|
URLMapperHandler(HttpServer server,
java.lang.String basePath,
java.net.URL sourceUrl,
boolean includeRelatives)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.net.URL |
getBaseUrl()
Returns the base URL for this handler.
|
static HttpServer.Response |
mapUrlResponse(java.lang.String method,
java.net.URL targetUrl)
Repackages a resource from a given target URL as an HTTP response.
|
HttpServer.Response |
serveRequest(HttpServer.Request request)
Provides a response to an HTTP request.
|
private final java.lang.String basePath_
private final java.net.URL baseUrl_
private final java.net.URL sourceUrl_
private final boolean includeRelatives_
public URLMapperHandler(HttpServer server, java.lang.String basePath, java.net.URL sourceUrl, boolean includeRelatives) throws java.net.MalformedURLException
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 at
basePath
may be requested (potentially giving access to
for instance the entire tree of classpath resources);
if false, only the exact resource named by
sourceUrl is servedjava.net.MalformedURLExceptionpublic java.net.URL getBaseUrl()
public HttpServer.Response serveRequest(HttpServer.Request request)
HttpServer.HandlerserveRequest in interface HttpServer.Handlerrequest - HTTP requestpublic static HttpServer.Response mapUrlResponse(java.lang.String method, java.net.URL targetUrl)
method - HTTP methodtargetUrl - URL containing the resource to forward