Search in sources :

Example 1 with MQRMIClientSocketFactory

use of com.sun.messaging.jmq.management.MQRMIClientSocketFactory in project openmq by eclipse-ee4j.

the class ConnectorServerInfo method initConnectorServer.

/*
     * Initialize the connector server. This method assumes the URL has been initialized.
     *
     * The following properties can be used to further configure the connector server: imq.jmx.connector.<connector server
     * name>.useSSL imq.jmx.connector.<connector server name>.brokerHostTrusted imq.jmx.connector.<connector server
     * name>.backlog
     *
     */
private void initConnectorServer() throws BrokerException {
    JMXConnectorServer cs;
    BrokerConfig config = Globals.getConfig();
    MBeanServer mbs = agent.getMBeanServer();
    HashMap env = new HashMap();
    boolean useSSL, brokerHostTrusted;
    String jmxHostname = Globals.getJMXHostname();
    int backlog;
    if (connectorServer != null) {
        return;
    }
    if (mbs == null) {
        throw new BrokerException(rb.getString(rb.X_JMX_CANT_CREATE_CONNECTOR_SVR, name));
    }
    useSSL = config.getBooleanProperty(CONNECTOR_PROPBASE + name + SSL_SUFFIX, false);
    /*
         * Query property that specifies if the broker is to be trusted. If this property is not set, by default the broker is
         * *not* trusted.
         */
    brokerHostTrusted = config.getBooleanProperty(CONNECTOR_PROPBASE + name + BROKER_HOST_TRUSTED_SUFFIX, false);
    backlog = config.getIntProperty(CONNECTOR_PROPBASE + name + BACKLOG_SUFFIX, 0);
    try {
        /*
             * We only support the RMI protocol in MQ 4.0
             */
        if (configuredURL.getProtocol().equals("rmi")) {
            boolean useAuth = true;
            if (useAuth) {
                env.put(JMXConnectorServer.AUTHENTICATOR, new MQJMXAuthenticator(this));
            }
            /*
                 * Use MQ specific server socket factory only if: - SSL is enabled - need to specify a specific host/IP on a multihome
                 * system
                 */
            if ((useSSL) || (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL))) {
                MQRMIServerSocketFactory ssf = new MQRMIServerSocketFactory(jmxHostname, backlog, useSSL);
                env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
            }
            /*
                 * Use MQ specific client socket factory only if: - need to specify a specific host/IP on a multihome system
                 */
            if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
                MQRMIClientSocketFactory csf = new MQRMIClientSocketFactory(jmxHostname, brokerHostTrusted, useSSL);
                env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
                if ((Globals.isJMSRAManagedBroker() || Globals.isNucleusManagedBroker()) && agent.useRmiRegistry()) {
                    env.put("com.sun.jndi.rmi.factory.socket", csf);
                }
            } else {
                /*
                     * Use MQ specific client socket factory only if: - SSL is enabled and brokerHostTrusted is true If brokerHostTrusted is
                     * false, use the JDK provided javax.rmi.ssl.SslRMIClientSocketFactory
                     */
                if (useSSL) {
                    if (brokerHostTrusted) {
                        MQRMIClientSocketFactory csf = new MQRMIClientSocketFactory(jmxHostname, brokerHostTrusted, useSSL);
                        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
                    } else {
                        javax.rmi.ssl.SslRMIClientSocketFactory sslcf = new javax.rmi.ssl.SslRMIClientSocketFactory();
                        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, sslcf);
                        if ((Globals.isJMSRAManagedBroker() || Globals.isNucleusManagedBroker()) && agent.useRmiRegistry()) {
                            env.put("com.sun.jndi.rmi.factory.socket", sslcf);
                        }
                    }
                }
            }
        }
        cs = JMXConnectorServerFactory.newJMXConnectorServer(configuredURL, env, mbs);
    } catch (Exception e) {
        throw new BrokerException(rb.getString(rb.W_JMX_ERROR_CREATING_CONNECTOR, name), e);
    }
    cs.addNotificationListener(listener, null, this);
    connectorServer = cs;
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) MalformedURLException(java.net.MalformedURLException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) IOException(java.io.IOException) MQRMIClientSocketFactory(com.sun.messaging.jmq.management.MQRMIClientSocketFactory)

Aggregations

BrokerConfig (com.sun.messaging.jmq.jmsserver.config.BrokerConfig)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 MQRMIClientSocketFactory (com.sun.messaging.jmq.management.MQRMIClientSocketFactory)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1