Class WebMountHandler

  extended by sunlabs.brazil.sunlabs.WebMountHandler (view source)
All Implemented Interfaces:

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.


If specified, use the indicated proxy. If ":port" is left off, port 80 is assumed.
if specified, all http headers returned from the origin server are set in the request properties prefixed by the value of "getheaders".
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.
If true, then all mapped URL's are emitted to stderr.
If true, then HTTP headers are emitted to stderr.
A list of tokens that represent additonal http headers to add to this request. For each token the the pair: and token.value are used. For example:
  headers=auth other
  auth.value=Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
would cause the headers:
 Authorization: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
 X-foo: bar
to be added to the request.
A list of tokens spcifying which hosts are to be mapped. (defaults to "[prefix].map").
The remote website fetch
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.
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".
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).
If true, all cookied paths are set to "/", otherwise they are translated relative to the mount point.
Set the maximum time the server has to respond to this request. Use '0' for no timelimit.
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.


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


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

Constructor Summary
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


public WebMountHandler()
Method Detail


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

Specified by:
init in interface Handler
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.
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.


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
request - The Request object that represents the HTTP request.
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.
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.


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.