001: /*
002: * MultiProxyHandler.java
003: *
004: * Brazil project web application Framework,
005: * export version: 1.1
006: * Copyright (c) 1998-2000 Sun Microsystems, Inc.
007: *
008: * Sun Public License Notice
009: *
010: * The contents of this file are subject to the Sun Public License Version
011: * 1.0 (the "License"). You may not use this file except in compliance with
012: * the License. A copy of the License is included as the file "license.terms",
013: * and also available at http://www.sun.com/
014: *
015: * The Original Code is from:
016: * Brazil project web application Framework release 1.1.
017: * The Initial Developer of the Original Code is: suhler.
018: * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019: * All Rights Reserved.
020: *
021: * Contributor(s): cstevens, suhler.
022: *
023: * Version: 1.12
024: * Created by suhler on 98/09/21
025: * Last modified by suhler on 00/12/23 11:37:10
026: */
027:
028: package sunlabs.brazil.handler;
029:
030: import sunlabs.brazil.server.Server;
031: import java.util.Hashtable;
032:
033: /**
034: * Handler for permitting multiple cross connected virtual web sites.
035: * Each handler instance adds its prefix and destination to a
036: * static hashtable so the URL rewrite rules rewrite all of them correctly.
037: * <p>
038: * The
039: * {@link GenericProxyHandler}
040: * rewrites all of the links in each wepage to point back to the local.
041: * machine. Using this handler, if multiple virtual websites are configured,
042: * then links in one site that point to other virtual web sites are
043: * rewritten to point locally as well.
044: *
045: * @author Stephen Uhler
046: * @version 1.12, 00/12/23
047: */
048:
049: public class MultiProxyHandler extends GenericProxyHandler {
050:
051: /* XXX This shouldn't be global; instead there should be a
052: * per-server hashtable (sau)
053: */
054: /**
055: * Holds all proxy -> prefix mappings for this server.
056: */
057: public static Hashtable proxies = null;
058:
059: /**
060: * Initialize this handler.
061: * Add rewrite mapping into the global table.
062: * If any "virtual" web sites reference other "virtual" web sites, then
063: * rewrite the links accordingly.
064: */
065:
066: public boolean init(Server server, String prefix) {
067: if (!super .init(server, prefix)) {
068: return false;
069: }
070: if (proxies == null) {
071: proxies = new Hashtable(17);
072: }
073: String map = "http://" + host + ":" + port + "/";
074:
075: /*
076: * No good reason not to allow this, other then to prevent confusion
077: */
078:
079: if (proxies.containsKey(map)) {
080: server.log(Server.LOG_WARNING, prefix,
081: "Prefix already in use: " + map + " -> "
082: + proxies.get(map));
083: return false;
084: }
085: proxies.put(map, urlPrefix);
086: if (map.endsWith(":80/")) {
087: proxies.put(map.substring(0, map.length() - 4) + "/",
088: urlPrefix);
089: }
090:
091: server.log(Server.LOG_INFORMATIONAL, prefix, "proxies: "
092: + proxies);
093: return true;
094: }
095:
096: /**
097: * this gets called by the parent class.
098: */
099:
100: public void addMap(MapPage map) {
101: map.setMap(proxies);
102: }
103: }
|