[jboss-cvs] JBossAS SVN: r76138 - in branches/JBoss_4_0_5_GA_CP: tomcat/src/main/org/jboss/web/tomcat/tc5 and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 23 12:12:06 EDT 2008


Author: mmoyses
Date: 2008-07-23 12:12:06 -0400 (Wed, 23 Jul 2008)
New Revision: 76138

Modified:
   branches/JBoss_4_0_5_GA_CP/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java
   branches/JBoss_4_0_5_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/TomcatDeployer.java
Log:
ASPATCH-386: changed hard coded "localhost" MBean names

Modified: branches/JBoss_4_0_5_GA_CP/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java	2008-07-23 16:02:46 UTC (rev 76137)
+++ branches/JBoss_4_0_5_GA_CP/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java	2008-07-23 16:12:06 UTC (rev 76138)
@@ -21,6 +21,18 @@
  */
 package org.jboss.management.j2ee;
 
+import java.net.InetAddress;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.JMException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
 import org.jboss.deployment.DeploymentInfo;
 import org.jboss.deployment.MainDeployerConstants;
 import org.jboss.deployment.SubDeployer;
@@ -32,17 +44,6 @@
 import org.jboss.system.ServiceMBean;
 import org.jboss.system.ServiceMBeanSupport;
 
-import javax.management.JMException;
-import javax.management.MBeanException;
-import javax.management.MBeanServer;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import java.net.InetAddress;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
 /**
  * The integration MBean for the local JBoss server management domain. This
  * bridges between the core JBoss JSR-77 agnostic code to the JSR-77
@@ -53,7 +54,9 @@
  * @version $Revision$
  */
 public class LocalJBossServerDomain extends ServiceMBeanSupport
-   implements NotificationListener, LocalJBossServerDomainMBean
+      implements
+         NotificationListener,
+         LocalJBossServerDomainMBean
 {
    /**
     * Class logger.
@@ -66,66 +69,82 @@
     * The name of the MainDeployer
     */
    private ObjectName mainDeployer;
+
    /**
     * The name of the SARDeployer
     */
    private ObjectName sarDeployer;
+
    /**
     * The name of the EARDeployer
     */
    private ObjectName earDeployer;
+
    /**
     * The name of the EJBDeployer
     */
    private ObjectName ejbDeployer;
+
    /**
     * The name of the RARDeployer
     */
    private ObjectName rarDeployer;
+
    /**
     * The name of the JCA connection manager deployer
     */
    private ObjectName jcaCMDeployer;
+
    /**
     * The name of the WARDeployer
     */
    private ObjectName warDeployer;
+
    /**
     * The client application deployer
-    */ 
+    */
    private ObjectName carDeployer;
+
    /**
     * The name of the JMS service
     */
    private ObjectName jmsService;
+
    /**
     * The name of the JNDI service
     */
    private ObjectName jndiService;
+
    /**
     * The name of the JTA service
     */
    private ObjectName jtaService;
+
    /**
     * The name of the UserTransaction service
     */
    private ObjectName userTxService;
+
    /**
     * The name of the JavaMail service
     */
    private ObjectName mailService;
+
    /**
     * The name of the RMI_IIOP service
     */
    private ObjectName rmiiiopService;
+
    /**
     * The name of the service which emites URL binding events
     */
    private ObjectName jndiBindingService;
+
    /**
     * A mapping of JMX notifications to ManagedObjectFactory instances
     */
    private ManagedObjectFactoryMap managedObjFactoryMap;
+
    private Class managedObjFactoryMapClass = DefaultManagedObjectFactoryMap.class;
 
    // -------------------------------------------------------------------------
@@ -274,6 +293,7 @@
    {
       return carDeployer;
    }
+
    /**
     * @param name The CARDeployer mbean name
     * @jmx:managed-attribute
@@ -631,10 +651,10 @@
          {
             // Ignore when host address is not accessible (localhost is used instead)
          }
-         JVM jvm = new JVM("localhost", lServer,
-                 System.getProperty("java.version"),
-                 System.getProperty("java.vendor"),
-                 hostName);
+         String vmVendor = System.getProperty("java.vendor");
+         String vmVersion = System.getProperty("java.version");
+         String name = vmVendor + " " + vmVersion;
+         JVM jvm = new JVM(name, lServer, vmVersion, vmVendor, hostName);
          ObjectName jvmName = jvm.getObjectName();
          mbeanServer.registerMBean(jvm, jvmName);
       }
@@ -657,8 +677,7 @@
    {
       try
       {
-         mbeanServer.addNotificationListener(ServiceControllerMBean.OBJECT_NAME,
-                 this, null, null);
+         mbeanServer.addNotificationListener(ServiceControllerMBean.OBJECT_NAME, this, null, null);
          log.debug("Registered as listener of: " + ServiceControllerMBean.OBJECT_NAME);
       }
       catch (JMException jme)
@@ -700,8 +719,7 @@
     * @throws Exception thrown on failure to register as a listener of the
     *                   MainDeployer or to obtain the list of deployers
     */
-   private void registerWithCurrentDeployers(MBeanServer mbeanServer)
-           throws Exception
+   private void registerWithCurrentDeployers(MBeanServer mbeanServer) throws Exception
    {
       log.debug("Registering with all deployers, mainDeployer=" + mainDeployer);
       mbeanServer.addNotificationListener(mainDeployer, this, null, null);
@@ -710,8 +728,7 @@
       log.debug("Getting current deployers");
       Object[] args = {};
       String[] sig = {};
-      Collection deployers = (Collection) mbeanServer.invoke(mainDeployer,
-              "listDeployers", args, sig);
+      Collection deployers = (Collection) mbeanServer.invoke(mainDeployer, "listDeployers", args, sig);
       Iterator iter = deployers.iterator();
       while (iter.hasNext())
       {
@@ -727,8 +744,7 @@
     * @throws Exception thrown on failure to unregister as a listener of the
     *                   MainDeployer or to obtain the list of deployers
     */
-   private void unregisterWithCurrentDeployers(MBeanServer mbeanServer)
-           throws Exception
+   private void unregisterWithCurrentDeployers(MBeanServer mbeanServer) throws Exception
    {
       log.debug("Unregistering with all deployers, mainDeployer=" + mainDeployer);
       mbeanServer.removeNotificationListener(mainDeployer, this);
@@ -737,8 +753,7 @@
       log.debug("Getting current deployers");
       Object[] args = {};
       String[] sig = {};
-      Collection deployers = (Collection) mbeanServer.invoke(mainDeployer,
-              "listDeployers", args, sig);
+      Collection deployers = (Collection) mbeanServer.invoke(mainDeployer, "listDeployers", args, sig);
       Iterator iter = deployers.iterator();
       while (iter.hasNext())
       {

Modified: branches/JBoss_4_0_5_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/TomcatDeployer.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/TomcatDeployer.java	2008-07-23 16:02:46 UTC (rev 76137)
+++ branches/JBoss_4_0_5_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/TomcatDeployer.java	2008-07-23 16:12:06 UTC (rev 76138)
@@ -46,7 +46,6 @@
 import org.jboss.web.AbstractWebContainer;
 import org.jboss.web.AbstractWebDeployer;
 import org.jboss.web.WebApplication;
-import org.jboss.web.tomcat.security.CustomPrincipalValve;
 import org.jboss.web.tomcat.security.JaccContextValve;
 import org.jboss.web.tomcat.security.RunAsListener;
 import org.jboss.web.tomcat.security.SecurityAssociationValve;
@@ -69,9 +68,15 @@
    private static final String CONTEXT_CONFIG_FILE = "WEB-INF/context.xml";
 
    private DeployerConfig config;
-   private String[] javaVMs =
-      {" jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=localhost"};
+
+   private String vmName = System.getProperty("java.vendor");
+
+   private String vmVersion = System.getProperty("java.version");
+
+   private String[] javaVMs = {"jboss.management.local:J2EEServer=Local,j2eeType=JVM,name=" + vmName + " " + vmVersion};
+
    private String serverName = "jboss";
+
    private HashMap vhostToHostNames = new HashMap();
 
    public void init(Object containerConfig) throws Exception
@@ -87,8 +92,7 @@
     * Perform the tomcat specific deployment steps.
     */
    protected void performDeploy(WebApplication appInfo, String warUrl,
-      AbstractWebContainer.WebDescriptorParser webAppParser)
-      throws Exception
+         AbstractWebContainer.WebDescriptorParser webAppParser) throws Exception
    {
       WebMetaData metaData = appInfo.getMetaData();
       String hostName = null;
@@ -108,10 +112,8 @@
       }
    }
 
-   protected void performDeployInternal(String hostName,
-      WebApplication appInfo, String warUrl,
-      AbstractWebContainer.WebDescriptorParser webAppParser)
-      throws Exception
+   protected void performDeployInternal(String hostName, WebApplication appInfo, String warUrl,
+         AbstractWebContainer.WebDescriptorParser webAppParser) throws Exception
    {
 
       WebMetaData metaData = appInfo.getMetaData();
@@ -160,23 +162,25 @@
       appInfo.setClassLoader(loader);
       appInfo.setURL(url);
 
-      String objectNameS = config.getCatalinaDomain()
-         + ":j2eeType=WebModule,name=//" +
-         ((hostName == null) ? "localhost" : hostName)
-         + ctxPath + ",J2EEApplication=none,J2EEServer=none";
+      String defaultHost = hostName;
+      if (defaultHost == null)
+      {
+         String objName = config.getCatalinaDomain() + ":type=Engine";
+         defaultHost = (String) server.getAttribute(new ObjectName(objName), "defaultHost");
+      }
+      String objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//" + defaultHost + ctxPath
+            + ",J2EEApplication=none,J2EEServer=none";
 
       ObjectName objectName = new ObjectName(objectNameS);
 
       if (server.isRegistered(objectName))
       {
          log.debug("Already exists, destroying " + objectName);
-         server.invoke(objectName, "destroy", new Object[]{},
-            new String[]{});
+         server.invoke(objectName, "destroy", new Object[]{}, new String[]{});
       }
 
-      server.createMBean("org.apache.commons.modeler.BaseModelMBean",
-         objectName, new Object[]{config.getContextClassName()},
-         new String[]{"java.lang.String"});
+      server.createMBean("org.apache.commons.modeler.BaseModelMBean", objectName, new Object[]{config
+            .getContextClassName()}, new String[]{"java.lang.String"});
 
       // Find and set config file on the context
       // If WAR is packed, expand config file to temp folder
@@ -194,31 +198,25 @@
 
       server.setAttribute(objectName, new Attribute("configFile", ctxConfig));
 
-      server.setAttribute(objectName, new Attribute
-         ("defaultContextXml", "context.xml"));
-      server.setAttribute(objectName, new Attribute
-         ("defaultWebXml", "conf/web.xml"));
+      server.setAttribute(objectName, new Attribute("defaultContextXml", "context.xml"));
+      server.setAttribute(objectName, new Attribute("defaultWebXml", "conf/web.xml"));
 
       server.setAttribute(objectName, new Attribute("javaVMs", javaVMs));
 
       server.setAttribute(objectName, new Attribute("server", serverName));
 
-      server.setAttribute(objectName, new Attribute
-         ("saveConfig", Boolean.FALSE));
+      server.setAttribute(objectName, new Attribute("saveConfig", Boolean.FALSE));
 
       if (webLoader != null)
       {
-         server.setAttribute(objectName, new Attribute
-            ("loader", webLoader));
+         server.setAttribute(objectName, new Attribute("loader", webLoader));
       }
       else
       {
-         server.setAttribute(objectName, new Attribute
-            ("parentClassLoader", loader));
+         server.setAttribute(objectName, new Attribute("parentClassLoader", loader));
       }
 
-      server.setAttribute(objectName, new Attribute
-         ("delegate", new Boolean(getJava2ClassLoadingCompliance())));
+      server.setAttribute(objectName, new Attribute("delegate", new Boolean(getJava2ClassLoadingCompliance())));
 
       String[] jspCP = getCompileClasspath(loader);
       StringBuffer classpath = new StringBuffer();
@@ -245,7 +243,7 @@
                // avoid opening .xml files
                if (fp.getName().toLowerCase().endsWith(".xml"))
                   continue;
-               
+
                ZipFile zip = new ZipFile(fp);
                zip.close();
             }
@@ -260,23 +258,20 @@
          classpath.append(repository);
       }
 
-      server.setAttribute(objectName, new Attribute
-         ("compilerClasspath", classpath.toString()));
+      server.setAttribute(objectName, new Attribute("compilerClasspath", classpath.toString()));
 
       // Set the session cookies flag according to metadata
       switch (metaData.getSessionCookies())
       {
-         case WebMetaData.SESSION_COOKIES_ENABLED:
-            server.setAttribute(objectName, new Attribute
-               ("cookies", new Boolean(true)));
+         case WebMetaData.SESSION_COOKIES_ENABLED :
+            server.setAttribute(objectName, new Attribute("cookies", new Boolean(true)));
             log.debug("Enabling session cookies");
             break;
-         case WebMetaData.SESSION_COOKIES_DISABLED:
-            server.setAttribute(objectName, new Attribute
-               ("cookies", new Boolean(false)));
+         case WebMetaData.SESSION_COOKIES_DISABLED :
+            server.setAttribute(objectName, new Attribute("cookies", new Boolean(false)));
             log.debug("Disabling session cookies");
             break;
-         default:
+         default :
             log.debug("Using session cookies default setting");
       }
 
@@ -284,9 +279,7 @@
       Certificate[] certs = null;
       CodeSource cs = new CodeSource(url, certs);
       JaccContextValve jaccValve = new JaccContextValve(metaData.getJaccContextID(), cs);
-      server.invoke(objectName, "addValve",
-         new Object[]{jaccValve},
-         new String[]{"org.apache.catalina.Valve"});
+      server.invoke(objectName, "addValve", new Object[]{jaccValve}, new String[]{"org.apache.catalina.Valve"});
 
       // Pass the metadata to the RunAsListener via a thread local
       RunAsListener.metaDataLocal.set(metaData);
@@ -303,7 +296,7 @@
 
       // make the context class loader known to the WebMetaData, ws4ee needs it
       // to instanciate service endpoint pojos that live in this webapp
-      Loader ctxLoader = (Loader)server.getAttribute(objectName, "loader");
+      Loader ctxLoader = (Loader) server.getAttribute(objectName, "loader");
       metaData.setContextLoader(ctxLoader.getClassLoader());
 
       // Clustering
@@ -318,7 +311,7 @@
             manager = (AbstractJBossManager) managerClass.newInstance();
 
             if (manager instanceof JBossCacheManager)
-            {        
+            {
                // TODO either deprecate snapshot mode or move its config
                // into jboss-web.xml.
                String snapshotMode = config.getSnapshotMode();
@@ -327,30 +320,29 @@
                jbcm.setSnapshotMode(snapshotMode);
                jbcm.setSnapshotInterval(snapshotInterval);
             }
-            
+
             String name = "//" + ((hostName == null) ? "localhost" : hostName) + ctxPath;
             manager.init(name, metaData, config.isUseJK(), config.isUseLocalCache());
-            
+
             // Don't assign the manager to the context until all config
             // is done, or else the manager will be started without the config
             server.setAttribute(objectName, new Attribute("manager", manager));
-            
+
             log.debug("Enabled clustering support for ctxPath=" + ctxPath);
          }
          catch (ClusteringNotSupportedException e)
          {
             // JBAS-3513 Just log a WARN, not an ERROR
-            log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: " + 
-                  e.getMessage());
+            log.warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: "
+                  + e.getMessage());
          }
          catch (NoClassDefFoundError ncdf)
          {
             // JBAS-3513 Just log a WARN, not an ERROR
             log.debug("Classes needed for clustered webapp unavailable", ncdf);
-            log.warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: " + 
-                  ncdf.getMessage());            
+            log.warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: " + ncdf.getMessage());
          }
-         catch(Throwable t)
+         catch (Throwable t)
          {
             // TODO consider letting this through and fail the deployment
             log.error("Failed to setup clustering, clustering disabled. Exception: ", t);
@@ -361,12 +353,9 @@
       valves so that the authenticated user may be associated with the
       request thread/session.
       */
-      SecurityAssociationValve valve = new SecurityAssociationValve(metaData,
-         config.getSecurityManagerService());
+      SecurityAssociationValve valve = new SecurityAssociationValve(metaData, config.getSecurityManagerService());
       valve.setSubjectAttributeName(config.getSubjectAttributeName());
-      server.invoke(objectName, "addValve",
-         new Object[]{valve},
-         new String[]{"org.apache.catalina.Valve"});
+      server.invoke(objectName, "addValve", new Object[]{valve}, new String[]{"org.apache.catalina.Valve"});
 
       // Retrieve the state, and throw an exception in case of a failure
       Integer state = (Integer) server.getAttribute(objectName, "state");
@@ -380,9 +369,8 @@
       // Create mbeans for the servlets
       DeploymentInfo di = webAppParser.getDeploymentInfo();
       di.deployedObject = objectName;
-      ObjectName servletQuery = new ObjectName
-         (config.getCatalinaDomain() + ":j2eeType=Servlet,WebModule="
-         + objectName.getKeyProperty("name") + ",*");
+      ObjectName servletQuery = new ObjectName(config.getCatalinaDomain() + ":j2eeType=Servlet,WebModule="
+            + objectName.getKeyProperty("name") + ",*");
       Iterator iterator = server.queryMBeans(servletQuery, null).iterator();
       while (iterator.hasNext())
       {
@@ -393,23 +381,20 @@
 
    }
 
-
    /**
     * Called as part of the undeploy() method template to ask the
     * subclass for perform the web container specific undeployment steps.
     */
-   protected void performUndeploy(String warUrl, WebApplication appInfo)
-      throws Exception
+   protected void performUndeploy(String warUrl, WebApplication appInfo) throws Exception
    {
       if (appInfo == null)
       {
-         log.debug("performUndeploy, no WebApplication found for URL "
-            + warUrl);
+         log.debug("performUndeploy, no WebApplication found for URL " + warUrl);
          return;
       }
 
-      log.info("undeploy, ctxPath=" + appInfo.getMetaData().getContextRoot()
-         + ", warUrl=" + shortWarUrlFromServerHome(warUrl));
+      log.info("undeploy, ctxPath=" + appInfo.getMetaData().getContextRoot() + ", warUrl="
+            + shortWarUrlFromServerHome(warUrl));
 
       WebMetaData metaData = appInfo.getMetaData();
       String hostName = null;
@@ -427,9 +412,7 @@
 
    }
 
-   protected void performUndeployInternal(String hostName, String warUrl,
-      WebApplication appInfo)
-      throws Exception
+   protected void performUndeployInternal(String hostName, String warUrl, WebApplication appInfo) throws Exception
    {
 
       WebMetaData metaData = appInfo.getMetaData();
@@ -439,16 +422,13 @@
       if (server == null)
          return;
 
-      ObjectName objectName = new ObjectName(config.getCatalinaDomain()
-         + ":j2eeType=WebModule,name=//" +
-         ((hostName == null) ? "localhost" : hostName)
-         + ctxPath + ",J2EEApplication=none,J2EEServer=none");
+      ObjectName objectName = new ObjectName(config.getCatalinaDomain() + ":j2eeType=WebModule,name=//"
+            + ((hostName == null) ? "localhost" : hostName) + ctxPath + ",J2EEApplication=none,J2EEServer=none");
 
       if (server.isRegistered(objectName))
       {
          // Contexts should be stopped by the host already
-         server.invoke(objectName, "destroy", new Object[]{},
-            new String[]{});
+         server.invoke(objectName, "destroy", new Object[]{}, new String[]{});
       }
 
    }
@@ -458,28 +438,26 @@
     * @param vhostNames Iterator<String> for the jboss-web/virtual-host elements 
     * @return Iterator<String> of the unique Host names
     * @throws Exception
-    */ 
-   protected synchronized Iterator mapVirtualHosts(Iterator vhostNames)
-      throws Exception
+    */
+   protected synchronized Iterator mapVirtualHosts(Iterator vhostNames) throws Exception
    {
-      if( vhostToHostNames.size() == 0 )
+      if (vhostToHostNames.size() == 0)
       {
          // Query the configured Host mbeans
          String hostQuery = config.getCatalinaDomain() + ":type=Host,*";
          ObjectName query = new ObjectName(hostQuery);
          Set hosts = server.queryNames(query, null);
          Iterator iter = hosts.iterator();
-         while( iter.hasNext() )
+         while (iter.hasNext())
          {
             ObjectName host = (ObjectName) iter.next();
             String name = host.getKeyProperty("host");
-            if( name != null )
+            if (name != null)
             {
                vhostToHostNames.put(name, name);
-                String[] aliases = (String[])
-                    server.invoke(host, "findAliases", null, null);
+               String[] aliases = (String[]) server.invoke(host, "findAliases", null, null);
                int count = aliases != null ? aliases.length : 0;
-               for(int n = 0;n < count; n ++)
+               for (int n = 0; n < count; n++)
                {
                   vhostToHostNames.put(aliases[n], name);
                }
@@ -489,13 +467,13 @@
 
       // Map the virtual host names to the hosts
       HashSet hosts = new HashSet();
-      while( vhostNames.hasNext() )
+      while (vhostNames.hasNext())
       {
          String vhost = (String) vhostNames.next();
          String host = (String) vhostToHostNames.get(vhost);
-         if( host == null )
+         if (host == null)
          {
-            log.warn("Failed to map vhost: "+vhost);
+            log.warn("Failed to map vhost: " + vhost);
             // This will cause a new host to be created
             host = vhost;
          }
@@ -512,7 +490,8 @@
       if (warURL.getProtocol().equals("file") && warFile.isDirectory() == true)
       {
          File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
-         if (webDD.exists() == true) result = webDD.getAbsolutePath();
+         if (webDD.exists() == true)
+            result = webDD.getAbsolutePath();
       }
       else
       {
@@ -537,17 +516,17 @@
       return result;
    }
 
-    private String shortWarUrlFromServerHome(String warUrl)
-    {
-        String serverHomeUrl =  System.getProperty(org.jboss.system.server.ServerConfig.SERVER_HOME_URL);
+   private String shortWarUrlFromServerHome(String warUrl)
+   {
+      String serverHomeUrl = System.getProperty(org.jboss.system.server.ServerConfig.SERVER_HOME_URL);
 
-        if (warUrl == null || serverHomeUrl == null)
-            return warUrl;
+      if (warUrl == null || serverHomeUrl == null)
+         return warUrl;
 
-        if (warUrl.startsWith(serverHomeUrl))
-          return ".../" + warUrl.substring(serverHomeUrl.length());
-        else
-          return warUrl;
+      if (warUrl.startsWith(serverHomeUrl))
+         return ".../" + warUrl.substring(serverHomeUrl.length());
+      else
+         return warUrl;
    }
 
 }




More information about the jboss-cvs-commits mailing list