Ejemplo n.º 1
0
  /**
   * Return the child Container that should be used to process this Request, based upon its
   * characteristics. If no such child Container can be identified, return <code>null</code>
   * instead.
   *
   * @param request Request being processed
   * @param update Update the Request to reflect the mapping selection?
   */
  public Container map(Request request, boolean update) {

    debug = engine.getDebug();

    // Extract the requested server name
    String server = request.getRequest().getServerName();
    if (server == null) {
      server = engine.getDefaultHost();
      if (update) request.setServerName(server);
    }
    if (server == null) return (null);
    if (debug >= 1) engine.log("Mapping server name '" + server + "'");

    // Find the specified host in our cache
    if (debug >= 2) engine.log(" Trying a cache match");
    Host host = (Host) cache.get(server);

    // Map to the default host if any
    if ((host == null) && (defaultHost != null)) {
      if (debug >= 2) engine.log(" Mapping to default host");
      host = defaultHost;
      addAlias(server, host);
    }

    // Update the Request if requested, and return the selected Host
    ; // No update to the Request is required
    return (host);
  }
Ejemplo n.º 2
0
  /**
   * Set the default Host used for resolving unknown host names.
   *
   * @param name Name of the default host
   */
  private void setDefaultHost(String name) {

    if (debug >= 3) engine.log("Setting default host '" + name + "'");

    if (name == null) defaultHost = null;
    else defaultHost = (Host) engine.findChild(name);
  }
Ejemplo n.º 3
0
  /**
   * Add a new child Host to our associated Engine.
   *
   * @param host Child host to add
   */
  private void addHost(Host host) {

    if (debug >= 3) engine.log("Adding host '" + host.getName() + "'");

    host.addContainerListener(this);

    // Register the host name
    addAlias(host.getName(), host);

    // Register all associated aliases
    String aliases[] = host.findAliases();
    for (int i = 0; i < aliases.length; i++) addAlias(aliases[i], host);
  }
Ejemplo n.º 4
0
  /**
   * Remove an existing child Host from our associated Engine.
   *
   * @param host Host to be removed
   */
  private void removeHost(Host host) {

    if (debug >= 3) engine.log("Removing host '" + host.getName() + "'");

    host.removeContainerListener(this);

    // Identify all names mapped to this host
    ArrayList removes = new ArrayList();
    Iterator keys = cache.keySet().iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (host.equals((Host) cache.get(key))) removes.add(key);
    }

    // Remove the associated names
    keys = removes.iterator();
    while (keys.hasNext()) {
      removeAlias((String) keys.next());
    }
  }
Ejemplo n.º 5
0
  /**
   * Remove the specified alias from our cache.
   *
   * @param alias Alias to remove
   */
  private void removeAlias(String alias) {

    if (debug >= 3) engine.log("Removing alias '" + alias + "'");
    cache.remove(alias.toLowerCase());
  }
Ejemplo n.º 6
0
  /**
   * Add an alias for the specified host.
   *
   * @param alias New alias name
   * @param host Host to resolve to
   */
  private void addAlias(String alias, Host host) {

    if (debug >= 3) engine.log("Adding alias '" + alias + "' for host '" + host.getName() + "'");
    cache.put(alias.toLowerCase(), host);
  }