Ejemplo n.º 1
0
  /**
   * Create an <code>ObjectName</code> for this <code>Manager</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param manager The Manager to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, Manager manager)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = manager.getContainer();

    if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=Manager");
    } else if (container instanceof Host) {
      name = new ObjectName(domain + ":type=Manager,host=" + container.getName());
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      name = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + host.getName());
    } else if (container == null) {
      DefaultContext defaultContext = manager.getDefaultContext();
      if (defaultContext != null) {
        Container parent = defaultContext.getParent();
        if (parent instanceof Engine) {
          name = new ObjectName(domain + ":type=DefaultManager");
        } else if (parent instanceof Host) {
          name = new ObjectName(domain + ":type=DefaultManager,host=" + parent.getName());
        }
      }
    }

    return (name);
  }
Ejemplo n.º 2
0
 /** Un-initialization. */
 @Override
 public void destroy() throws Exception {
   log.debug("TomcatVHostLoader un-init");
   Container[] children = host.findChildren();
   for (Container c : children) {
     if (c instanceof StandardContext) {
       try {
         ((StandardContext) c).stop();
         host.removeChild(c);
       } catch (Exception e) {
         log.error("Could not stop context: {}", c.getName(), e);
       }
     }
   }
   // remove system prop
   String propertyPrefix = name;
   if (domain != null) {
     propertyPrefix += '_' + domain.replace('.', '_');
   }
   System.clearProperty(propertyPrefix + ".webapp.root");
   // stop the host
   try {
     ((StandardHost) host).stop();
   } catch (LifecycleException e) {
     log.error("Could not stop host: {}", host.getName(), e);
   }
   // remove host
   engine.removeChild(host);
   // unregister jmx
   unregisterJMX();
 }
Ejemplo n.º 3
0
  @Override
  public String getMBeanKeyProperties() {
    Container c = this;
    StringBuilder keyProperties = new StringBuilder();
    int containerCount = 0;

    // Work up container hierarchy, add a component to the name for
    // each container
    while (!(c instanceof Engine)) {
      if (c instanceof Context) {
        keyProperties.append(",context=");
        ContextName cn = new ContextName(c.getName(), false);
        keyProperties.append(cn.getDisplayName());
      } else if (c instanceof Host) {
        keyProperties.append(",host=");
        keyProperties.append(c.getName());
      } else if (c == null) {
        // May happen in unit testing and/or some embedding scenarios
        keyProperties.append(",container");
        keyProperties.append(containerCount++);
        keyProperties.append("=null");
        break;
      } else {
        // Should never happen...
        keyProperties.append(",container");
        keyProperties.append(containerCount++);
        keyProperties.append('=');
        keyProperties.append(c.getName());
      }
      c = c.getParent();
    }
    return keyProperties.toString();
  }
  /**
   * Log a message on the Logger associated with our Container (if any).
   *
   * @param message Message to be logged
   */
  protected void log(String message) {

    Logger logger = null;
    if (container != null) logger = container.getLogger();
    if (logger != null) logger.log("StandardPipeline[" + container.getName() + "]: " + message);
    else System.out.println("StandardPipeline[" + container.getName() + "]: " + message);
  }
Ejemplo n.º 5
0
 @Override
 protected String getDomainInternal() {
   Container container = getContainer();
   if (container == null) {
     return null;
   }
   return container.getDomain();
 }
  public void begin(String namespace, String name, Attributes attributes) throws Exception {

    if (digester.getLogger().isDebugEnabled())
      digester.getLogger().debug("Setting parent class loader");

    Container top = (Container) digester.peek();
    top.setParentClassLoader(parentClassLoader);
  }
Ejemplo n.º 7
0
 @Override
 protected String getDomainInternal() {
   Container p = getParent();
   if (p == null) {
     return null;
   } else {
     return p.getDomain();
   }
 }
Ejemplo n.º 8
0
 /**
  * Retrieve the enclosing Engine for this Manager.
  *
  * @return an Engine object (or null).
  */
 public Engine getEngine() {
   Engine e = null;
   for (Container c = getContainer(); e == null && c != null; c = c.getParent()) {
     if (c != null && c instanceof Engine) {
       e = (Engine) c;
     }
   }
   return e;
 }
Ejemplo n.º 9
0
  @Override
  protected String getObjectNameKeyProperties() {
    StringBuilder name = new StringBuilder("type=Cluster");

    Container container = getContainer();
    if (container != null) {
      name.append(container.getMBeanKeyProperties());
    }

    return name.toString();
  }
Ejemplo n.º 10
0
  /**
   * Log a message on the Logger associated with our Container (if any).
   *
   * @param message Message to be logged
   * @param throwable Associated exception
   */
  protected void log(String message, Throwable throwable) {

    Logger logger = null;
    if (container != null) logger = container.getLogger();
    if (logger != null)
      logger.log("StandardPipeline[" + container.getName() + "]: " + message, throwable);
    else {
      System.out.println("StandardPipeline[" + container.getName() + "]: " + message);
      throwable.printStackTrace(System.out);
    }
  }
 private void waitForSessionExpiration(final boolean sticky) throws InterruptedException {
   final SessionManager manager = _tomcat1.getManager();
   assertEquals(manager.getMemcachedSessionService().isSticky(), sticky);
   final Container container = manager.getContainer();
   final long timeout =
       TimeUnit.SECONDS.toMillis(
               sticky
                   ? container.getBackgroundProcessorDelay() + manager.getMaxInactiveInterval()
                   : 2 * manager.getMaxInactiveInterval())
           + 1000;
   Thread.sleep(timeout);
 }
Ejemplo n.º 12
0
  /**
   * Create an <code>ObjectName</code> for this <code>Valve</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param valve The Valve to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, GlassFishValve valve)
      throws MalformedObjectNameException {
    if (valve instanceof ValveBase) {
      ObjectName name = ((ValveBase) valve).getObjectName();
      if (name != null) return name;
    }

    ObjectName name = null;
    Container container = null;
    String className = valve.getClass().getName();
    int period = className.lastIndexOf('.');
    if (period >= 0) className = className.substring(period + 1);
    if (valve instanceof Contained) {
      container = ((Contained) valve).getContainer();
    }
    if (container == null) {
      throw new MalformedObjectNameException(
          "Cannot create mbean for non-contained valve " + valve);
    }
    if (container instanceof Engine) {
      String local = "";
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    } else if (container instanceof Host) {
      String local = ",host=" + container.getName();
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      String local = ",path=" + path + ",host=" + host.getName();
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    }

    return (name);
  }
Ejemplo n.º 13
0
  private void registerMember(Member member) {
    // JMX registration
    StringBuilder name = new StringBuilder("type=Cluster");
    Container container = getContainer();
    if (container != null) {
      name.append(container.getMBeanKeyProperties());
    }
    name.append(",component=Member,name=");
    name.append(ObjectName.quote(member.getName()));

    ObjectName oname = register(member, name.toString());
    memberOnameMap.put(member, oname);
  }
Ejemplo n.º 14
0
 @Override
 protected void initInternal() throws LifecycleException {
   super.initInternal();
   if (clusterDeployer != null) {
     StringBuilder name = new StringBuilder("type=Cluster");
     Container container = getContainer();
     if (container != null) {
       name.append(container.getMBeanKeyProperties());
     }
     name.append(",component=Deployer");
     onameClusterDeployer = register(clusterDeployer, name.toString());
   }
 }
Ejemplo n.º 15
0
 private static void stopWebApp(StandardContext context) throws Exception {
   try {
     Container container = context.getParent();
     container.removeChild(context);
     context.stop();
   } catch (LifecycleException e) {
     throw MESSAGES.stopContextPhaseFailed(e);
   }
   try {
     context.destroy();
   } catch (Exception e) {
     throw MESSAGES.destroyContextPhaseFailed(e);
   }
 }
Ejemplo n.º 16
0
  /**
   * Log a message on the Logger associated with our Container (if any)
   *
   * @param message Message to be logged
   */
  protected void log(String message) {

    Logger logger = null;
    String name = null;
    if (container != null) {
      logger = container.getLogger();
      name = container.getName();
    }

    if (logger != null) {
      logger.log(getName() + "[" + name + "]: " + message);
    } else {
      System.out.println(getName() + "[" + name + "]: " + message);
    }
  }
Ejemplo n.º 17
0
  /** Register this Manager with JMX. */
  protected void registerManagerMBean() {
    try {
      MBeanServer server = getMBeanServer();

      String domain;
      if (container_ instanceof ContainerBase) {
        domain = ((ContainerBase) container_).getDomain();
      } else {
        domain = server.getDefaultDomain();
      }
      String hostName = ((Host) container_.getParent()).getName();
      hostName = (hostName == null) ? "localhost" : hostName;
      ObjectName clusterName =
          new ObjectName(
              domain
                  + ":type=Manager,host="
                  + hostName
                  + ",path="
                  + ((Context) container_).getPath());

      if (server.isRegistered(clusterName)) {
        log_.warn("MBean " + clusterName + " already registered");
        return;
      }

      objectName_ = clusterName;
      server.registerMBean(this, clusterName);

    } catch (Exception ex) {
      log_.error("Could not register " + getClass().getSimpleName() + " to MBeanServer", ex);
    }
  }
Ejemplo n.º 18
0
 /**
  * Return the Server object that is the ultimate parent for the container with which this Realm is
  * associated. If the server cannot be found (eg because the container hierarchy is not complete),
  * <code>null</code> is returned.
  */
 protected Server getServer() {
   Container c = container;
   if (c instanceof Context) {
     c = c.getParent();
   }
   if (c instanceof Host) {
     c = c.getParent();
   }
   if (c instanceof Engine) {
     Service s = ((Engine) c).getService();
     if (s != null) {
       return s.getServer();
     }
   }
   return null;
 }
Ejemplo n.º 19
0
  /**
   * Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the
   * Valve, the Valve's <code>setContainer()</code> method will be called, if it implements <code>
   * Contained</code>, with the owning Container as an argument. The method may throw an <code>
   * IllegalArgumentException</code> if this Valve chooses not to be associated with this Container,
   * or <code>IllegalStateException</code> if it is already associated with a different Container.
   *
   * @param valve Valve to be added
   * @exception IllegalArgumentException if this Container refused to accept the specified Valve
   * @exception IllegalArgumentException if the specified Valve refuses to be associated with this
   *     Container
   * @exception IllegalStateException if the specified Valve is already associated with a different
   *     Container
   */
  @Override
  public void addValve(Valve valve) {

    // Validate that we can add this Valve
    if (valve instanceof Contained) ((Contained) valve).setContainer(this.container);

    // Start the new component if necessary
    if (getState().isAvailable()) {
      if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).start();
        } catch (LifecycleException e) {
          log.error("StandardPipeline.addValve: start: ", e);
        }
      }
    }

    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
      first = valve;
      valve.setNext(basic);
    } else {
      Valve current = first;
      while (current != null) {
        if (current.getNext() == basic) {
          current.setNext(valve);
          valve.setNext(basic);
          break;
        }
        current = current.getNext();
      }
    }

    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
  }
Ejemplo n.º 20
0
 @Override
 public synchronized void stop() throws Exception {
   if (_serverContext != null) {
     // Destroy the web context unless if it is default
     if (!_serverContext.getPath().equals("/")) {
       try {
         Container container = _serverContext.getParent();
         container.removeChild(_serverContext);
         _serverContext.stop();
         _serverContext.destroy();
         _log.info("Destroyed HTTP context " + _serverContext.getPath());
       } catch (Exception e) {
         _log.error("Unable to destroy web context", e);
       }
     }
   }
 }
Ejemplo n.º 21
0
  // -------------------- JMX and Registration  --------------------
  @Override
  public String getObjectNameKeyProperties() {
    StringBuilder name = new StringBuilder("type=Valve");

    Container container = getContainer();

    name.append(MBeanUtils.getContainerKeyProperties(container));

    int seq = 0;

    // Pipeline may not be present in unit testing
    Pipeline p = container.getPipeline();
    if (p != null) {
      for (Valve valve : p.getValves()) {
        // Skip null valves
        if (valve == null) {
          continue;
        }
        // Only compare valves in pipeline until we find this valve
        if (valve == this) {
          break;
        }
        if (valve.getClass() == this.getClass()) {
          // Duplicate valve earlier in pipeline
          // increment sequence number
          seq++;
        }
      }
    }

    if (seq > 0) {
      name.append(",seq=");
      name.append(seq);
    }

    String className = this.getClass().getName();
    int period = className.lastIndexOf('.');
    if (period >= 0) {
      className = className.substring(period + 1);
    }
    name.append(",name=");
    name.append(className);

    return name.toString();
  }
Ejemplo n.º 22
0
 /**
  * @param name
  * @param manager
  * @return TODO
  */
 @Override
 public String getManagerName(String name, Manager manager) {
   String clusterName = name;
   if (clusterName == null) clusterName = manager.getContext().getName();
   if (getContainer() instanceof Engine) {
     Context context = manager.getContext();
     if (context != null) {
       Container host = context.getParent();
       if (host != null
           && host instanceof Host
           && clusterName != null
           && !(clusterName.startsWith(host.getName() + "#"))) {
         clusterName = host.getName() + "#" + clusterName;
       }
     }
   }
   return clusterName;
 }
Ejemplo n.º 23
0
  /**
   * Logs the given message to the Logger associated with the Container (if any) of this
   * StandardPipeline.
   *
   * @param message the message
   * @param t the Throwable
   */
  protected void log(String message, Throwable t) {
    org.apache.catalina.Logger logger = null;
    if (container != null) {
      logger = container.getLogger();

      String msg =
          MessageFormat.format(
              rb.getString(STANDARD_PIPELINE_INFO), new Object[] {container.getName(), message});

      if (logger != null) {
        logger.log(msg, t, org.apache.catalina.Logger.WARNING);
      } else {
        log.log(Level.WARNING, msg, t);
      }
    } else {
      String msg = MessageFormat.format(rb.getString(STANDARD_PIPELINE_NULL_INFO), message);
      log.log(Level.WARNING, msg, t); // INFO set to WARNING
    }
  }
Ejemplo n.º 24
0
  /**
   * Return a File object representing the "configuration root" directory for our associated Host.
   */
  protected File configBase() {

    if (configBase != null) {
      return configBase;
    }

    File file = new File(System.getProperty("catalina.base"), "conf");
    Container parent = host.getParent();
    if ((parent != null) && (parent instanceof Engine)) {
      file = new File(file, parent.getName());
    }
    file = new File(file, host.getName());
    try {
      configBase = file.getCanonicalFile();
    } catch (IOException e) {
      configBase = file;
    }
    return (configBase);
  }
Ejemplo n.º 25
0
  @Override
  protected void initInternal() throws LifecycleException {

    super.initInternal();

    // We want logger as soon as possible
    if (container != null) {
      this.containerLog = container.getLogger();
    }

    x509UsernameRetriever = createUsernameRetriever(x509UsernameRetrieverClassName);
  }
Ejemplo n.º 26
0
  /**
   * Create an <code>ObjectName</code> for this <code>Realm</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param realm The Realm to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, Realm realm)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = realm.getContainer();

    if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=Realm");
    } else if (container instanceof Host) {
      name = new ObjectName(domain + ":type=Realm,host=" + container.getName());
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      name = new ObjectName(domain + ":type=Realm,path=" + path + ",host=" + host.getName());
    }

    return (name);
  }
Ejemplo n.º 27
0
 /** Return a String rendering of this object. */
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder(this.getClass().getName());
   sb.append('[');
   if (container == null) {
     sb.append("Container is null");
   } else {
     sb.append(container.getName());
   }
   sb.append(']');
   return sb.toString();
 }
  /**
   * Prepare for the beginning of active use of the public methods of this component. This method
   * should be called after <code>configure()</code>, and before any of the public methods of the
   * component are utilized.
   *
   * @exception LifecycleException if this component detects a fatal error that prevents this
   *     component from being used
   */
  public void start() throws LifecycleException {

    // Validate and update our current component state
    if (started) throw new LifecycleException(sm.getString("authenticator.alreadyStarted"));
    lifecycle.fireLifecycleEvent(START_EVENT, null);
    if ("org.apache.catalina.core.StandardContext".equals(context.getClass().getName())) {
      try {
        Class paramTypes[] = new Class[0];
        Object paramValues[] = new Object[0];
        Method method = context.getClass().getMethod("getDebug", paramTypes);
        Integer result = (Integer) method.invoke(context, paramValues);
        setDebug(result.intValue());
      } catch (Exception e) {
        log("Exception getting debug value", e);
      }
    }
    started = true;

    // Look up the SingleSignOn implementation in our request processing
    // path, if there is one
    Container parent = context.getParent();
    while ((sso == null) && (parent != null)) {
      if (!(parent instanceof Pipeline)) {
        parent = parent.getParent();
        continue;
      }
      Valve valves[] = ((Pipeline) parent).getValves();
      for (int i = 0; i < valves.length; i++) {
        if (valves[i] instanceof SingleSignOn) {
          sso = (SingleSignOn) valves[i];
          break;
        }
      }
      if (sso == null) parent = parent.getParent();
    }
    if (debug >= 1) {
      if (sso != null) log("Found SingleSignOn Valve at " + sso);
      else log("No SingleSignOn Valve is present");
    }
  }
  public void processContainerRemoveChild(Container parent, Container child)
      throws RemoteException, RemoteException {

    if (log.isDebugEnabled())
      log.debug("Process removeChild[parent=" + parent + ",child=" + child + "]");

    if (child instanceof Context) {
      Context context = (Context) child;
      context.removeLifecycleListener(this);
    } else if (child instanceof Host || child instanceof Engine) {
      child.removeContainerListener(this);
    }
  }
Ejemplo n.º 30
0
  /**
   * Log a message on the Logger associated with our Container (if any).
   *
   * @param message Message to be logged
   */
  protected void log(String message) {
    org.apache.catalina.Logger logger = null;
    if (container != null) {
      logger = container.getLogger();

      String msg =
          MessageFormat.format(
              rb.getString(STANDARD_PIPELINE_INFO), new Object[] {container.getName(), message});

      if (logger != null) {
        logger.log(msg);
      } else {
        if (log.isLoggable(Level.INFO)) {
          log.log(Level.INFO, msg);
        }
      }
    } else {
      if (log.isLoggable(Level.INFO)) {
        String msg = MessageFormat.format(rb.getString(STANDARD_PIPELINE_NULL_INFO), message);
        log.log(Level.INFO, msg);
      }
    }
  }