how to create groovy client? getting an error, below.

**

start up jboss with following paremater:

**

set JAVA_OPTS= -Djava.rmi.server.hostname=localhost
               -Dcom.sun.management.jmxremote.ssl=false
               -Dcom.sun.management.jmxremote.authenticate=true
               -Dcom.sun.management.jmxremote.password.file=C:\Java\jdk1.7.0\jre\lib\management\jmxremote.password
               -Dcom.sun.management.jmxremote.access.file=C:\Java\jdk1.7.0\jre\lib\management\jmxremote.access"

**

test jboss is started:

**

http://localhost:9990/
username: abc
password: abc1#

**

Groovy script:

**

import javax.management.ObjectName
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
import groovy.swing.SwingBuilder
import javax.swing.WindowConstants as WC


// Connect to server
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:9990/jmxrmi'
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def serverInfo = new GroovyMBean(server, 'Catalina:type=Server').serverInfo
println "Connected to: $serverInfo"

**

Error:

**

Exception thrown

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
    java.net.SocketTimeoutException: Read timed out]
    at jmxClient.run(jmxClient.groovy:10)

Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
    java.net.SocketTimeoutException: Read timed out]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
    ... 1 more

Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
    java.net.SocketTimeoutException: Read timed out
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:114)
    ... 2 more


Caused by: java.net.SocketTimeoutException: Read timed out
    ... 3 more

Dani AI

Generated

Short diagnosis and what happened in this thread: was right — the management HTTP endpoint and a native RMI JMX endpoint are different things — and discovered the RMI connector itself wasn’t running. WildFly/JBoss (standalone mode) exposes JMX via the Remoting/management endpoint (the management port is used by default), not the classic JVM RMI registry unless you explicitly enable the JVM agent. (docs.jboss.org)

If the server is WildFly / AS7+ (management console on 9990), use the server’s remoting JMX connector and the remoting-style service URL rather than the plain RMI registry URL. Also run your Groovy client with the WildFly/JBoss client jar(s) on the classpath (jboss-client/jboss-cli-client or wildfly-client-all) and pass the management credentials in the connector environment. Example Groovy pattern (adjust username/password and classpath to include the server client jar):

import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL
import javax.management.remote.JMXConnector

def url = 'service:jmx:remote+http://localhost:9990'
def env = [(JMXConnector.CREDENTIALS): ['MGMT_USER','MGMT_PASS'] as Object[]]
def connector = JMXConnectorFactory.connect(new JMXServiceURL(url), env)
def mbsc = connector.getMBeanServerConnection()
println "MBean count: ${mbsc.getMBeanCount()}"
connector.close()

WildFly docs show the remote+http / http-remoting-jmx URLs and explain the classpath requirement for client tools. (docs.jboss.org)

If instead you want the JVM’s built-in RMI JMX agent (classic com.sun.management JMX), enable it in the server start options by setting the agent port(s) and hostname (for example, com.sun.management.jmxremote.port and com.sun.management.jmxremote.rmi.port plus java.rmi.server.hostname). That publishes a standard jmxrmi entry you can connect to, but it must be started explicitly and is subject to firewall and security settings. (docs.oracle.com)

Quick checklist to resolve timeouts: confirm the exact JBoss/WildFly version; pick remoting-JMX (preferred for AS7+/WildFly) or JVM RMI agent; ensure the correct service URL and client jars on the Groovy classpath; create a management user using add-user(.bat) if using the management endpoint; and make sure the management interface is bound to the desired address (use -bmanagement or edit interfaces). Also verify firewall/port access. (docs.wildfly.org)

Relevant docs: WildFly JMX subsystem, Oracle JMX agent properties, WildFly add-user and bind-address notes (see cited sources above).

Recommended Answers

All 2 Replies

it seems that you're trying to connect on the http port of your jboss, instead of rmi connection ?

by default, rmi binds on port 1099.

maybe you should try

def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost/jmxrmi'
commented: thanks alot for getting back to me +3

i think I found the problem. i have start up JBoss but I never start rmi server. Do you have any idea's how can I start rmi using JBOSS in window?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.