{"id":162,"date":"2015-03-19T17:07:42","date_gmt":"2015-03-19T16:07:42","guid":{"rendered":"http:\/\/www.arensa.net\/?p=162"},"modified":"2015-03-19T17:10:31","modified_gmt":"2015-03-19T16:10:31","slug":"how-to-get-ip-address-and-port-in-jboss-as-7-1-programmatically","status":"publish","type":"post","link":"https:\/\/www.arensa.net\/?p=162","title":{"rendered":"How to get IP-address and port in JBoss AS 7.1 programmatically."},"content":{"rendered":"<p>This can be achieved using the MBeanServerConnection API and the correct node and attribute names within the JBoss configuration:<br \/>\n<code><br \/>\n\/\/ get an javax.management.MBeanServerConnection object<br \/>\nMBeanServerConnection mbServerConn = ManagementFactory.getPlatformMBeanServer();<br \/>\n\/\/ drill down to the 'http' node in the standard-socket-binding-group<br \/>\nObjectName nameSocket = new ObjectName(\"jboss.as:socket-binding-group=standard-sockets,socket-binding=http\");<br \/>\n\/\/ use the getAttribute()-method of the MBeanServerConnection object<br \/>\nString serverBase = \"http:\/\/\" + mbServerConn.getAttribute(nameSocket, \"bound-address\") + \":\" + mbServerConn.getAttribute(nameSocket, \"port\")+ \"\/\";<br \/>\n<\/code><\/p>\n<p>How to find out about the nodes and attribute names? The easiest way to achieve this, is to use the JBoss command line interface <code>jboss-cli.sh<\/code>. After you connected to the JBoss instance in question, use the <code>ls<\/code> command to find out about the nodes. You can use tab for autocompletion. Once you have found a leave, use the parameter <code>-l<\/code> for listing the attribute names:<\/p>\n<p><code><br \/>\nls socket-binding-group=standard-sockets<br \/>\nls socket-binding-group=standard-sockets\/socket-binding=http<br \/>\nls - socket-binding-group=standard-sockets\/socket-binding=http<br \/>\n<\/code> <\/p>\n<p>The last command results in<br \/>\n<code><br \/>\nATTRIBUTE         VALUE       TYPE<br \/>\nbound             true        BOOLEAN<br \/>\nbound-address     XX.YY.ZZ.WW STRING<br \/>\nbound-port        8080        INT<br \/>\nclient-mappings   undefined   LIST<br \/>\nfixed-port        false       BOOLEAN<br \/>\ninterface         undefined   STRING<br \/>\nmulticast-address undefined   STRING<br \/>\nmulticast-port    undefined   INT<br \/>\nname              http        STRING<br \/>\nport              8080        INT<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This can be achieved using the MBeanServerConnection API and the correct node and attribute names within the JBoss configuration: \/\/ get an javax.management.MBeanServerConnection object MBeanServerConnection mbServerConn = ManagementFactory.getPlatformMBeanServer(); \/\/ drill down to the &#8216;http&#8217; node in the standard-socket-binding-group ObjectName nameSocket = new ObjectName(&#8220;jboss.as:socket-binding-group=standard-sockets,socket-binding=http&#8221;); \/\/ use the getAttribute()-method of the MBeanServerConnection object String serverBase = &#8220;http:\/\/&#8221; &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.arensa.net\/?p=162\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to get IP-address and port in JBoss AS 7.1 programmatically.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,13],"tags":[11,25],"_links":{"self":[{"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/posts\/162"}],"collection":[{"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.arensa.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=162"}],"version-history":[{"count":1,"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.arensa.net\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.arensa.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.arensa.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.arensa.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}