I end up creating a bunch of j2ee apps that run on Oracle Application Server (OAS). When writing servlets/jsps it is frequently useful to get the URL or server name where the app is running. According to the java docs for HttpServletRequest, there are a couple of useful messages to get this info. I usually stick to getServerName for just the host name or getRequestURL for the full url (getRequestURI will have this info in a GET request). Both of these methods get their info from the HTTP Host header.

The trickiness comes with Apache, because no matter what the browser sends in the Host header, it replaces the host portion with the configured serverName. So if you pass:
Host: foo.bar.baz.com:8888
but if Apache has "foo" in the httpd.conf, Apache will change the header to have
Host: foo:8888

The way this came to my attention is when a customer reported some of our site wasn't working. The url being used by the component was "http://serverName:8888/whateverUrlIs.do?foo=blargh" even though if you looked at the browser, the address is "http://serverName.fullhost.fulldomain.com:8888/whateverUrlIs.do?foo=blargh". This was a bit of pain as nowhere in our code were we shortening the host name. It ended up that OAS was installed with just the host name rather than the full host name.

OAS doesn't let you change the server name through a nice gui, but it is easy enough to edit the httpd.conf file through the advanced pane or directly in the file system.

So I wonder: why does OAS/Apache change the passed HTTP headers? This makes debugging a real pain. So now, one of my first debugging steps is running the app in jboss, oc4j or websphere to make sure the app server isn't doing something weird to the request. I had similar headaches with WebSphere on AIX/zOS not liking the Content-Type header with my SOAP requests.