How did I setup SSL with HTTPClient-4.1.2

I've been struggling to get this working for about 2 days now. I was able to POST a request directly from sockets, but it took me a while to see it working with HTTPClient-4.1.2. There are different variants out there in google for legacy HTTPClient and less than 4.1.x.
The key was to specify TrustManager and KeyManager while initializing SSLContext.

Step-1: First, you have to initialize SSLContext like this:

SSLContext ctx = SSLContext.getInstance("TLS");

Step-2: Getting TrustManager. Java look into its trust managers to check against authorized Certification Authorities(CA). Default trust store in Java is "jks". This is how you can get trust manager:
TrustManager[] getTrustManagers(String trustStoreType, InputStream trustStoreFile, String trustStorePassword) throws Exception {
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(trustStore);
return tmfactory.getTrustManagers();
}

It should be called as:
TrustManager[] trustManagers = getTrustManagers("jks", new FileInputStream(new File("/Library/Java/Home/lib/security/cacerts")), "changeit");

/Library/Java/Home/lib/security/cacerts is the default path to trust managers in Mac OSX

Step-3: Getting KeyManager: This is where your client certificates are stored. KeyManager in the code can be retrieved as :
KeyManager[] keyManagers = getKeyManagers("pkcs12", new FileInputStream(new File("clientCertificate.p12")), "password");

You have to get KeyManagers using KeyManagerFactory like this:

KeyManager[] getKeyManagers(String keyStoreType, InputStream keyStoreFile, String keyStorePassword) throws Exception {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmfactory init(keyStore, keyStorePassword.toCharArray());
return kmfactory.getKeyManagers();
}

Step-4: Once you have TrustManager and KeyManager ready, pass them in SSLContext:
ctx.init(keyManagers, trustManagers, new SecureRandom());

Step-5: Now create a SSLSocketFactory object using SSLContext object:
SSLSocketFactory sf = new SSLSocketFactory(ctx, new StrictHostnameVerifier());

Step-6: Assign Scheme to the HttpClient:
DefaultHttpClient httpclient = new DefaultHttpClient();
ClientConnectionManager manager = httpclient.getConnectionManager();
manager.getSchemeRegistry().register(new Scheme("https", 443, sf));

Done !
Now use this httpclient in HttpPost, HttpGet ….

My take on setting up Jenkins for PHP project on Mac OSX

I've found many good articles on setting up Jenkins for PHP projects. But couldn't get one which is targeted to Mac OSX. Here is the one, I followed to setup Jenkins for myself. I took following steps to setup one on Mac OS:

1- Installing php5 and pear using mac-ports: sudo port install php5 +pear
Enable libphp5.so module in apache configuration file: /etc/apache2/httpd.conf

2- Installing/configuring xdebug using macports:
command: sudo ports install php5-xdebug
Macports automatically put xdebug.so in /opt/local/lib/php/extensions/no-debug-non-zts-20090626

Copy xdebug config in /etc/php.ini
[xdebug]
zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

Check debug installtion:
php -r 'var_dump(extension_loaded("xdebug"));'

3-Install ant using macports
sudo port install apache-ant
Macports installs ant in : /opt/local/bin/ant

4- Follow this tutorial for creating demo project and other steps:
http://edorian.posterous.com/setting-up-jenkins-for-php-projects

I had trouble in installing phpunit. I had to do install following packages as well in addition to the packages mentioned in above tutorial:
sudo pear install -f Net_URL2-0.3.1
sudo pear install HTTP_Request2-2.0.0RC1
and then
sudo pear install --alldeps phpunit/PHPUnit

5- Jenkins jobs folderis located at: /Users/Shared/Jenkins/Home/jobs/
6- Restart jenkins using : java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
7- Reloading jenkins configuration: java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
8- Checkout php-template job from this tutorial and reload configuration
9- You are Done !
10- Play around the Jenkins :-)

Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .