You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Louis Voo <jl...@yahoo.com> on 2009/08/25 18:43:06 UTC

how to get exception stack after redirect to action

Hi,

What I'm trying to do is when exception happen, it redirect to ExceptionHandlingAction and do something extra like sending email. My question are
1) How to get the exception in ExceptionHandlingAction ? I've this setter in the action public void setException(Exception exception), but nothing is set
2) How to get the original request? I want to print out all the request parameters which user submit.
3) If I use result type "chain" I got this error message:
 Infinite recursion detected:
[/exception/exception!execute,
/exception/ExceptionHandling, /exception/ExceptionHandling]
- [unknown location]


Here is my configuration:

                <global-results> 
<result name="errorAction" type="redirectAction">ExceptionHandling</result>
<result name="error">/WEB-INF/pages/error/Error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="errorAction" />
</global-exception-mappings> 
<action name="ExceptionHandling" class="demo.action.ExceptionHandlingAction"/>



Thanks
Louis

Re: how to get exception stack after redirect to action

Posted by ma...@yahoo.com.
Thanks, I'll try your solution.

Regards
Louis


________________________________
From: Greg Lindholm <gr...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Tuesday, August 25, 2009 6:21:00 PM
Subject: Re: how to get exception stack after redirect to action

The exception will not persist across the redirect unless you were to save
it in the session. If you want to do this then you could take a look at [1]
RedirectMessageInterceptor for an example of how to saveand retrieve the
exception in the session.

However, what I do to handle exceptions is have a global result "error"
which just goes to a jsp page.
    <global-results>
      <result name="error">/struts/Error.jsp</result>
    </global-results>

In the Error.jsp page I use some ognl to call a method "notifyAdmiin()" and
pass it the exception.

<%-- Dummy expression to notify the admin --%>
<s:if test="notifyAdmin(exception)"></s:if>

I can than do any handling of the exception in my notifyAdmin() method, this
method is in my base Action class so is available from all actions.


[1]
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/

On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo <jl...@yahoo.com> wrote:

> Hi,
>
> What I'm trying to do is when exception happen, it redirect to
> ExceptionHandlingAction and do something extra like sending email. My
> question are
> 1) How to get the exception in ExceptionHandlingAction ? I've this setter
> in the action public void setException(Exception exception), but nothing is
> set
> 2) How to get the original request? I want to print out all the request
> parameters which user submit.
> 3) If I use result type "chain" I got this error message:
>  Infinite recursion detected:
> [/exception/exception!execute,
> /exception/ExceptionHandling, /exception/ExceptionHandling]
> - [unknown location]
>
>
> Here is my configuration:
>
>                <global-results>
> <result name="errorAction" type="redirectAction">ExceptionHandling</result>
> <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
> <exception-mapping exception="java.lang.Exception"
> result="errorAction" />
> </global-exception-mappings>
> <action name="ExceptionHandling"
> class="demo.action.ExceptionHandlingAction"/>
>
>
>
> Thanks
> Louis

Re: how to get exception stack after redirect to action

Posted by Greg Lindholm <gr...@gmail.com>.
You get the exception because following an exception the exception is put on
the ValueStack with name 'exception'.  see [1].

As for why "request is null" you are asking to find an object on the
ValueStack named 'request' and I don't know if there is such an object.

Are looking for the HttpServletRequest object?

I'm sure it's in the VS somewhere (I don't off hand know what it's called)
maybe someone else can answer?



[1] http://struts.apache.org/2.1.6/docs/exception-configuration.html

On Wed, Aug 26, 2009 at 11:10 AM, <ma...@yahoo.com> wrote:

> I tried this
>
> <s:if test="notify(exception,request)"></s:if>
>
> In the action, I receive the exception but not the request, request is
> null, why?
>
> -Louis
>
>
>
> ________________________________
> From: Greg Lindholm <gr...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Tuesday, August 25, 2009 6:21:00 PM
> Subject: Re: how to get exception stack after redirect to action
>
> The exception will not persist across the redirect unless you were to save
> it in the session. If you want to do this then you could take a look at [1]
> RedirectMessageInterceptor for an example of how to saveand retrieve the
> exception in the session.
>
> However, what I do to handle exceptions is have a global result "error"
> which just goes to a jsp page.
>    <global-results>
>      <result name="error">/struts/Error.jsp</result>
>    </global-results>
>
> In the Error.jsp page I use some ognl to call a method "notifyAdmiin()" and
> pass it the exception.
>
> <%-- Dummy expression to notify the admin --%>
> <s:if test="notifyAdmin(exception)"></s:if>
>
> I can than do any handling of the exception in my notifyAdmin() method,
> this
> method is in my base Action class so is available from all actions.
>
>
> [1]
>
> http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/
>
> On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo <jl...@yahoo.com> wrote:
>
> > Hi,
> >
> > What I'm trying to do is when exception happen, it redirect to
> > ExceptionHandlingAction and do something extra like sending email. My
> > question are
> > 1) How to get the exception in ExceptionHandlingAction ? I've this setter
> > in the action public void setException(Exception exception), but nothing
> is
> > set
> > 2) How to get the original request? I want to print out all the request
> > parameters which user submit.
> > 3) If I use result type "chain" I got this error message:
> >  Infinite recursion detected:
> > [/exception/exception!execute,
> > /exception/ExceptionHandling, /exception/ExceptionHandling]
> > - [unknown location]
> >
> >
> > Here is my configuration:
> >
> >                <global-results>
> > <result name="errorAction"
> type="redirectAction">ExceptionHandling</result>
> > <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> > </global-results>
> >
> > <global-exception-mappings>
> > <exception-mapping exception="java.lang.Exception"
> > result="errorAction" />
> > </global-exception-mappings>
> > <action name="ExceptionHandling"
> > class="demo.action.ExceptionHandlingAction"/>
> >
> >
> >
> > Thanks
> > Louis
>

Re: how to get exception stack after redirect to action

Posted by ma...@yahoo.com.
I tried this

<s:if test="notify(exception,request)"></s:if>

In the action, I receive the exception but not the request, request is null, why?

-Louis



________________________________
From: Greg Lindholm <gr...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Tuesday, August 25, 2009 6:21:00 PM
Subject: Re: how to get exception stack after redirect to action

The exception will not persist across the redirect unless you were to save
it in the session. If you want to do this then you could take a look at [1]
RedirectMessageInterceptor for an example of how to saveand retrieve the
exception in the session.

However, what I do to handle exceptions is have a global result "error"
which just goes to a jsp page.
    <global-results>
      <result name="error">/struts/Error.jsp</result>
    </global-results>

In the Error.jsp page I use some ognl to call a method "notifyAdmiin()" and
pass it the exception.

<%-- Dummy expression to notify the admin --%>
<s:if test="notifyAdmin(exception)"></s:if>

I can than do any handling of the exception in my notifyAdmin() method, this
method is in my base Action class so is available from all actions.


[1]
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/

On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo <jl...@yahoo.com> wrote:

> Hi,
>
> What I'm trying to do is when exception happen, it redirect to
> ExceptionHandlingAction and do something extra like sending email. My
> question are
> 1) How to get the exception in ExceptionHandlingAction ? I've this setter
> in the action public void setException(Exception exception), but nothing is
> set
> 2) How to get the original request? I want to print out all the request
> parameters which user submit.
> 3) If I use result type "chain" I got this error message:
>  Infinite recursion detected:
> [/exception/exception!execute,
> /exception/ExceptionHandling, /exception/ExceptionHandling]
> - [unknown location]
>
>
> Here is my configuration:
>
>                <global-results>
> <result name="errorAction" type="redirectAction">ExceptionHandling</result>
> <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
> <exception-mapping exception="java.lang.Exception"
> result="errorAction" />
> </global-exception-mappings>
> <action name="ExceptionHandling"
> class="demo.action.ExceptionHandlingAction"/>
>
>
>
> Thanks
> Louis

Re: how to get exception stack after redirect to action

Posted by Greg Lindholm <gr...@gmail.com>.
The exception will not persist across the redirect unless you were to save
it in the session. If you want to do this then you could take a look at [1]
RedirectMessageInterceptor for an example of how to saveand retrieve the
exception in the session.

However, what I do to handle exceptions is have a global result "error"
which just goes to a jsp page.
    <global-results>
      <result name="error">/struts/Error.jsp</result>
    </global-results>

In the Error.jsp page I use some ognl to call a method "notifyAdmiin()" and
pass it the exception.

<%-- Dummy expression to notify the admin --%>
<s:if test="notifyAdmin(exception)"></s:if>

I can than do any handling of the exception in my notifyAdmin() method, this
method is in my base Action class so is available from all actions.


[1]
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/

On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo <jl...@yahoo.com> wrote:

> Hi,
>
> What I'm trying to do is when exception happen, it redirect to
> ExceptionHandlingAction and do something extra like sending email. My
> question are
> 1) How to get the exception in ExceptionHandlingAction ? I've this setter
> in the action public void setException(Exception exception), but nothing is
> set
> 2) How to get the original request? I want to print out all the request
> parameters which user submit.
> 3) If I use result type "chain" I got this error message:
>  Infinite recursion detected:
> [/exception/exception!execute,
> /exception/ExceptionHandling, /exception/ExceptionHandling]
> - [unknown location]
>
>
> Here is my configuration:
>
>                <global-results>
> <result name="errorAction" type="redirectAction">ExceptionHandling</result>
> <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
> <exception-mapping exception="java.lang.Exception"
> result="errorAction" />
> </global-exception-mappings>
> <action name="ExceptionHandling"
> class="demo.action.ExceptionHandlingAction"/>
>
>
>
> Thanks
> Louis

Re: how to get exception stack after redirect to action

Posted by ma...@yahoo.com.
Ya, I understand the redirect will create a new request, that is why I also try to use chain result type, but it gave error.
Is it a good idea to extend ExceptionMappingInterceptor and build a custom exception interceptor? 

Louis



________________________________
From: Wes Wannemacher <we...@wantii.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Tuesday, August 25, 2009 6:14:43 PM
Subject: Re: how to get exception stack after redirect to action

The core problem here is that you are redirecting... A redirect
generates a whole new request and all of your previous context is
lost. I would say find a different way to pass the exception around,
but keep in mind that you can run into exception bubbling problems
(such as your exception mapping throwing an exception).

-Wes

On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo<jl...@yahoo.com> wrote:
> Hi,
>
> What I'm trying to do is when exception happen, it redirect to ExceptionHandlingAction and do something extra like sending email. My question are
> 1) How to get the exception in ExceptionHandlingAction ? I've this setter in the action public void setException(Exception exception), but nothing is set
> 2) How to get the original request? I want to print out all the request parameters which user submit.
> 3) If I use result type "chain" I got this error message:
>  Infinite recursion detected:
> [/exception/exception!execute,
> /exception/ExceptionHandling, /exception/ExceptionHandling]
> - [unknown location]
>
>
> Here is my configuration:
>
>                <global-results>
> <result name="errorAction" type="redirectAction">ExceptionHandling</result>
> <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
> <exception-mapping exception="java.lang.Exception"
> result="errorAction" />
> </global-exception-mappings>
> <action name="ExceptionHandling" class="demo.action.ExceptionHandlingAction"/>
>
>
>
> Thanks
> Louis



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Re: how to get exception stack after redirect to action

Posted by Wes Wannemacher <we...@wantii.com>.
The core problem here is that you are redirecting... A redirect
generates a whole new request and all of your previous context is
lost. I would say find a different way to pass the exception around,
but keep in mind that you can run into exception bubbling problems
(such as your exception mapping throwing an exception).

-Wes

On Tue, Aug 25, 2009 at 12:43 PM, Louis Voo<jl...@yahoo.com> wrote:
> Hi,
>
> What I'm trying to do is when exception happen, it redirect to ExceptionHandlingAction and do something extra like sending email. My question are
> 1) How to get the exception in ExceptionHandlingAction ? I've this setter in the action public void setException(Exception exception), but nothing is set
> 2) How to get the original request? I want to print out all the request parameters which user submit.
> 3) If I use result type "chain" I got this error message:
>  Infinite recursion detected:
> [/exception/exception!execute,
> /exception/ExceptionHandling, /exception/ExceptionHandling]
> - [unknown location]
>
>
> Here is my configuration:
>
>                <global-results>
> <result name="errorAction" type="redirectAction">ExceptionHandling</result>
> <result name="error">/WEB-INF/pages/error/Error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
> <exception-mapping exception="java.lang.Exception"
> result="errorAction" />
> </global-exception-mappings>
> <action name="ExceptionHandling" class="demo.action.ExceptionHandlingAction"/>
>
>
>
> Thanks
> Louis



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org