sunlabs.brazil.sunlabs
Class WebMountHandler

java.lang.Object
  extended by sunlabs.brazil.sunlabs.WebMountHandler (view source)
All Implemented Interfaces:
Handler

public class WebMountHandler
extends Object
implements Handler

Handler for implementing "mounted" web sites. This causes another web site (or sites) to "appear" inside our document root. All of the appropriate links in HTML documents from the mounted site are rewritten, so they appear to be local references.

Properties:

proxy:port
If specified, use the indicated proxy. If ":port" is left off, port 80 is assumed.
getheaders
if specified, all http headers returned from the origin server are set in the request properties prefixed by the value of "getheaders".
doStyle
If true, look for (and rewrite) background URL's defined in inline style attributes. (e.g. <div style='background: url("/someimage.gif")'>). but requires the examination of every HTML tag. Using background images in style attributes in normally considered poor style.
debug
If true, then all mapped URL's are emitted to stderr.
debugHeaders
If true, then HTTP headers are emitted to stderr.
headers
A list of tokens that represent additonal http headers to add to this request. For each token the the pair: token.name and token.value are used. For example:
  headers=auth other
  auth.name=Authorization
  auth.value=Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
  other.name=X-foo
  other.value=bar
 
would cause the headers:
 Authorization: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
 X-foo: bar
 
to be added to the request.
mappings
A list of tokens spcifying which hosts are to be mapped. (defaults to "[prefix].map").
[map].remote
The remote website fetch
[map].local
The specified URL on the local machine to use Both "local" and "remote" may have ${..} constructs with are resolved relative to the server properties object.
mapRefer
If true the http "refer" header is mapped from the local namespace to the remote namespace
local, remote, fragment
These properties are added to the request and indicate the mapping from "local+fragment" to "remote+fragment".
configurationChanged
Normally the configuration options are read and processed once at startup. However, if configurationChanged is set, this handler will re-read it's configuration options, then un-set configurationChanged. This allows mounts to be modified dynamically. (This is an experimental feature).
rootpath=true|false
If true, all cookied paths are set to "/", otherwise they are translated relative to the mount point.
timelimit=[seconds]
Set the maximum time the server has to respond to this request. Use '0' for no timelimit.
noErrorReturn
If true, then if the proxy request fails, the response method returns "false", and places the reason for failure in the "errorCode" and "errorMsg" request properties. Otherwise, and error response is generated. The default is (erroneously) false for historical reasons.

Example:

 mappings = a b ...
 a.remote=http(s)://www.something.com/test/
 a.local=http(s)://localhost:2345/something/
 
A request for: /something/foo.htmlon localhost:2345 will cause the page from: http://www.something.com/test/foo.html to be fetched. In addition, any URL's in the returned document that start with http://www.something.com/test/ are modified to start with http://localhost:2345/something/ instead. This also applies for both cookie and location HTTP headers.

Notes:

See Also the MultiProxyHandler, which this class is designed to replace.


Constructor Summary
WebMountHandler()
           
 
Method Summary
 boolean init(Server server, String prefix)
          Remember the mounts
 byte[] modifyContent(Request request, byte[] content)
          Rewrite the links in an html or css file so they resolve correctly
 boolean respond(Request request)
          If this is one of "our" url's, fetch the document from the destination server, and return it as if it was local.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebMountHandler

public WebMountHandler()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Remember the mounts

Specified by:
init in interface Handler
Parameters:
server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
                throws IOException
If this is one of "our" url's, fetch the document from the destination server, and return it as if it was local.

Specified by:
respond in interface Handler
Parameters:
request - The Request 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 calling Request.sendResponse() or Request.sendError.
Throws:
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.


modifyContent

public byte[] modifyContent(Request request,
                            byte[] content)
Rewrite the links in an html or css file so they resolve correctly


Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.