Saturday, November 28, 2009

Guice-ing your code

During my learning on shindig, i found out that shindig using guice a lot on its code. Of course, I try to find out what is this tool about. After a little bit searching, I found out that the it is a bit similar with Spring. However, the authors say that it is different. They say that guice is not container and it is too light to be container. Anyway, just cut the bullshit and try to find out what is this tool about.

The first impression on my side after trying this tool is simple. Well, yes... it is indeed very simple as a dependency injection framework. What you need to do is the annotation. It makes all the things very simple.

The things that you need to remember (well, at least on my simple try) on regard of guice-ing your codes is the injector. The injector will try to lookup what are the fields, methods or constructor which need to be injected with object. Then, guice will inject it for you.

Below is a little bit example on it:

public static void main(String[] args) {
// TODO Auto-generated method stub
Injector injector = Guice.createInjector();
Customer customer = injector.getInstance(Customer.class);
customer.changeItem("barangnya");
}

The method injector.getInstance(Customer.class) will give you a complete object of customer with the injected notifier object. Below is the class of Customer:

public class Customer {
@Inject
public Notifier notifier;
public void changeItem(String message)
{
notifier.sendNotification(message);
}
}


Notifier is an interface. Guice will lookup on this interface to find out what class implement Notifier interface. In order to know what class which implemet Notifier interface, the interface should define annotation to tell the guice. Below is the interface of Notifier.

@ImplementedBy(SendSms.class)
public interface Notifier {
public void sendNotification(String message);
}


Its easy, isnt it (well, at least for this try :P)?

Monday, November 16, 2009

Building and Running shindig source on eclipse

Well, running or debugging any java sources managed by maven inside eclipse is as easy as running any simple application in eclipse. The only thing that you need is maven integration plugin. This is a super power plugin when your application deal a lot with maven. I just started to fall in love with eclipse instead of his competitor, Intellije IDEA, which always falls on the error of classpath. I need to delete the current working space and then rebuild it again. Its very annoying.

Yeps, maybe better to tell you a bit story of using this IDEA, a very lame tool to develop your application. The slogan should not be "Develop with pleasure", but it should be "Develop with pressure" instead. Many people agree with this slogan. Perhaps, we really need to tell them this new slogan. I have been using this IDEA to develop and learn about Confluence and JIRA source. However, everyday, I restart my computer, it always fall on the classpath error. It says that it cannot find xxx class while yesterday i build it without any problem. Then, the only thing that I can do is to build it again. It takes a lot of time indeed. Thus, I recommend you for not using IDEA to develop your application. It will only give you pressure because you spend a lot of time to rebuild your source.

Anyway, back to eclipse. I am using this tool to build, running and debugging the source of shindig. Yeps, it is pretty much easy. You just need to install the plugin on this url:
http://m2eclipse.sonatype.org/update/

well, you should get the list of plugins need to be installed. Just pick the core and then installed and restart your eclipse after finishing the installation. After that, you can simply open debug configuration and then create a maven command to run your source. You can use any maven plugin, I have used jetty and tomcat for the tries.

Building and Running shindig source

I ve just tried to build the source of Shindig and running it on eclipse. Yes, as what most people expected, there will be problem face during this process.

First time I was experiencing the problem of not able to build the source of shindig. I saw the log of the process, it fails on the test code. Thus, I just skipped it and running the maven command mvn is success.

The problem is not stopped on this, if you try to run it on jetty using the following command (as what the doco said)

mvn clean install jetty:run -DrunType=full -Djetty.port=80

It will complain as in the following:

[INFO] The plugin 'org.apache.maven.plugins:maven-jetty-plugin' does not exist o r no valid version could be found
Thus, you need to run a complete maven command as in the following

mvn clean install org.mortbay.jetty:maven-jetty-plugin:6.0.1:run -DrunType=full -Djetty.port=8091

Even more, it will complain on the non-availability of the webapp directory as in the following:

[INFO] web.xml does not exist at location F:\software\shindig\src\main\webapp\WE B-INF\web.xml
Therefore, you need to run it on /java/server. Run the above complete maven command, you should get your jetty running the shindig. You can access the sample of shindig using the address:

http://localhost:8091/gadgets/ifr?url=http://www.labpixies.com/campaigns/todo/todo.xml

You should see the following image on your browser.

Saturday, November 14, 2009

SSO (Single Sign On) for JIRA and Confluence

I just developed an SSO application which is built on mule. This SSO can be plugged in the application which is using seraph as its security framework. The 2 greats Atlassian's product which are Confluence and JIRA uses seraph, as its security framework. Thus, this SSO can be applied to these products.

Basically, the idea of this SSO are:

  • to use a middleware to store a data on regard of user's authentication, The middleware that I use is mule as it is free and open source. So, people can use it.
  • to use the existing user framework which is used in seraph to perform authentication. Seraph, by default, uses osuser as its user management framework. However, as we can customize and plug any authenticator to seraph. This would make the authentication is more dynamic to perform. The authentication definitely needs user management framework to perform its task by comparing the credential in database against the input that use provides.
As of now, i still need to clean the code and doing some automation to ease the installation.