Tuesday, 21 December 2010

keepass on android

I have just entered the 21st century phonewise and got an android phone, the motorola defy, and very pleased with it I am.

The first two apps I put on the phone are keepassdroid and dropbox.

I have blogged about these in the past and now I have my phone synced to the same keepass database. For all those i-phone users there is of course an i-phone version too. It all works a treat so I still do not need to know any of my passwords.

One slight issue I had, my PC version of keepass was out of date so I had to upgrade that to get the two keepass clients to work together.

Wednesday, 24 November 2010

eclipse, junit & static imports

It was annoying me that eclipse was not finding the static imports needed by junit 4 unit tests.

A quick google tuned up this gem, which I have grabbed below:

Open the Preferences via Window -> Preferences and select Java > Editor > Content Assist > Favorites. Add then via "New Member" the methods you need. For example this makes the assertTrue, assertFalse and assertEquals method available.

You can now use Content Assist (Ctrl+Space) to add the method and the import.

He suggests to add at least the following new members.

  • org.junit.Assert.assertTrue

  • org.junit.Assert.assertFalse

  • org.junit.Assert.assertEquals

  • org.junit.Assert.fail

I suggest also adding

  • org.junit.Assert.assertNotNull

Friday, 19 November 2010

pidgin - Unable to validate certificate error

If you are having the 'Unable to validate certificate' error from pidgin then do the following:

  1. go to here, download the certificate omega.contacts.msn.com.pem
  2. in pidgin go to tools/certificates
  3. delete the cert omega.contacts.msn.com.pem
  4. add the new downloaded cert
  5. and away you go
UPDATE - or as I have said in the comment, now you can download the new version with a fix - see or better still update to the latest version that now has the fix - http://www.pidgin.im/

Thursday, 21 October 2010

SQLdeveloper & showing the full date

I keep getting this every time I install SQLDeveloper.

The date shown is just dd/mm/yyyy with no hours:minutes:seconds

The solution can be found here on Zenx's blog, but to save me looking here it is also.

1. From SQL Developer, open menu Tools >> Preferences.
2. From the Preferences dialog, select Database >> NLS Parameters from the left panel.
3. From the list of NLS parameters, enter DD-MON-RR HH24:MI:SS into the Date Format field.
4. Save and close the dialog, done!

Thanks Zenx.

Also, if you want milli-seconds add ':SSSSS' at the end.

Wednesday, 20 October 2010

git & github from windows

While learning Grails and working though 'Grails in Action' I wanted to save my work to a repository. SVN can be a pain to setup on windows and many people use github & so I thought I would give it a go.

Sadly I am on a windows PC but I have just been so pleasantly surprised as to how easy it was.

This is what I had to do:
  1. I work from a cygwin command shell. In this I had to have ssh & git executables installed.
  2. help to set up the ssh key is here .
  3. I did not realise that git acts as a local repository as well as a public repository so you are under no obligation to upload your work. The local set up is a breeze and is described in this excellent tutorial, running the commands from my cygwin shell.
  4. There is even a GUI with the command 'gitk'
  5. create the repository on the remote server such as the public github repository
  6. Once you want to upload the code to a public github repository it is a simple case of running the following commands:
  7. cd existing_git_repo
    git remote add origin git@github.com:bill-comer/hubbub.git
    git push origin master
  8. And you can download code from github using the following:
  9. git clone   git@github.com:bill-comer/hubbub.git
  10. As I am on a windows PC I had to tweak the SSH2 key location. In eclipse go to Preferences/Network Conections/SSH2. Here I set the SSH2 home to where my cygwin .ssh directory is. In my case C:\cygwin\home\comerb\.ssh.

Now go ahead and enjoy a free and easy to use code repository.

Thursday, 30 September 2010

Grails & 'Grails in Action' - some notes & comments

I have just started playing with grails.
I am using 'Grails in Action' as my reference.
My current version of grails is 1.3.4
I am using the STS eclipse IDE with their built in grails plugin

Here are some initial notes on GOTCHAs I have found with the book and grails itself.
NB I will continue to update this one page with other gotchas, instaed of creating many pages.

Comments on 'Grails in Action'

1) p28, list 1.22
'render' should be 'response.outputStream <<'

2) logo.png & snazzy.css are needed for chapt 1 & can be got from github

Comments on Grails 1.3.4

1) can not create integration tests - getting error
Error executing script CreateIntegrationTest: No such property: type for class: CreateIntegrationTest
No such property: type for class: CreateIntegrationTest

edit the file scripts/CreateIntegrationTest.groovy in your grails installation
and add the line
def type = "Tests"
after the line
depends(checkVersion, parseArguments)

NB this is fixed in 1.3.5

2) when running the test via 'grails test-app' the url for the report is incorrect
and is missing the trailing 's' from the URL

edit the file scripts/_GrailsTest.groovy line 402 and add a space after the the closing brace of testReportsDir and before the double quote
msg += " - view reports in ${testReportsDir} "

3) 1.3.5 bug - add a contraint that specifies the size of the field then it does not check for null.
IE This will allow a nulll value in name:
static constraints = {
name (size:3..8)

The work around is to do this:

static constraints = {
name (size:3..8, blank:false)

bug GRAILS-6821 has been raised on version 1.3.5

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 &lt;parseNumber&gt;, 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" ?>
<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>

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:
  • 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:
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:

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"
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:

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.