Hello,

I wrote my own Connector for Tomcat which have to be registered on the
MbeanServer since version 4.1.
Without registration, Tomcat throw an Exception "ManagedBean is not found
..." and the MBeanServer is not available for the Tomcat Administration.
I tried to register the Connector using my own MBean description, but I
just get an MalformedObjectNameException in the Class
org.apache.catalina.mbeans.MBeanUtils, method createObjectName.

A closer look into the source code shows that only connector instances of
HttpConnector, org.apache.catalina.connector.http10.HttpConnector,
org.apache.ajp.tomcat4.Ajp13Connector and
org.apache.coyote.tomcat4.CoyoteConnector are supported. By all other
Connectors an Exception is thrown.

Am I right, it is not possible to register an another connector to the
MBeanServer ?

It would suffice first to look on the MBeanServer if an MBean already exist
for a Object, instead of always trying to create one.
In this case the connector could register himself on the MBeanServer.



    /**
     * Create an <code>ObjectName</code> for this
     * <code>Connector</code> object.
     *
     * @param domain Domain in which this name is to be created
     * @param connector The Connector to be named
     *
     * @exception MalformedObjectNameException if a name cannot be created
     */
    public static ObjectName createObjectName(String domain,
                                        Connector connector)
        throws MalformedObjectNameException {

        ObjectName name = null;
        if (connector instanceof HttpConnector) {
            HttpConnector httpConnector = (HttpConnector) connector;
            Service service = httpConnector.getService();
            String serviceName = null;
            if (service != null)
                serviceName = service.getName();
            name = new ObjectName(domain + ":type=Connector" +
                                  ",service=" + serviceName +
                                  ",port=" + httpConnector.getPort() +
                                  ",address=" + httpConnector.getAddress
());
            return (name);
        } else if (connector instanceof
org.apache.catalina.connector.http10.HttpConnector) {
            org.apache.catalina.connector.http10.HttpConnector
httpConnector =
                (org.apache.catalina.connector.http10.HttpConnector)
connector;
            Service service = httpConnector.getService();
            String serviceName = null;
            if (service != null)
                serviceName = service.getName();
            name = new ObjectName(domain + ":type=Connector" +
                                  ",service=" + serviceName+
                                  ",port=" + httpConnector.getPort() +
                                  ",address=" + httpConnector.getAddress
());
            return (name);
        } else if ("org.apache.ajp.tomcat4.Ajp13Connector".equals
                   (connector.getClass().getName())) {
            try {
                String address = (String)
                    PropertyUtils.getSimpleProperty(connector, "address");
                Integer port = (Integer)
                    PropertyUtils.getSimpleProperty(connector, "port");
                Service service = connector.getService();
                String serviceName = null;
                if (service != null)
                    serviceName = service.getName();
                name = new ObjectName(domain + ":type=Connector" +
                                      ",service=" + serviceName +
                                      ",port=" + port +
                                      ",address=" + address);
                return (name);
            } catch (Exception e) {
                throw new MalformedObjectNameException
                    ("Cannot create object name for " + connector+e);
            }
        } else if ("org.apache.coyote.tomcat4.CoyoteConnector".equals
                   (connector.getClass().getName())) {
            try {
                String address = (String)
                    PropertyUtils.getSimpleProperty(connector, "address");
                Integer port = (Integer)
                    PropertyUtils.getSimpleProperty(connector, "port");
                Service service = connector.getService();
                String serviceName = null;
                if (service != null)
                    serviceName = service.getName();
                name = new ObjectName(domain + ":type=Connector" +
                                      ",service=" + serviceName +
                                      ",port=" + port +
                                      ",address=" + address);
                return (name);
            } catch (Exception e) {
                throw new MalformedObjectNameException
                    ("Cannot create object name for " + connector+e);
            }
        } else {
            throw new MalformedObjectNameException
                ("Cannot create object name for " + connector);
        }

    }


Best regards
Arthur



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to