Mar 29, 2012

JavaDoc incremental searchbar for Firefox and Chrome

Javadoc is very old but it is a great way to create documentation and now with Java 7 we have better CSS in Javadoc.

Grease Monkey
But there is one thing always missing in the generated documentation and that is a search bar in the left frame where the class list is displayed. Since there are tons of java projects and with that tons of Javadoc it's very probable that most of the Javadoc will remain a little bit ugly.  Because we cannot change the Javadoc on other sites we can change it  how they are displayed on our side.

There is this super awesome project on google code  where using GreaseMonkey and some client side JS they have added incremental search. So now when viewing Javadocs, this script replaces the package and class frames with a single search frame that allows searching incrementally through all packages and classes at once. There is plugin for Firefox and Chrome available.  You would need to have GreaseMonkey installed first on the Firefox version.
So now we have a search bar that is awesome and it works remote as well as local pages.

Code Google project page

Mar 26, 2012

Basic Authentication with RestTemplate

Spring Rest Templates are very good way of writing REST clients. By default they work with basic HTTP so if we need to use Basic Authorization we would need to init the rest template with custom HttpClient. This way the Rest Template will automatically use Basic Auth and append to the HTTP headers "Authorization: Basic BASE64ENCODED_USER_PASS".

HttpClient client = new HttpClient();
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials("USERNAME","PASS");
  new AuthScope("", 9090, AuthScope.ANY_REALM),
CommonsClientHttpRequestFactory commons =
     new CommonsClientHttpRequestFactory(client);

RestTemplate template = new RestTemplate(commons);
SomeObject result = template.getForObject(

In EE application this would probably be managed by DI framework like Spring Core and only initialized once since  RestTemplate is stateless.

HTTP Basic Auth
Spring Rest Templates
Spring Rest Templates JavaDoc
Apache HTTP components