1

Suppose I have a statefull session bean B, which creates some POJO A. How can I inside one of the A's methods obtain the IP(and hostname) of the Java EE server which manages the session bean B?

PS. If this is not possible, then how could I do the same in B itself?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
azerIO
  • 519
  • 1
  • 9
  • 19

2 Answers2

2

In jboss 7 (as well as all the other jboss servers at least from 4.x on).

You have a property file that holds the bind ip.

I think in jboss 7.1 is called:

jboss.bind.address

And in theory can be accessed by using System.getProperty

Regards

PS: Needless to say, this is always local to the jvm, so no remote invocation unless you provide some sort of api for it, or the jboss folks already build a remote api for this.

feniix
  • 1,558
  • 2
  • 21
  • 35
  • When bound to 0.0.0.0 it will output exactly that value (i.e. if I run the server using ./standalone -b 0.0.0.0) + it is J2EE server specific. – azerIO Mar 28 '12 at 08:28
  • I tend to bind to specific IPs in the box (that are also not the primary IP of the box) I do not like using port offsets. – feniix Mar 28 '12 at 14:19
0

You could use java.net.InetAddress#getLocalHost for this.

E.g.

InetAddress host = InetAddress.getLocalHost();
byte[] rawIP = host.getAddress();
String name = host.getHostName();
// etc
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Nope, there might be several interfaces with several IPs on the machine. How should I know that a given IP is the one my J2EE server listens on? – azerIO Apr 04 '12 at 09:48