Question : retrieving JNDI port in code

Hi,

I wondered, can I retrieve the actual configured JNDI listening port for JBoss in my code (running on JBoss ofcourse). The port is set in jboss-service.xml on the NamingService MBean. So I need that Port value in my code.

Thanks!

Answer : retrieving JNDI port in code

you can use JMX for mbean invocation.


Get the MBeanServer like this:

MBeanServer mbeanServer =
(MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next();

Create an ObjectName for your MBean like this:
ObjectName objectName = new ObjectName(":e>");

e.g. ObjectName objectName = new ObjectName("com.example:service=myservice");
Check the JMX Console for the name of your MBean.
Then, invoke methods against your mbean as follows:

mbeanServer.invoke(objectName, "",  new Object[]{}, new String[]{}  );

Random Solutions  
 
programming4us programming4us