Prepend
2006-01-19
  Host Header can be tricky on Oracle Application Server (Apache)
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.
 
Comments: Post a Comment



<< Home
Technical and personal notes from Brian Lee, technologist/enterprise architect/software developer/soa guy.

ARCHIVES
February 2005 / March 2005 / April 2005 / May 2005 / June 2005 / July 2005 / August 2005 / September 2005 / October 2005 / November 2005 / December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / May 2007 / June 2007 / August 2007 / September 2007 / October 2007 / April 2008 / July 2008 / January 2009 / May 2009 / June 2009 /
My Photo
Name: Brian Lee
Location: Atlanta, Georgia, United States

 
Web prepend.com






Powered by Blogger