I am trying to implement a custom exception mapping interceptor to be used
in my struts2 portlet. I implemented my own ExceptionMappingInterceptor
class that is similar to
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor, the only
difference is that I send an email with the exception report to the
application administrators. I have used this same interceptor successfully
in a regular struts2 application.

The problem I am having is that it appears that the action is being called
and the exception caught by some other class before it gets to my
interceptor even though my interceptor is declared first in my stack. Since
my custom interceptor is first in my stack shouldn't it be the first thing
to catch an exception begin thrown from my action?

*My interceptor looks like this in struts.xml:*
<interceptors>
    <interceptor name="customException"
class="edu.suu.struts2.interceptor.ExceptionMappingInterceptor"/>
    <interceptor-stack name="myStack">
        <interceptor-ref name="customException"/>
        <interceptor-ref name="portletDefaultStack"/>
    </interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"/>

*
Here is my debug logging:*
DEBUG [com.opensymphony.xwork2.DefaultActionInvocation] - Executing action
method = optIn
DEBUG [edu.suu.googleapps.portlet.OptInAction] - optIn()
---exception is thrown here---
DEBUG [org.apache.struts2.portlet.result.PortletResult] - Executing result
in Event phase
DEBUG [org.apache.struts2.portlet.result.PortletResult] - Setting event
render parameter: /WEB-INF/jsp/error.jsp
DEBUG [edu.suu.struts2.interceptor.ExceptionMappingInterceptor] - result =
error
DEBUG [edu.suu.struts2.interceptor.ExceptionMappingInterceptor] - No
exceptions caught
DEBUG [org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher] - Leaving
processAction
DEBUG [org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher] - Entering
render
DEBUG [org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher] -
serviceAction
DEBUG [org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher] - Creating
action proxy for name = renderDirect, namespace =
DEBUG [com.opensymphony.xwork2.DefaultActionProxy] - Creating an
DefaultActionProxy for namespace  and action name renderDirect
DEBUG [org.apache.struts2.portlet.interceptor.PortletStateInterceptor] -
Restoring value stack from event phase
DEBUG [org.apache.struts2.portlet.interceptor.PortletStateInterceptor] -
Restored stack
DEBUG [com.opensymphony.xwork2.interceptor.I18nInterceptor] - intercept
'/renderDirect' {
DEBUG [com.opensymphony.xwork2.interceptor.I18nInterceptor] -
requested_locale=null
*
The interceptor looks like this:*
public String intercept(ActionInvocation invocation) throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String result = null;
        try {
            logger.debug("Invoking action, looking for exceptions.");
            result = invocation.invoke();
            logger.debug("result = " + result);
            logger.debug("No exceptions caught");
        } catch (Exception ex) {
            logger.debug("Exceptions caught");
            ex.printStackTrace();
            ......
        }
        return result;
}

Reply via email to