Class VirtualHostHandler
java.lang.Object
sunlabs.brazil.handler.VirtualHostHandler
- All Implemented Interfaces:
Handler
Handler for managing virtual hosts using the same server configuration.
This prefixes the host name (from the http "host" header, with the
port portion removed) onto the
url and passes the request along.
If no host is provided, the host "default" is used instead.
If hosts require their own server configurations, use the
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.htmlwill 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.htmlwill 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:HandlerInitializes the handler.- Specified by:
initin interfaceHandler- Parameters:
server- The HTTP server that created thisHandler. TypicalHandlers will useServer.propsto obtain run-time configuration information.prefix- The handlers name. The string thisHandlermay prepend to all of the keys that it uses to extract configuration information fromServer.props. This is set (by theServerandChainHandler) to help avoid configuration parameter namespace collisions.- Returns:
trueif thisHandlerinitialized successfully,falseotherwise. Iffalseis returned, thisHandlershould not be used.
-
respond
Either look for host header, tack on front of url, or modify the "root" property- Specified by:
respondin interfaceHandler- Parameters:
request- TheRequestobject that represents the HTTP request.- Returns:
trueif 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, theServerwill (try to) send an error message to the client and then close the client's connection.The
IOExceptionshould not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundExceptiondue to not being able to open a file). In that case, theHandler's duty is to turn thatIOExceptioninto a HTTP response indicating, in this case, that a file could not be found.
-