|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsunlabs.brazil.handler.MultiHostHandler (view source)
public class MultiHostHandler
The MultiHostHandler
allows the user to handle a set
of host names that are all running on the same IP address. This
handler looks at the http "Host" header and redispatches the request to the
appropriate sub-server.
Only the main server is actually listening to the port on the specified IP address. The sub-servers are not running in separate threads. Indeed, they are not "running" at all. They exist merely as a convenient bag to hold each of the server-specific configuration parameters.
The respond
method of the main handler for the appropriate
sub-server is called directly from the respond
method of
this handler.
This handler uses the following configuration parameters:
server.props
with the
specified prefix. In this way, the configuration parameters for
all the sub-servers can be stored in the same Properties
object.
FileHandler
.
The property "root", if included in the "config" file, is treated specially: If it does not represent an absolute path, then it is resolved relative to the main server's root.
handler=host port=8081 log=5 host.class=sunlabs.brazil.server.MultiHostHandler host.servers=mars jupiter saturn mars.host=www.mars.com mars.log=2 mars.handler=mars.file mars.file.class=sunlabs.brazil.server.FileHandler mars.file.root=public_html/mars jupiter.host=jupiter.planet.org jupiter.handler=sunlabs.brazil.server.FileHandler jupiter.root=public_html/jupiter saturn.host=*.saturn.planet.org saturn.handler=sunlabs.brazil.server.FileHandler saturn.root=public_html/saturnThese parameters set up a normal
Server
on port 8081,
running a MultiHostHandler
. The MultiHostHandler
will create three additional servers that respond to the virtual hosts
"www.mars.com", "jupiter.planet.org", and "Server.prefix
of "mars",
so that all other configuration parameters that the "mars" server
examines can begin with "mars" and be kept distinct from the "jupiter"
and "saturn" parameters.
The main server and the three sub-servers will all share the same properties object, but can use their own individual prefixes to keep their data separate (because "inherit" is not set).
Constructor Summary | |
---|---|
MultiHostHandler()
|
Method Summary | |
---|---|
boolean |
init(Server server,
String prefix)
Initializes the servers for the virtual hosts. |
boolean |
respond(Request request)
Responds to an HTTP request by examining the "Host:" request header and dispatching to the main handler of the server that handles that virtual host. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MultiHostHandler()
Method Detail |
---|
public boolean init(Server server, String prefix)
init
method of the
main handler for each sub-server is called.
init
in interface Handler
server
- The HTTP server that created this handler.prefix
- A prefix to prepend to all of the keys that this
handler uses to extract configuration information.
true
if at least one sub-server was found and
could be initialized, false
otherwise.
Diagnostic messages are logged for each sub-server started.public boolean respond(Request request) throws IOException
init
from the list of virtual hosts, this method returns without
handling the request. Port numbers are not used for host matching.
respond
in interface Handler
request
- The HTTP request to be forwarded to one of the sub-servers.
true
if the sub-server handled the message,
false
if it did not. false
is
also returned if the "Host:" was unspecified or unknown.
IOException
- if there was an I/O error while sending the response to
the client. Typically, in that case, the Server
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 a
FileNotFoundException
due to not being able
to open a file). In that case, the Handler
's
duty is to turn that IOException
into a
HTTP response indicating, in this case, that a file could
not be found.
|
Version Kenai-svn-r24, Generated 08/18/09 Copyright (c) 2001-2009, Sun Microsystems. |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |