Sunday, February 9, 2014

Tomcat 6 returns null on getLocalAddr() from HTTPRequest.

Tomcat prior to version 6.0.29 has a bug in method getLocalAddr() which returns null instead of the IP Address of the Local Server.

The issue is described here

Tuesday, March 12, 2013

HTTPS on Tomcat 7 deployed on EC2

Recently, I was asked to enable SSL/HTTPS on tomcat7 for a POC which was deployed on EC2. Since I had never done it before it was a nice thing to learn.

I followed the below steps to achieve it:
  • Generate Key store file - I used the keytool present in the jre/bin to generate a self-signed certificate by running 
keytool -genkey -alias Tomcat7 -keyalg RSA -keystore c:\.keystore
After running the command, I had to answer a bunch of questions (below) which i really didn't pay much attention except the password.

  • Modify Connector in tomcat's server.xml - The connector tag for https was already present in server.xml, I just had to uncomment it and add the keystorePass which was the password that i used while creating the keystore file. 
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true" clientAuth="false"
    sslProtocol="TLS" keystorePass="password"/>
  • Test - I opened a browser and ran https://localhost:8443/project which showed me not trusted page, which was expected for a self-signed certificate. 
I thought i was done. But, I found out the next day that it was not working from other systems.

The reason was EC2 is configured to run on port 443 by default, after the connector port was changed from 8443 to 443 it started working.