Hi all, I want to know all the aliases defined in <host> container in
server.xml of Tomcat 7.0.61

My server.xml has the following configuration:

..
<Service name="Catalina">

..
    <Engine defaultHost="localhost" name="Catalina">
..
      <Host appBase="webapps" autoDeploy="true" name="localhost"
unpackWARs="true">

        <alias>alias1.server</alias>
        <alias>alias2.server</alias>
        <alias>alias3.server</alias>
        <alias>alias4.server</alias>

..
      <Context docBase="XXXX" path="/XXX" reloadable="true"
source="org.eclipse.jst.jee.server:CrystalReportWeb"/></Host>
    </Engine>
  </Service>
..

I want to retrieve all this posibles "alias" defined in host contanier.

I use the following code:

        Server servidorTomcat = null;

        MBeanServer mBeanServer =
MBeanServerFactory.findMBeanServer(null).get(0);
        ObjectName catalinaNombre = null;
        ObjectName hostNombre = null;
        try {
            catalinaNombre = new ObjectName("Catalina","type","Server");

        } catch (MalformedObjectNameException e) {
            this.error = true;
            this.errorDescripcion = "'MalformedObjectNameException' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        } catch (Exception e) {
            this.error = true;
            this.errorDescripcion = "'Exception' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        }

        try {
            servidorTomcat = (Server) mBeanServer.getAttribute(
catalinaNombre, "managedResource");
            StandardEngine engineTomcat = (StandardEngine)
servidorTomcat.findService("Catalina").getContainer();
            Host hostTomcat = (Host) engineTomcat.findChild( "localhost" );
            String[] tomcat7HostAlias = hostTomcat.findAliases();
        } catch (AttributeNotFoundException e) {
            this.error = true;
            this.errorDescripcion = "'AttributeNotFoundException' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        } catch (InstanceNotFoundException e) {
            this.error = true;
            this.errorDescripcion = "'InstanceNotFoundException' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        } catch (MBeanException e) {
            this.error = true;
            this.errorDescripcion = "'MBeanException' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        } catch (ReflectionException e) {
            this.error = true;
            this.errorDescripcion = "'ReflectionException' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        } catch (Exception e) {
            this.error = true;
            this.errorDescripcion = "'Exception' en " +
                                    "Jsfthis.getTomcat7Servidor(). " +
                                    "Error: " + e.getMessage();
        }

Everythings seem to work fine, but String[] tomcat7HostAlias always returns
zero length array.

I don't know what i am doing wrong.

Please help.

Regads,


Mariano

Reply via email to