package org.roadway.wisp.zd.util;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* @author Huyvanpull
*
*/
@SuppressWarnings("serial")
public class ExceptionInterceptor extends AbstractInterceptor
{
private Logger logger = Logger.getLogger(ExceptionInterceptor.class);
private String interceptorName;
@Override
public String intercept(ActionInvocation invocation) throws Exception
{
this.logger.debug("进入" + this.getInterceptorName());
String result = null;
try
{
result = invocation.invoke();
}
catch (Exception exception)
{
this.logger.error(this.getExceptionInfo(exception));
throw exception;
}
return result;
}
private String getExceptionInfo(Exception exception)
{
StringBuffer bExceptionInfo = new StringBuffer();
bExceptionInfo.append(exception.toString());
bExceptionInfo.append("\n\t");
StackTraceElement[] stackTraceElements = exception.getStackTrace();
for (int i = 0; i < stackTraceElements.length; i++)
{
bExceptionInfo.append("[" + this.getInterceptorName() + "] "
+ stackTraceElements[i].toString() + "\n\t");
}
return bExceptionInfo.toString();
}
public String getInterceptorName()
{
return interceptorName;
}
public void setInterceptorName(String interceptorName)
{
this.interceptorName = interceptorName;
}
}