0

How could I get from a java class the port where my application? For example, with JBoss in standalone.xml I used it is:

standalone.xml

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}" />
        <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}" />
        <socket-binding name="ajp" port="${jboss.ajp.port:8009}" />
        <socket-binding name="http" port="${jboss.http.port:8080}" />
        <socket-binding name="https" port="${jboss.https.port:8443}" />
        <socket-binding name="txn-recovery-environment" port="4712" />
        <socket-binding name="txn-status-manager" port="4713" />
        <outbound-socket-binding name="mail-smtp">
            <remote-destination host="localhost" port="25" />
        </outbound-socket-binding>
    </socket-binding-group>

Java class:

 Integer port = (Integer) ManagementFactory.getPlatformMBeanServer()
                .getAttribute(new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http"),
                    "port");
Carbomax
  • 23
  • 1
  • 4
  • Do you have the `jmx` and `management` fractions? Both might be necessary (not 100% sure if having only 1 of them will suffice.) Alternatively, you can try reading the system property `thorntail.http.port`. – Ladicek Jan 03 '20 at 16:25
  • I try with: io.thorntail jmx io.thorntail management but not working. And I tested too: System.getenv("thorntail.http.port"); and not working – Carbomax Jan 03 '20 at 18:30
  • Weird, adding `jmx` should expose the WildFly MBean server. Can you try connecting to running Thorntail application with `jconsole` and see the MBeans? And it's not `System.getenv`, it's `System.getProperty`. – Ladicek Jan 03 '20 at 19:27
  • For me, It definitely does not work. If I find the solution, I shared it. – Carbomax Jan 04 '20 at 14:11

0 Answers0