Example usage for javax.management.remote JMXConnectorFactory PROTOCOL_PROVIDER_PACKAGES

List of usage examples for javax.management.remote JMXConnectorFactory PROTOCOL_PROVIDER_PACKAGES

Introduction

In this page you can find the example usage for javax.management.remote JMXConnectorFactory PROTOCOL_PROVIDER_PACKAGES.

Prototype

String PROTOCOL_PROVIDER_PACKAGES

To view the source code for javax.management.remote JMXConnectorFactory PROTOCOL_PROVIDER_PACKAGES.

Click Source Link

Document

Name of the attribute that specifies the provider packages that are consulted when looking for the handler for a protocol.

Usage

From source file:com.ibm.soatf.component.osb.ServiceManager.java

public static JMXConnector initConnection(String hostName, int port, String userName, String password)
        throws MalformedURLException, IOException {

    JMXServiceURL serviceUrl = new JMXServiceURL(DEFAULT_PROTO, hostName, port,
            JNDI_PREFIX + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME);
    HashMap<String, String> h = new HashMap<String, String>();
    h.put(Context.SECURITY_PRINCIPAL, userName);
    h.put(Context.SECURITY_CREDENTIALS, password);
    h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, DEFAULT_PROTO_PROVIDER_PACKAGES);
    return JMXConnectorFactory.connect(serviceUrl, h);

}

From source file:com.zabbix.gateway.JMXItemChecker.java

public JMXItemChecker(JSONObject request) throws ZabbixException {
    super(request);

    try {//  w ww. ja v  a2s . co  m
        String conn = request.getString(JSON_TAG_CONN);
        int port = request.getInt(JSON_TAG_PORT);

        jmxc = null;
        mbsc = null;
        String jmx_url = "service:jmx:rmi:///jndi/rmi://[" + conn + "]:" + port + "/jmxrmi"; // default
        String jboss_url = "service:jmx:remoting-jmx://" + conn + ":" + port; // jboss
        String t3_url = "service:jmx:t3://" + conn + ":" + port
                + "/jndi/weblogic.management.mbeanservers.runtime"; // T3
        String t3s_url = "service:jmx:t3s://" + conn + ":" + port
                + "/jndi/weblogic.management.mbeanservers.runtime"; // T3S
        protocol = "jmx";
        String tested_url = jmx_url;

        username = request.optString(JSON_TAG_USERNAME, null);
        password = request.optString(JSON_TAG_PASSWORD, null);

        //if (null != username && null == password || null == username && null != password)
        //   throw new IllegalArgumentException("invalid username and password nullness combination");

        if (null != username) {
            // Testing if username is like "<user>:<protocol>"
            int protocol_in_username = username.indexOf(':');
            if (protocol_in_username != -1) {
                String result[] = username.split(":");
                username = result[0];
                protocol = result[1];
            }
        }

        switch (protocol) {
        case "jmx":
        case "jmxs":
            tested_url = jmx_url;
            break;
        case "jboss":
            tested_url = jboss_url;
            break;
        case "t3":
            tested_url = t3_url;
            break;
        case "t3s":
            tested_url = t3s_url;
            break;
        default:
            tested_url = jmx_url;
            break;
        }

        logger.info("Using url '{}' with user '{}'", tested_url, username);

        HashMap<String, Object> env = new HashMap<String, Object>();
        env.put(JMXConnector.CREDENTIALS, new String[] { username, password });

        if (protocol.equals("t3") || protocol.equals("t3s")) {
            env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, ((String[]) env.get(JMXConnector.CREDENTIALS))[0]);
            env.put(javax.naming.Context.SECURITY_CREDENTIALS,
                    ((String[]) env.get(JMXConnector.CREDENTIALS))[1]);
        }

        // Required by SSL
        if (protocol.equals("jmxs")) {
            env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
        }

        url = new JMXServiceURL(tested_url);
        jmxc = ZabbixJMXConnectorFactory.connect(url, env);
        mbsc = jmxc.getMBeanServerConnection();
    } catch (Exception e) {
        throw new ZabbixException(e);
    } finally {
        try {
            if (null != jmxc)
                jmxc.close();
        } catch (java.io.IOException exception) {
        }

        jmxc = null;
        mbsc = null;
    }
}

From source file:com.zabbix.gateway.JMXItemChecker.java

@Override
public JSONArray getValues() throws ZabbixException {
    JSONArray values = new JSONArray();

    try {//  www .java 2s.c o m

        HashMap<String, Object> env = null;

        env = new HashMap<String, Object>();
        env.put(JMXConnector.CREDENTIALS, new String[] { username, password });

        if (protocol.equals("t3") || protocol.equals("t3s")) {
            env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, ((String[]) env.get(JMXConnector.CREDENTIALS))[0]);
            env.put(javax.naming.Context.SECURITY_CREDENTIALS,
                    ((String[]) env.get(JMXConnector.CREDENTIALS))[1]);
        }

        // Required by SSL
        if (protocol.equals("jmxs")) {
            env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
        }

        jmxc = ZabbixJMXConnectorFactory.connect(url, env);
        mbsc = jmxc.getMBeanServerConnection();

        for (String key : keys)
            values.put(getJSONValue(key));
    } catch (Exception e) {
        throw new ZabbixException(e);
    } finally {
        try {
            if (null != jmxc)
                jmxc.close();
        } catch (java.io.IOException exception) {
        }

        jmxc = null;
        mbsc = null;
    }

    return values;
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

public static JMXConnector getMBeanConnector(Properties config) throws MalformedURLException, IOException {

    String jmxUrl = config.getProperty(MxUtil.PROP_JMX_URL);
    Map map = new HashMap();

    String user = config.getProperty(PROP_JMX_USERNAME);
    String pass = config.getProperty(PROP_JMX_PASSWORD);

    map.put(JMXConnector.CREDENTIALS, new String[] { user, pass });

    // required for Oracle AS
    String providerPackages = config.getProperty(PROP_JMX_PROVIDER_PKGS);
    if (providerPackages != null)
        map.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, providerPackages);

    if (jmxUrl == null) {
        throw new MalformedURLException(PROP_JMX_URL + "==null");
    }/*from  www.  ja  va  2 s . c om*/

    if (jmxUrl.startsWith(PTQL_PREFIX)) {
        jmxUrl = getUrlFromPid(jmxUrl.substring(PTQL_PREFIX.length()));
    }

    JMXServiceURL url = new JMXServiceURL(jmxUrl);

    String proto = url.getProtocol();
    if (proto.equals("t3") || proto.equals("t3s")) {
        //http://edocs.bea.com/wls/docs92/jmx/accessWLS.html
        //WebLogic support, requires:
        //cp $WLS_HOME/server/lib/wljmxclient.jar pdk/lib/
        //cp $WLS_HOME/server/lib/wlclient.jar pdk/lib/
        map.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
        map.put(Context.SECURITY_PRINCIPAL, user);
        map.put(Context.SECURITY_CREDENTIALS, pass);
    }

    JMXConnector connector = JMXConnectorFactory.connect(url, map);
    if (log.isDebugEnabled()) {
        log.debug("created new JMXConnector url=" + url + ", classloader="
                + Thread.currentThread().getContextClassLoader());
    }
    return connector;
}