Peter Penzov
Peter Penzov

Reputation: 1688

java.net.MalformedURLException: Unsupported protocol: remoting-jmx

I want to use Java client with JBoss 6.4.0 EAP. I tested this code:

public void testConnection() throws Exception
    {

        System.out.println("Starting lookup ...");

        ObjectName mBeanName = new ObjectName("java.lang:type=Runtime");
        String attributeName = "StartTime";

        String host = "104.233.103.41";
        int port = 9999;  // management-native port

        String urlString = System.getProperty("jmx.service.url", "service:jmx:remoting-jmx://" + host + ":" + port);
        JMXServiceURL serviceURL = new JMXServiceURL(urlString);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
        MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

        Object attrVal = connection.getAttribute(mBeanName, attributeName);
        System.out.println("Value via JMX: " + new Date((Long) attrVal));

    }

My project is Maven based so I added these dependencies:

   <dependencies>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-ejb-client-bom</artifactId>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-jms-client-bom</artifactId>
            <type>pom</type>
        </dependency>
    </dependencies>

But I get this error when I run the code:

java.net.MalformedURLException: Unsupported protocol: remoting-jmx
    at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:359)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:269)

Into EAP-6.4.0/bin/client I found this description:

jboss-client.jar is a combined client jar for JBoss EAP 6, for use in non-maven environments. This jar should be used with standalone clients only, not with deployments are that deployed to an JBoss EAP 6 instance.

This jar contains the classes required for remote JMS and EJB usage, and consists of the following shaded artifacts:

org.jboss.spec.javax.jms:jboss-jms-api_1.1_spec
org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec
org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec

org.jboss:jboss-ejb-client
org.jboss:jboss-remote-naming
org.jboss.logging:jboss-logging
org.jboss.marshalling:jboss-marshalling
org.jboss.marshalling:jboss-marshalling-river
org.jboss.remoting3:jboss-remoting
org.jboss.remoting3:remoting-jmx
org.jboss.sasl:jboss-sasl
org.jboss.xnio:xnio-api
org.jboss.xnio:xnio-nio
org.jboss.netty:netty
org.hornetq:hornetq-core-client
org.hornetq:hornetq-jms-client

Maven users should not use this jar, but should use the following BOM dependencies instead

<dependencies>
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-jms-client-bom</artifactId>
        <type>pom</type>
    </dependency>
</dependencies>

This is because using maven with a shaded jar has a very high chance of causing class version conflicts, which is why we do not publish this jar to the maven repository.

But again i get this error. Can you propose some solution?

Upvotes: 1

Views: 7486

Answers (1)

shonky linux user
shonky linux user

Reputation: 6428

Add a dependency to the remoting-jmx protocol, i.e. org.jboss.remoting3:remoting-jmx as per https://developer.jboss.org/thread/199914?tstart=0

<dependency>
    <groupId>org.jboss.remoting3</groupId>
    <artifactId>remoting-jmx</artifactId>
    <version>1.0.1.Final</version>
</dependency>

A complete and working POM :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-ejb-client-bom</artifactId>
            <type>pom</type>
            <version>7.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-jms-client-bom</artifactId>
            <type>pom</type>
            <version>7.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.remoting3</groupId>
            <artifactId>remoting-jmx</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Running the maven build with a JBoss server running on local host:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running test.ATest
Starting lookup ...
Dec 16, 2015 6:25:50 PM org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.7.GA
Dec 16, 2015 6:25:50 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.7.GA
Dec 16, 2015 6:25:50 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.14.GA
Value via JMX: Wed Dec 16 18:14:05 CST 2015
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.89 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Upvotes: 5

Related Questions