I've done this on client side only by specifying the list of accepted certificates. I've never tried to do this what certificate hash, I don't know whether the java api allows you to do this or not. If you have the certificates then you can specify them as trusted: http://stackoverflow.com/questions/859111/how-do-i-accept-a-self-signed-certificate-with-a-java-httpsurlconnection
]. I think this is the clean solution.
If you want custom server certificate validator code then this example may help: http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https/6378872
The important thing is the
method in the trustmanager, you should always throw an exception there except if your check find the server acceptable.