Showing posts from 2009

OSGi - introduction

OSGi - Open Services Gateway initiative helps to develop and deploy applications/libraries which are modular or need to be modular.This specification was started by OSGi alliance in 1999.
To develop OSGi application, the OSGi specification defines two things: first the set of services that the OSGi container needs to implement and second a contract between the OsGi container and the application. So in short, you need a OSGi container to run your OSGi complaint application. As of now there are 3 containers that are OSGi complaint; Knopflerfish,Equinox and Apache Felix.
OSGi offers several advantages
one can install,uninstall,start, stop any modules of the application at runtime.Helps to build service-oriented applicationsApplication can have more than one version of a module running at the same time.In the next article I will show you how each of these advantages translates into code rather than just plain english sentences in your tech vocab.

NullPointerException in static factory-method in Spring

For one project, I was trying to test db connection at startup using some method like
public static void testConnection(DataSource ds){...}

which I happily configured in Spring using the factory-method attribute. To my surprise I got NullPointerException in populateMethod of Spring class AbstractAutowireCapableBeanFactory.

The reason for this was, Spring was expecting a object to be returned as it's a factory-method and fatory method will always return some object. Since my use case was to only test the connection and leave it I didnt return anything.

Hope this helps.

Binary To Text using Base64 encoding

If you need to convert binary data to text one of the recommended approach is to use base64 encoding and not direct string conversion like
byte[] byteArray = //get byte array from any image file
String str = new String(byteArray);

This is not recommended as it will not necessarily represent a valid character string in any encoding. Base64 will make sure that the byte array represents a valid ASCII character string
Ex byte[] byteArray = //get byte array from any image file
String str = new Base64Encoder().encode(byteArray);

To support this point lets take an XML String with the str String padded between some xml element like
String xmlString = <imagedata>;

This xml when parsed for the image
InputSource inputSource = new InputSource(new StringReader(xmlString));
DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder();
Document document = builder.parse(inputSource);

will throw an error in the first case ie using String…


Was excited to check Google GWT 1.6, I decided to try an example application using the same. But hit a road block when I got stuck when I needed more advanced features, so had to look at ExtGWT or GWT-Ext, was confused as to what to use. GWT-Ext is maintained by Sanjiv Jivan and uses ExtJS, and ExtGWT (GXT) is from the makers of ExtJS.I decided to move on ExtGWT, I made this choice based on that I would always put a bet on some company product than an individual,purely my decision. Though, GWT-Ext seemed so viable and tempting option.