Hi,
I try to find the host name and port of my server something like, if JBoss is installed localy: hostname: localhost, port:8080.
My JBoss version is: 7.1.1.Final
I try this code and it doesn't work:
private static MBeanServer getMBeanServer() { for(MBeanServer server: javax.management.MBeanServerFactory.findMBeanServer(null)) { if("DefaultDomain".equals(server.getDefaultDomain())) return server; } return null; } public static String getHostName() { String hostName = null; MBeanServer server = getMBeanServer(); try { hostName = server.queryNames(new ObjectName("jboss.web:type=Connector,address=*,port=*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))) .iterator().next().getKeyProperty("address"); } catch (MalformedObjectNameException e) { e.printStackTrace(); } }
it doesn't work, I get this error:
java.util.NoSuchElementException
java.util.HashMap$HashIterator.nextEntry(HashMap.java:897)
java.util.HashMap$KeyIterator.next(HashMap.java:928)
h2o.aidaneo.fileimport.jcr.services.util.PropertiesUtil.getHostName(PropertiesUtil.java:37):
line error (37):
hostName = server.queryNames(new ObjectName("jboss.web:type=Connector,address=*,port=*"),
Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")))
.iterator().next().getKeyProperty("address");
Has somebody an idee how to do this?
Thanks,
Radouane