Sunday, December 1, 2013

Logging Interceptor

import org.sonar.report.pdf.util.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * @author premkumar.bharti Logging Interceptor handles logging.
 */
public class LoggingInterceptor implements Interceptor {
   
    private static final long serialVersionUID = 1L;
   
    /**
     * Interceptor acts when Action Class starts and exists
     */
    public String intercept(ActionInvocation invocation) {
        String result = null;
       
        @SuppressWarnings("unused")
        String className = invocation.getAction().getClass().getName();
        try {
            result = invocation.invoke();
        } catch (Exception ex) {
            return null;
        }
        return result;
    }
   
    /**
     * called at destruction of Action
     */
    public void destroy() {
        Logger.info("Destroyed-----------");
       
    }
   
    /**
     * called at initialisation of Action
     */
    public void init() {
        Logger.info("Initialised-----------");
       
    }
}

No comments:

Post a Comment