Class VirtualHostHandler
- All Implemented Interfaces:
Handler
If hosts require their own server configurations, use the
MultiHostHandler
instead.
Configuration parameters:
- maproot
- If set upon server startup, this handler changes the "root" property instead of the "url" property, by appending the "host" onto the document root, instead of prepending the "host" to the url.
- [prefix].[host].
- If the "mapping" property exists that matches the incoming "host" name, then that value is used instead of [host] to rewrite the "url" or "root".
- default
- If set, then all hosts for which no mappings are defined are mapped to the value of this property.
- levels
- If defined, then for the purpose of host matching, only "levels" of hostnames are considered. If levels=3, then for host: a.b.c.d.e, the host is considered to be "c.d.e". This enables support for wildcard-host matching within a virtual domain.
- addlevel=true|false
- If "true", "levels" is specified, and the number of tokens (levels)
in the hostname exceeds "levels", then all the extra tokens in the
hostname are prepended to the URL as initial directories: If
"levels" is 3, and "addlevel=true" then:
host
http://a.b.c.d.e/foo.html
will be mapped tohttp://c.d.e/b/a/foo.html
, and the file "foo.html" should be at [docroot]/c.d.e/b/a/foo.html].If "addlevel=false", then
http://a.b.c.d.e/foo.html
will be mapped tohttp://c.d.e/foo.html
, and the file "foo.html" should be at [docroot]/c.d.e/foo.html. In this case, the "a.b" part of the host is available as part of the host property, which retains its original value.
- Version:
- 2.1, 02/10/01
- Author:
- Stephen Uhler
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
VirtualHostHandler
public VirtualHostHandler()
-
-
Method Details
-
init
Description copied from interface:Handler
Initializes the handler.- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
Either look for host header, tack on front of url, or modify the "root" property- Specified by:
respond
in interfaceHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
true
if the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()
orRequest.sendError
.- Throws:
IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
will (try to) send an error message to the client and then close the client's connection.The
IOException
should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-