Saturday, February 13, 2016

How to generate alert mail to find Unchecked Exception in your JSF application (ExceptionHandlingActionListener)

Past few days I had a dilemma of how to generate email alert if my JSF application has any RuntimeException. Finally I found a solution.

ActionListenerImpl class   help me for that.

No need to talk, let's start the party.

First step:
We need to create ExceptionHandlingActionListener  class that implements  ActionListenerImpl.
in the ExceptionHandlingActionListener classwe should override the supper class processAction(ActionEvent event) method. And write our email alert code inside the catch block.

So in my sysout " Typing email " section, we can call to a email generation method and pass the StackTrace to email body. Email formatting is not in my radar.

package com.imesh.test;

import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import com.sun.faces.application.ActionListenerImpl;

public class ExceptionHandlingActionListener extends ActionListenerImpl
  implements ActionListener {
 public void processAction (ActionEvent event) {
  try {
   super.processAction (event);
  } catch (Throwable e) {
   try {
                System.out.println("----------------------- SYSTEM EXCEPTION EMAIL SEND BEGIN. -----------------------");
                System.out.println("Typing email");
                System.out.println("----------------------- SYSTEM EXCEPTION EMAIL SEND END. -----------------------");
            } catch (Exception f) {
                System.out.println("----------------------- SYSTEM EXCEPTION EMAIL NOT ABLE TO SENT. -----------------------");


Second step : 
Add this listener to the faces-config.xml

<action-listener> com.imesh.test.ExceptionHandlingActionListener 

Awesome!!!,  We are done. Try create any RuntimeException in your application. Magically it will handle by our ExceptionHandlingActionListener  and generate the email for you.

Thank you, Comments are welcome !!.

Tuesday, February 9, 2016

My experience with Qistina Express bus to Kuala Lumpur

Qistina Bus Review

I have seen many places that Qistina has bad review on certain things. I traveled to Kuala Lumpur from Singapore on 6th Feb 2016.

My depart time was 8.30 am at Little India Arcade.
Since I read all the review previous day, I just did another search to see whether the bus has got any seats available, thinking that if it's full then no need to wait for more pax. The bus was not appear in the search results. So I thought the bus is full and can go without waiting it to get filled.

As most of the travelers mentioned, they were late. But the office was opened. I saw some ppl said that office was not opened till 10.30 am. But by the time I reach 8.30, the counter was already opened.

Bus came around 9 am luckily. But it was waiting there till 9.30 for more passengers. There is no seat preference as we book. You can sit freely anywhere you need. So they add ppl who ever wants to go by this bus. Bus is full now.

Then the journey started it's a big traffic due to chinese new year. After JB check point, the bus stopped in a petrol shed. Not to fill the petrol. I don't know where the hell driver went but the bus was stopped there around 40 mins for nothing. We did not move to another bus but we had to waste the time for nothing.

Bus is not smelly, Driver didn't smoke during travel, Seats are average. A/C also OK. Driver was waiting for all passengers. He is fast but safe drive.

So this is my experience the Journey to KL.

Sri Maju Group reivew

On the way back to Singapore, I used Sri Maju travels.  I had perfect journey. The bus reached on time to the TBS point and depart within 5 mins. No stops no wait. The driver stopped after 1,5 hrs for a small break in a petrol shed. again started and stopped in the usual stop for a tea break.

So we started 1.30 from TBS we reach JB 6 pm. Amazing. The drive was very nice, he saw there is a block in the one enterence to the JB check point then he turn the bus in to another way. No traffic we went directly to the check point. And he wait until everyone come on each checkpoint and each time he count the pax.

It's a Scania bus. The journey was not tired at all. Price was 18 SGD (not bad at all huh?)
We reach around 7.20 to the Golden Mile Complex.

How ever I will not use the Qistina Express again but for sure Sri Maju. Thumbs up  for Sri Maju !!! 

Saturday, January 30, 2016

Damro Innovex Electronic goods and after service crappy

I would like to write the review of the Damro Innovex  Pedestal Fans.

Sometimes ago I bought tow fans (one after another) from Damro which is Innovex brand. After one and half year my first fan suddenly stopped working. So I gave to the Damro Dalugama showroom to check. I am out of warranty. They took almost 2 weeks and came back with  Rs 900.00 service fee. When I asked them what did they do to fix, the show room staff said that they have no idea what the service center did.
So I had my fan back. But after a one week again the fan is stopping intermittently. Then again it works for few weeks with bad sound. Stopped working again and I went back to Damro, told them that few weeks ago I got repaired this but doesn't work again. They said they have service warranty for 6 months, so let's send this back to service center.
After 2 weeks, they phoned me and said the fan is fixed but I was charged Rs 1200.00 for the fix. I said what the hell you said it has 6 months warranty but now you charge me again Rs 1200.  Then the staff said they will check with service center again but still didn't comeback.

My loyalty for Damro is fading now. I had few electrical items from them thinking that I am supporting to sri lankan owned business.

I just want to tell that based on these info decide whether you still go with Damro Innovex product and service or pay bit more and purchase a long lasting branded product.

I checked around and found that KDK is quite long lasting. Even it's double the price as Innovex fans but it will last more than 20 years for sure.

Friday, October 23, 2015

PC Dreams Laptop Hospital - Singapore

Few weeks ago suddenly my laptop screen became white. So I checked in web and found a place call PC Dreams in Funan mall.

They hold the laptop by charging 64$ for inspection.  And after three days phoned me and said it would cost 240$ to replce thr screen. The laptop it self is only cost me 500$. I checked with Acer service center.  They said the screen cost around 80$ only.

So I was misleeding with hardware zone forum and paid 64$ for nothing. Also they have broken the screem arm which I saw only I came home.

Sunday, November 9, 2014

Resource in Maven POM

Recently I was engaged to a project which convert a legacy ant build application into Maven build. My main application project has several sub projects. One child project fully contained sql scripts and cron job scripts. So I had to find where to include these sql and .sh files in the maven structure. I google and went through few articles to find out the correct place.

There is no clear cut solution I found. Some people suggest to put it into resources folder and some suggest to use separate folder. So, I thought to go ahead with a separate folder because the content of resource folder will attach to ear once I build it ( but still we can exclude them. Yet I thought it could be messy).


While surfing the web, I found more about Resources. We can include our separate folder into jar file. In my case, I do not want sql and .sh files to available in final jar. I just want to keep those in the same project. Let's see where to include those files and how to bundle our own folder into a jar.

Below is the apache introduction about Resources..
" Resources is a nice feature of build elements is specifying where resources exist within the project. Resources are not (usually) code. They are not compiled, but are items meant to be bundled within your project or used for various other reasons, such as code generation"

So I included all my sql and .sh files in its own directory instead put them in src/main/resource/scripts/sql, Now my sql and .sh files are located in src/main/scripts/sql and src/main/scripts/sh folders respectively. When I build the project, scripts folder is not included to jar.

Say, now I need to build a jar including the sql and sh files.

For this I used JAR plugin to bundle the resource correctly, and I would specify resources similar to the following:

<project xmlns="" xmlns:xsi=""

See below detail about each tag.

  • resources: is a list of resource elements that each describe what and where to include files associated with this project.
  • targetPath: Specifies the directory structure to place the set of resources from a build. Target path defaults to the base directory. A commonly specified target path for resources that will be packaged in a JAR is META-INF.
  • filtering: is true or false, denoting if filtering is to be enabled for this resource. Note, that filter *.properties files do not have to be defined for filtering to occur - resources can also use properties that are by default defined in the POM (such as ${project.version}), passed into the command line using the "-D" flag (for example, "-Dname=value") or are explicitly defined by the properties element. Filter files were covered above.
  • directory: This element's value defines where the resources are to be found. The default directory for a build is ${basedir}/src/main/resources.
  • includes: A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard.
  • excludes: The same structure as includes, but specifies which files to ignore. In conflicts between include and exclude, exclude wins.
  • testResources: The testResources element block contains testResource elements. Their definitions are similar to resource elements, but are naturally used during test phases. The one difference is that the default (Super POM defined) test resource directory for a project is ${basedir}/src/test/resources. Test resources are not deployed.
Hope this would help to increase your knowledge about maven resources.

Friday, February 14, 2014

Use OpenEJB for Junit Test

I was struggling yesterday to find a way to do Junit test for EJB and I found OpenEJB. But  the configuration gave me errors. So I thought to write a complete example because I couldn't find it anywhere.

First lets create a simple ejb.
Here is the interface

  package com.imesh.testejb;
  import javax.ejb.Local;
  public interface IHello {
    public string sayHi();
OK now the bean class.
  package com.imesh.testejb;
  import javax.ejb.Stateless;
   * Session Bean implementation class Hello
  public class HelloBean implements IHello{
     * Default constructor.
    public HelloBean() {
    public string sayHi() {
      return "HI";

Write our unit test class.

package com.imesh.test.ejbtest;
import static org.junit.Assert.*;
import java.util.Properties;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import org.apache.openejb.api.LocalClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class HelloBeanTest {
 public void setUp() throws Exception {
     Properties properties = new Properties();
     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
     properties.setProperty("openejb.deployments.classpath.include", ".*");
     initialContext = new InitialContext(properties);
 public void tearDown() throws Exception {
 public void testSayHi() {
   bean = (IHello) initialContext.lookup("HelloBeanLocal");
   assertEquals("Hi", bean.sayHi());
  private InitialContext initialContext;
 private IHello bean ;

Ok now we need ejb-jar.xml file which should be located in the META-INF folder.
ejb-jar.xml contains nothing but   just empty tag. I couldn't run the unit test without this xml but nobody mentioned about this xml in examples. The error I got is relate to the JNDI name not found.
If you do use annotation in your ejb class, ejb-jar.xml will overwrite your annotation. So you can add this xml to test > resources > META-INF folder because we need this only for unit test. 
Next is dependencies. You may not want slf4j dependency. But I had some errors without it.



 That's it. We are done. you can compile and run the unit test.

Sunday, November 11, 2012

Malithma Flora

I write this incident before you go to Malithma flora nugegoda. You can judge malithma flora while talking with them. Malithma is not flexible to their customers. Malithma flora did bad job in my sister's wedding flower decoration. In initial discussion malithma flora promise to make any new design and decorations for us. When dates close, we gave our choices but Malithma flora said they have to charge additional. So we had no option yet to go with existing. However eventually the decoration was poor.
So I advise to sri lankans when hiring malithma flora for your wedding meet them and discuss deeply rather than simple telcons. Carefully test them.

Here are there web details. They located in Nugegoda.