Tuesday, 21 September 2010

keepass and dropbox combined.

A while ago I blogged about using keepass as a secure password & data storage tool.
The blog entry is here.

The issue I have always had is keeping the keepass db in sync between my different PCs at work & at home and on the move. I used to use a memory stick but decided that was prone to getting lost or damaged.

I have recently started using dropbox. This tool provides online storage allowing sync between any number of devices and supports linux, i-phones, android, iPad as well as Microsoft platforms. It is free for the first 2GB and you get to earn additional storage by either nominating others or getting nominated by an existing member.

From the reviews I have read it appears secure so I have started using it for my keepass database as well as any every day stuff I want to share.

As for reviewing keepass I am still very pleased and impressed with it.
My family now all have their own keepass databases to keep their personal data.

So if you want to try dropbox, follow this referral link and try it out.


Thursday, 16 September 2010

tomcat IE and parse locale Exceptions

I have just done an upgrade for a customer that involved new java, tomcat as well as a new version of our application software.


The webapp was failing with the following Exception:


Caused by: javax.servlet.jsp.JspException: In <parseNumber>, a parse locale can not be established
at org.apache.taglibs.standard.tag.common.fmt.ParseNumberSupport.doEndTag(ParseNumberSupport.java:134)
at org.apache.jsp.tag.web.shared.paging_tag._jspx_meth_fmt_005fparseNumber_005f0(paging_tag.java:598)
at org.apache.jsp.tag.web.shared.paging_tag.doTag(paging_tag.java:241)
at org.apache.jsp.pages.jsp.type3Footer_jsp._jspx_meth_tag_005fpaging_005f0(type3Footer_jsp.java:220)
at org.apache.jsp.pages.jsp.type3Footer_jsp._jspService(type3Footer_jsp.java:114)
... 73 more


Some googling pointed me to adding locale java options:
This just shifted the problem to Oracle Exceptions complaining about NLS_LANG and suggesting
After all the application worked fine before.

So what was my final solution.

Very simple. In IE go to Tools->Internet Options->General/Languages.
  • found out there were no languages set
  • Add the appropriate one
  • English (United Kingdom) [en-gb] in my case.



Friday, 20 August 2010

IntelliJ Live Templates for Eclipse ...more

This is an update from an earlier post of mine so save me following two links & then having to edit the file.

To Import them into eclipse go to Window -> Preferences -> Java -> Editor -> Templates and import away.

<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<template autoinsert="true" context="java" deleted="false" description="iterate over array with temporary variable" enabled="true" name="itar">for (int ${index} = 0; ${index} &lt; ${array}.length; ${index}++) { ${array_type} ${array_element} = ${array}[${index}]; ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="iterate over collection" enabled="true" name="itco">for (Iterator ${iterator} = ${collection}.iterator(); ${iterator}.hasNext(); ) { ${type} ${element} = (${type}) ${iterator}.next(); ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="iterate with enumeration" enabled="true" name="iten">while (${enumeration}.hasMoreElements()) { ${type} ${element} = (${type}) ${enumeration}.nextElement(); ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="iterate over an array or Iterable" enabled="true" name="iter">for (${iterable_type} ${iterable_element} : ${iterable}) { ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="iterate with iterator" enabled="true" name="itit">while (${iterator}.hasNext()) { ${type} ${element} = (${type}) ${iterator}.next(); ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="iterate over list elements" enabled="true" name="itli">for (int ${i} = 0; ${i} &lt; ${list}.size(); i++) { ${type} ${element} = (${type}) ${list}.get(${i}); ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="public static final" enabled="true" name="psf">public static final ${} = ${cursor};</template>
<template autoinsert="true" context="java" deleted="false" description="public static final int" enabled="true" name="psfi">public static final int ${} = ${cursor};</template>
<template autoinsert="true" context="java" deleted="false" description="public static final String" enabled="true" name="psfs">public static final String ${} = ${cursor};</template>
<template autoinsert="true" context="java" deleted="false" description="main method" enabled="true" name="psvm">public static void main(String[] args) { ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="public void test" enabled="true" name="pvt">public void test${NAME}() throws Exception { ${cursor} }</template>
<template autoinsert="true" context="java" deleted="false" description="print to standard error" enabled="true" name="serr">System.err.println(${word_selection}${});${cursor}</template>
<template autoinsert="true" context="java" deleted="false" description="print to standard out" enabled="true" name="sout">System.out.println(${word_selection}${});${cursor}</template>
<template autoinsert="true" context="java" deleted="false" description="print method name to system out" enabled="true" name="soutm">System.out.println("${enclosing_type}.${enclosing_method}(${enclosing_method_arguments})"); ${cursor}</template>
<template autoinsert="true" context="java" deleted="false" description="print variable out to System out" enabled="true" name="soutv">System.out.println("${VALUE} = " + ${VALUE});</template>
<template autoinsert="true" context="java" deleted="false" description="public void test" enabled="true" name="test">public void test${NAME}() throws Exception { ${cursor} }</template>
</templates>

Monday, 5 July 2010

Getting eclipse to connect to a running tomcat

Firstly tomcat needs to set up to allow a debug connection.

These instructions are for windows - sorry.

  • Go to the tomcat/bin directory and run tomcat6w.exe
  • Click on the java tab
  • To connect on port 8002 add the line:
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002
  • And start tomcat normally


Now go to eclipse.

  • Go the Debug perspective
  • Click on the 'bug' arrow and select 'Debug Configurations'
  • Double click 'Remote Java Application'
  • Give it a name EG 'tomcat'
  • Select the project
  • Select the server if it is not localhost (the default)
  • Select the port that you used above eg 8002
  • Click on the 'debug' button and you are now debugging the tomcat session.

If you want to save that config to use again do the following

  • Click on the 'bug' arrow and select 'organise Favourites'
  • Select 'Add'
  • Search down for the name of the debug session and tick the box
  • Select OK.

Tuesday, 18 May 2010

AgileNorth - May 2010

On Friday I attended AgileNorth May 2010 at Preston UCLAN.

It was an excellent day and thankyou to all the organizers and sponsers Valtech, Thoughtworks to name two.

The opening keynote was by Kevin Murray of Valtech, titled 'Agile in Waterfall Case Studies'. Kevin talked about two case studies where he had been the project manager and introduced agile working practises. Both were large goverment waterfall projects with the latter being a project rescue.

The second project was especially interesting. He was the 14th PM in 2 years and the team members were desperately demotivated. Kevin identified the following benefits:

  • increased morale

  • increased motivation

  • feeling of ownership

  • issues addressed earlier

  • visibility to all of status

  • better quality

  • less bugs at FAT


Kevin emphasised that introducing agile especially into large government style projects must not:

  • compromize estimates

  • question or sacrifice governance


The second talk I attended was by Nick Mckenna of Mckenna Consultants.
Nick is an agile consultant based in Harrogate offering training and consultancy and his talk was titled 'Agile Adoption'. The talk was good and interesting but felt to me like we were getting the first hour of a 1 day talk. His main point was to define a timetable when starting with agile and that could typically be about 3 months. He also emphasised the following:

  • get everyone to agree

  • identify roles

  • spend some time on training

  • take it slow

  • prepare to compromise

  • make it visible

  • keep everyone informed

  • the timetable must be agile

  • review the time table


The third talk was by Paul Shannon (twitter) and Craig Judson (twitter) of Codeweavers titled 'From Chaos to Kanban'

Their talk discussed the life story of how Codeweavers had adopted and adapted agile over the last 2 or 3 years along with the help of the agile consultant Kevin Rutherford. They are clearly exstatic with where they are now in terms of performance and quality. They emphasised to me how agile is in itself agile. how they started doing scrum by the book and ended up with their own kanban solution and board. Their slides are available here.

An excellent lunch was followed by a workshop from Sam Wessel also of Codeweavers on 'CRC - the forgotten Design Tool'. Here is one link to CRC - Class Responsibility Collaborator. This was a fun workshop designing a library application. It showed how to really break down an issue and see your self as the objects in the problem along with their inter-reactions and roles.


The penultimate talk was by the Agile consultant Kevin Rutherford of Rutherford Software (twitter) entitled 'Flow'. The aim of the talk was to show how agile increases the speed with which changes can flow through from requirements to an end product. I really like Kevin's dry and straight talking style. His blog write up of the talk is here. Here are some of his points:

  • YAGNI - do not do what you do not need now

  • question or sacrifice governance

  • thin sliced MMFs (minimal marketable feature) - IE breakdown the work into small chunks

  • continuous integration

  • Theory of constraints

  • The Goal by Goldratt


The closing keynote - phew it was a long day - was by Jim Barritt and Mark Crossfield. Mark is a Thoughtworks ">Thoughtworks consultant and Jim works for Autotrader. There talk covered the issues of working running an agile product with a rapidly expanding workforce.

Two interesting tools that I came across in talks and will investigate soon are

1) Migratordotnet - This is based on the idea of Rails ActiveRecord Migrations. Interestingly it puts the migrations into a dll making them easy to run & install on a windows PC without the need for Rails or other bespoke software.

2) AgileZen - This is an online kanban board, free to use for a single project.

The next AgileNorth will be October time and will be free.

Find other links on AgileNorth via this delicious tag.

Finally here are some twitter links:
@BlueReZZ - Paul Shannon of Codeweavers
@craigjudson - Craig Judson of Codeweavers

Wednesday, 3 March 2010

SSL, tomcat and self signed certificates

I have been through the process of getting an application to work via https before but I have always muddled through and never documented exactly what I have done.

I must also admit that I never quite understood exactly what I had done and why.

One problem is that I can not find one place that covers everything you need in one place.

Now I think I am pretty well there.

This post describes what I have done to get a simple client application working using HTTPS posting to tomcat server and using a self signed certificate with the help of several refereneces in particular:

The last reference has a chapter which is pretty well SSL for dummies and explains things very nicely.

The steps that need to be done are:
  1. Create a self signed certificate authority (CA)
  2. Sign a test key via the CA
  3. Add both these keys to a keystore
  4. Setup the application (client) and tomcat (the server) to use this keystore.

1) Create a self signed certificate authority (CA) and keystore

This is described in How to create a self signed certificate, but I will show the steps here

What is happening here:
you will create a CA that later will be added to your keystore file. By adding this CA to your keystore you are saying it is trusted like verisign and any certificates signed by it are then also trusted.


1.1) make a directory to hold the certs and keystore. This might be something like:
C:\ssl
1.2) generate a private key for the server
openssl genrsa -des3 -out server.key 1024
1.3) generate a CSR (Certificate Signing Request)
openssl req -new -key server.key -out server.csr
1.4) Remove the passphrasse from the key
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

1.5) Generate the self signed certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

2) Create a certificate for tomcat and add both to the keystore

2.1) cd to where the keystore is held. This might be something like:
C:\ssl

2.2) Create a keypair for 'tomcat'
keytool -genkey -alias tomcat  -keyalg RSA -keystore tomcat.ks

2.3) Generate a CSR (Certificate Signing Request) for tomcat
keytool -keystore tomcat.ks -alias tomcat -certreq -file tomcat.csr

2.4) create unique serial number
echo 02 > serial.txt

2.5) Sign the tomcat CSR
openssl x509 -CA server.crt -CAkey server.key -CAserial serial.txt -req -in tomcat.csr -out tomcat.cer -days 365

2.6) Import the server CA certificate into the keystore
keytool -import -alias serverCA -file server.crt -keystore tomcat.ks

2.7) add the tomcat certificate to the keystore
keytool -import -alias tomcat -file tomcat.cer -keystore tomcat.ks

3) Tomcat configuration
3.1) Tomcat needs to be configured to use SSL
This is described in more detail at Tomcat SSL Configuration How-To
However all that is needed here is to edit the server.xml to enable SSL
This section is already in the server.xml but commented out.
NB that the location of the keystore has been added.

<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="C:\ssl\tomcat.ks"
keystorePass="changeit"
clientAuth="false" sslProtocol="TLS" />

3.2) test tomcat
start tomcat and go to https://localhost:8443/

your browser will return an error such as "sites certificate is not trusted"

3.3) import the CA certificate server.crt into your browser's tructed root certificates

3.4) test again at https://localhost:8443/

this time you should see the tomcat home page

4) Test your application

4.1) I have a unit test run from eclipse that I have been using to post off to my test server. This produces the error;
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:289)

4.2) The reason for this is that eclipse is not referring to the keystore that we have created. At the time of writing I have not sussed out how to make eclipse use this - Do you know ?
So instead I have added the same two certs to javas keystore

4.3) cd to the directory where java's keystore is held. This might be something like:
C:\java\jdk1.6.0_18\jre\lib\security

4.4) the keystore is a file called cacerts

4.5) copy the files c:\ssl\server.crt and c:\ssl\tomcat.cer to this directory

4.6) import the server CA into the java keystore
keytool -import -alias serverCA -file server.crt -keystore cacerts
4.7 import tomcats cert into the java keystore
keytool -import -alias tomcat -file tomcat.cer -keystore cacerts

5) Test your app again.
Hopefully all will be hunkdory. Enjoy.

6) Caveats:

6.1) the passwords for all keystores and certs are 'changeit'. this is the default keystore password
and I suggest you change this for a production system

6.2) Using a self signed cert is great for a test environment of for a private system but not for a commercial released application. For this you will need to get & pay for a signed certificate from an approved authority such as Verisign.

Tuesday, 23 February 2010

train times using RESTful urls

While travelling by train in this arctic winter I came across this really nice simple train times site using RESTful URLs to great effect.


The output is really clear and simple making it great for display on small phone screens.