How would one find out the jboss port programatically within application/war that is deployed on that jboss server? Using Java
It is a web service running, we don't have any user interface
JBoss is a division of Red Hat that provides support for the WildFly open source Application Server program (formerly called JBoss AS) and related middleware services. JBoss is an open source alternative to commercial offerings from IBM WebSphere and SAP NetWeaver.
When the JBoss Enterprise Application Platform server is running you can retrieve its version information from the first page of the Web Console. This is located at http://localhost:8080/web-console/.
We've Moved! The JBoss AS community project has been renamed to the WildFly community project, which has a new home at wildfly.org. The JBoss name now only applies to the commercially supported product, called JBoss EAP, which is derived from the WildFly community project and is available here.
JBoss Application Server (JBoss AS) is an open-source, cross-platform Java application server developed by JBoss, a division of Red Hat Inc. JBoss AS is an open-source implementation of Java 2 Enterprise Edition (J2EE) that is used for implementing Java applications and other Web-based applications and software.
I am assuming you want the HTTP port.
JBoss publishes a Tomcat connector MBean for each web listener. The naming convention of the mbeans' ObjectNames is:
The trick is, without making any assumptions about the bind address or port (the bind address could be 127.0.0.1, or 0.0.0.0 or a host name), finding the correct MBean. To do this, you can use a JMX Query that specifies:
Once you have an MBeanServerConnection to the JBoss MBeanServer, this statement will return the correct port:
String port = server.queryNames(
new ObjectName("jboss.web:type=Connector,address=*,port=*"),
Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")))
.iterator().next().getKeyProperty("port");
If you are attempting to determine the port from code running inside the JBoss JVM, acquiring the MBeanServerConnection is trivial since you can make a static call to org.jboss.mx.util.MBeanServerLocator.locateJBoss().
Here is an example of a simple JSP to print the HTTP port number:
<%@page contentType="text/html" import="java.util.*,org.jboss.mx.util.*,javax.management.*" %>
<html><head><title>JBoss Web Server Port</title></head><body>
<%
try {
MBeanServerConnection server = MBeanServerLocator.locateJBoss();
String port = server.queryNames(
new ObjectName("jboss.web:type=Connector,address=*,port=*"),
Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")))
.iterator().next().getKeyProperty("port");
out.println("<p>Port:" + port + "</p>");
} catch (Exception e) {
e.printStackTrace(System.err);
}
%></body></html>
If you need to acquire this remotely, you need to use the JBoss client RMIAdaptor. The reference provided by Nayan Wadekar is a good example of how to do this.
If your JBoss server has a org.jboss.mx.remoting.service.JMXConnectorServerService deployed or you are running JBoss using the platform MBeanServer, you can also use the native JMX remoting. Here's a Groovy example of that:
import javax.management.*;
import javax.management.remote.*;
conn = null;
try {
url = new JMXServiceURL("service:jmx:rmi://njw810/jndi/rmi://njw810:1090/jmxconnector");
conn = JMXConnectorFactory.connect(url);
server = conn.getMBeanServerConnection();
objectName = new ObjectName("jboss.web:type=Connector,address=*,port=*"); // HTTP/1.1
println server.queryNames(objectName, Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))).iterator().next().getKeyProperty("port");
} finally {
try { conn.close(); println "Connection Closed"; } catch (Exception e) {}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With