Sun and Oracle Community Voices How to Buy Log In United States [Change] English

»  Spotlight Articles
»  Projects
»  Publications
»  People
»  Awards
»  Events
»  Downloads
»  Internships
»  Contrarian Minds
»  About Sun Labs
Brazil project: Class MultiHostHandler

sunlabs.brazil.server Class MultiHostHandler

java.lang.Object
  |
  +--sunlabs.brazil.server.MultiHostHandler
All Implemented Interfaces:
Handler

public class MultiHostHandler
extends Object
implements Handler

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 "Host:" 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:

servers
The list of prefixes for the other servers. Each server will be initialized from the main 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.
prefix.host
Each server is started with a given prefix. The property prefix.host specifies the virtual hostname that the server will be expected to handle. If this property is not specified, the server's virtual hostname will just be prefix.
prefix.handler
The main handler for the server with the given prefix. If this property is not specified, it defaults to the FileHandler.
prefix.log
The log level for the server with the given prefix. If this property is not specified, it defaults to the log level of the parent server.
A sample set of configuration parameters illustrating how to use this handler follows:
 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/saturn
 
These 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 "saturn.planet.org". The "mars" server will have a 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.

In fact, 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.

NOTE: This handler is in the Server package because it depends on implementation details of the Server and Request classes, not because it represents essential or "core" functionallity.


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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiHostHandler

public MultiHostHandler()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Initializes the servers for the virtual hosts. After creating and initializing each sub-server, the init method of the main handler for each sub-server is called.
Specified by:
init in interface Handler
Parameters:
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.
Returns:
true if at least one sub-server was found and could be initialized, false otherwise. Diagnostic messages are logged for each sub-server started.

respond

public boolean respond(Request request)
                throws IOException
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. If the "Host:" request header was not specified, or named a virtual host that was not initialized in init from the list of virtual hosts, this method returns without handling the request.
Specified by:
respond in interface Handler
Parameters:
request - The HTTP request to be forwarded to one of the sub-servers.
Returns:
true if the sub-server handled the message, false if it did not. false is also returned if the "Host:" was unspecified or unknown.

Version 2.2, Generated 07/25/00
Copyright (c) 2000, Sun Microsystems.