2

I have following (simplified) setup.

Setup

From the client I call http://somedomain.com/my.jsp via the proxy it's forwarded to apache 1 or apache 2

In my jsp I want the server1-domain.com or server2-domain.com and not somedomain.com

request.getServerName() gives me somedomain.com in the header the 'Host' param is also somedomain.com

It seems similar but just the opposite to: tomcat-getheaderhost-vs-getservername

But I cannot turn of 'ProxyPreserveHost' as I am not the only one on the cluster... Optimal solution is not having to change anything to the domaincontroller/loadbalancer/apaches

Can I get it via just a JSP method/param?

Community
  • 1
  • 1
VDP
  • 6,340
  • 4
  • 31
  • 53
  • 1
    Have you tried X-Forwarded headers, like X-Forwarded-For or X-Forwarded-Host? – andrucz Dec 09 '15 at 12:57
  • Take a look at http://stackoverflow.com/questions/10407203/tomcat-getheaderhost-vs-getservername – andrucz Dec 09 '15 at 13:21
  • Nope don't have the X-Forwarded headers.. I'm going to try this now: `String hostname = InetAddress.getLocalHost().getHostName();`. Looks promising in the the spring controller (tested locally). I'm still building and deploying on the clustered development environment.. – VDP Dec 09 '15 at 13:36
  • 1
    @andrucz you linked to the same question I refer to in my question... :-) – VDP Dec 09 '15 at 13:37
  • 1
    My bad. I didn't read your question completely :) – andrucz Dec 09 '15 at 14:28

1 Answers1

2

I ended up using this:

String hostname = InetAddress.getLocalHost().getHostName();

VDP
  • 6,340
  • 4
  • 31
  • 53