Sunday, February 14, 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.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 {
 
 
 @Override
 public void processAction (ActionEvent event) {
  try {
   super.processAction (event);
  } catch (Throwable e) {
   e.printStackTrace();
   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. -----------------------");
                f.printStackTrace();
            }
            
   
  }
 }

}


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


1
2
3
4
<application>
<action-listener> com.imesh.test.ExceptionHandlingActionListener 
</action-listener>
</application>


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 !!!