azerIO
azerIO

Reputation: 519

Get own IP address in a java class invoked by a Session Bean

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?

Upvotes: 1

Views: 696

Answers (2)

Arjan Tijms
Arjan Tijms

Reputation: 38163

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

E.g.

InetAddress host = InetAddress.getLocalHost();
byte[] rawIP = host.getAddress();
String name = host.getHostName();
// etc

Upvotes: 0

feniix
feniix

Reputation: 1628

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.

Upvotes: 2

Related Questions