Weekly links 2010-32

During these weeks I was too busy for contributing the weekly link. Here it is one for this week 🙂

Maven is good, but needs some love

…But Maven needs a proper and clean environment…

Functional Programming Concepts in JDK 7 | Javalobby

Kent Beck’s Test Driven Development Screencasts

Following the recommendations of Corey Haines, Michael Guterl, James Martin and Michael Hunger I decided to get Kent Beck’s screencasts on Test Driven Development which have been published by the Pragmatic Programmers.

Testing REST Web Services With JPA and Spring

REST Web Services can be particularly difficult to test, with the need for networking, a web container, multiple threads and transaction management creating extra complexity beyond your standard unit test. In this article I demonstrate patterns designed to address this complexity while enabling complete testing of your REST web service stack.

Oracle shuts down open source test servers

No One Nos: Learning to Say No to Bad Ideas

No. One word, a complete sentence. We all learned to say it around our first birthday, so why do we have such a hard time saying it now when it comes to our work?

Kick Ass Kickoff Meetings

Every meeting is an opportunity. Why waste your first one?

5 things you didn’t know about … Java Database Connectivity

JDBC is more than a background player in database connectivity. The more you know about it, the more efficient your RDBMS interactions will be.

Have you upgraded your Java 1.6_21 to Java 1.6_21?

Selenium 2/Web Driver – the land where Page Objects are king!

12 Things A Programmer Really Needs To Know

URL-based Locale

Spring Reading – Getting Started with Spring Framework

Advertisements

Specify proxy in Maven

I’ve just started using Maven, and I suddenly stub into a problem where maybe everybody in big corporate have stubbed: connecting through a proxy.

Maven can connect to internet through an HTTP proxy that support basic authentication. In order to specify it, just create (or modify if exist) the file ~/.m2/settings.xml in the following way:

<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>put.here.the.proxy.address</host>
<port>3128</port>
<username>yourUserName</username>
<password>yourPassword</password>
<nonProxyHosts /> <!– useful for location to make bypassed by proxy –>
</proxy>
</proxies>
</settings>

That’s it! 🙂

SSL and Java (ciak 2)

credits: Vagamundos (from flickr)

credits: Vagamundos (from flickr)

Last time we spoke about accessing a site via HTTPS using the pure Sun way.

Today, we see the same problem, solved with the apache HttpClient libraries. This library require a keystore specified in the code. In order to generate a keystore, you will have to download a certification file as described in the previous post and then create a keystore using the keytool program. I don’t remember well how to create a new keystore with the required certificate via keytool (I did’t write it down), but reading the help of the program it should be something like:

keytool -importcert -alias <my_alias_certificate> -file <path_to_the_cer_file> -keystore myKeystore.ks

where myKeystore.ks is the name of the file containing the keystore. The pros of using this approach is that you can provide a .ks file among with the program, in a location desired and the program will use it, avoiding post-installation procedures to register the certificate on each jvm.

So, assuming to have our keystore into a sub-directory certs the code for using the site is in the pdf as usual.

SSL and java

credits: ph0t0 (from flickr)

credits: ph0t0 (from flickr)

Sooner or later it happens that you have to access an https via Java. Accessing a generic http (non ssl) site is quite easy using the URL and URLConnection objects.

When you try to access a site through SSL the main problem is that most sites does not have a registration in the java’s Certificate Autorithy (CA), causing the framework to refuse connection to that site. So the main solution is to register the certificate of that site in the java’s CA.

So, the things to do are:

  1. download the site certificate
  2. register it in the java’s CA
  3. accessing the site

Downloading the certificate

In order to download the certificate we are gonna use Firefox. With firefox navigate to the site and if required accept the certificate. Double click on the icon of the certificate (1), in the screen that appear choose view certificate (2), on details tab (3) use the export button (4) and save it wherever you want (5).

screen

Register the certificate

Once downloaded the .cer file (X 509 Certificate DER), you can import it into the CA using the a command line program deployed with the j2se installation: keytool.

Java’s CA and keytool are available in the $JAVA_HOME/lib/security/ and an example of using the keytool (under windows) is the following

C:\Program Files\Java\jre6\lib\security>keytool -import -trustcacerts -alias fonsai -keystore cacerts -file fonsai.cer

where fonsai.cer the file name of the certificate just downloaded.

Maybe if you are using eclipse, you will have to restart the workbench in order to make the registration visible to the jvm.

The main counterpart of using this approach is that you have to register the certificate for each jvm running the program and since certificate can expire you should have to do this operation more than one time. I advise to automate the registration operation with a shell script to be distributed among with the program.

Accessing the site

Once registered the site’s certificate, you can access it as usual using the URL and URLConnection objects. It should be enough to tell (via System.properties) an SSL provider. Here is a PDF with the code.