Saturday, February 16, 2008

GoDaddy as a trusted certificate authority

GoDaddy has not as of yet ascended to the ranks of a default trusted certificate authority in the Java Security code. You have to make this happen manually.

I was getting an exception when attempting to consume a web service over SSL. Here is the exception:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Message: ; nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

The fix for this problem was to add GoDaddy as a trusted CA. Here are the steps I took:

1. Download gd_intermediate.cer from here.
2. I put this file in %JAVA_HOME%\jre\lib\security. You can put it anywhere you want.
3. Run the following command at a command prompt:

C:\Program Files\Java\jre1.6.0_02\bin>keytool -import -trustcacerts -alias godaddy-cert -keystore ..\lib\security\cacerts -file ..\lib\security\gd_intermediate.cer

4. You will be prompted for a password. If you have not changed the password, it will be "changeit".
5. You will then get the following message if all is successful - "Certificate was added to keystore".
6. Restart Tomcat.

Wednesday, February 06, 2008

Monitor MySQL and restart it if it has stopped

I had a need to monitor a MySQL database instance running as a Windows service and then restart it if for whatever reason it had stopped or died unexpectedly. From within my java web application, I created a Quartz job and scheduled it to run once per minute. I manually set the connection timeout to 10 seconds for the jdbc driver so as not to have to wait 30+ seconds if the MySQL instance were down. Here is the code that runs as part of the Quartz job:

Connection con = null;
try {
  DriverManager.setLoginTimeout(10);
  class.forName("com.mysql.jdbc.Driver");
  con = DriverManager.getConnection("jdbc:mysql://[server]:[port]/[dbname]", "[db user]", "[password]");
  // If we did not get a connection, the db must be down. Start it up again.
  if (con == null) {
    Runtime rt = Runtime.getRuntime();
    try {
      rt.exec("net start mysql");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
} catch (Exception e) {
  // If we did not get a connection and an exception is thrown, the db must
  // be down. Start it up again.
  if (con == null) {
    Runtime rt = Runtime.getRuntime();
    try {
      rt.exec("net start mysql");
    } catch (IOException e2) {
      e2.printStackTrace();
    }
  }
  e.printStackTrace();
} finally {
  // Clean up.
  try {
    if (con != null) {
      con.close();
    }
  } catch (SQLException ignored) {
  
}


This will only work if the instance of MySQL is running on the same box as the java web application. Also, the "mysql" in the command "net start mysql" is the name of the Windows service that I am wanting to start. One last thing, in my case the java web application was running under Tomcat. I had to make sure that the Tomcat Windows service was started with the same Windows account as the MySQL Windows service.

If you have better ways of doing something like this, please share.

HelpMeFinancial.com

We are designing a new financial portal HelpMeFinancial.com. It will be a place where we can use all of our calculator and article content, as well as other financial related information. The plan is to be "live" sometime in Q1 of this year. We plan on making it an ad-driven portal as well.

There are numerous financial portals on the internet. Our "edge" will be that this site will be centered around our expertise - FINANCIAL CALCULATORS. Whenever anyone needs a calculator, they can come to helpmefinancial.com and easily find the one they need. We will make it easy to understand and interpret the results. We will provide links to similar calculators or other calculators that may be able to provide additional information.

The site will be available in English and Spanish.

Friday, January 11, 2008

Testing of financial calculators in a blog

I wanted to try out some new "blogger-friendly" financial calculators available at CalcXML.com. For example, here is the Loan Payment calculator.