views:

28

answers:

0

I'm attempting to programatically locate the virtual hostname for a J2EE servlet container.

In this enterprise environment, the logical URL consists of protocol://application.company.com/, which is translated to protocol://virtualhost.datacenter.company.com:port/context/.

Using ServletRequest.getServerName() gives me "application.company.com", whilst using InetAddress.getLocalHost() gives me "physicalhost.datacenter.company.com". [The other ServletRequest accessors aren't a problem.] Naturally, reconstructing a URL with "http://physicalhost.datacenter.company.com:port/context/" fails as there's no listener.
What can I use to retrieve "virtualhost.datacenter.company.com" from within the servlet code?

My preference is for a pure J2EE solution, but I can deal with a vendor-specific one. The environment is WebLogic 10.0MP1 using Java 1.5.0.11 on HP/UX 11.11. (Not by choice ;-)