You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "CRANFORD, CHRIS" <Ch...@setech.com> on 2010/01/27 00:04:14 UTC

Chain Getting Original URI

Our Struts2 application has java.lang.Exception mapped to a global
result called 'error'.  Our 'error' global result is setup as a CHAIN
type to send the user to our ExceptionHandlerAction.  This action is
designed to capture the exception, log it, email it to an administration
mailbox and then forward the user to our error.jsp page.

When ExceptionHandlerAction is invoked, I need to be able to find out
what the original request URI was so that it can be included in the log
and notification.  Is there a way to get the chain history and get the
first action invoked?  If so, could someone explain it to me?

I had originally set our base action to implement ServletRequestAware
and set the HttpServletRequest object, but unfortunately I was getting
NullPointerExceptions with findStaticResource() method.  

Thoughts?
Chris



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


Re: Chain Getting Original URI

Posted by Brian Thompson <el...@gmail.com>.
On Wed, Jan 27, 2010 at 9:25 AM, Dale Newfield <da...@newfield.org> wrote:

>
> P.S.:
> Patient:  Doctor, doctor!  It hurts when I do *this*.
> Doctor:  Stop doing that.
>
>
>

Hopefully *this* isn't something like "walking" ;)

Re: Chain Getting Original URI

Posted by Dale Newfield <da...@newfield.org>.
CRANFORD, CHRIS wrote:
> That doesn't solve my original problem Gabriel.

It does if you are not tied to using chaining, which is almost always a 
bad idea.  Why isn't this implemented simply as an interceptor?

-Dale

P.S.:
Patient:  Doctor, doctor!  It hurts when I do *this*.
Doctor:  Stop doing that.

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


Re: Chain Getting Original URI

Posted by Brian Thompson <el...@gmail.com>.
The original Action that threw the exception ought to be included in the
stack trace.  That wouldn't easily lend itself to auto-parsing though.

You might be able to pass the request URI to teh error-handler with
something like this in struts.xml:

            <result name="error" type="chain">
                <param name="actionName">errorHandler</param>
                <param name="namespace">/</param>
                <param name="method">execute</param>
                <param name="requestUri">${request.requestURI}</param>
            </result>

(making sure that your original action classes have an appropriate public
getRequest() method)

* I haven't tested the above error-handling config, but I am using the
<param name="foo">${bar}</param> format in some other results.

-Brian



On Wed, Jan 27, 2010 at 8:05 AM, CRANFORD, CHRIS
<Ch...@setech.com>wrote:

>
> That doesn't solve my original problem Gabriel.
>
> What I need is a way that I can determine which Action threw the exception
> so that I could include that Request URI in the exception email and logged
> entry.
>
> I think if I use a redirect result type, to Struts when it redirects it is
> considered a new request and thus I loose what the original action was that
> created the exception in the first place.
>
> Hmm - Anyone else have any thoughts or suggestions?
>
> Chris
>
>
> -----Original Message-----
> From: Gabriel Belingueres [mailto:belingueres@gmail.com]
> Sent: Tuesday, January 26, 2010 8:06 PM
> To: Struts Users Mailing List
> Subject: Re: Chain Getting Original URI
>
> (I found the chain result type somewhat problematic, so I avoid it
> every time I can.)
>
> Having said that, if your action ONLY captures the exception, log it,
> email it and then forward the output to an error.jsp page, AND you are
> using Log4J you may find useful to attach more than one appender to
> the log category (one that logs it to some file, and other that emails
> it, see the SMTPAppender), then you could avoid the chained action
> execution.
>
> 2010/1/26 CRANFORD, CHRIS <Ch...@setech.com>:
> >
> > Our Struts2 application has java.lang.Exception mapped to a global
> > result called 'error'.  Our 'error' global result is setup as a CHAIN
> > type to send the user to our ExceptionHandlerAction.  This action is
> > designed to capture the exception, log it, email it to an administration
> > mailbox and then forward the user to our error.jsp page.
> >
> > When ExceptionHandlerAction is invoked, I need to be able to find out
> > what the original request URI was so that it can be included in the log
> > and notification.  Is there a way to get the chain history and get the
> > first action invoked?  If so, could someone explain it to me?
> >
> > I had originally set our base action to implement ServletRequestAware
> > and set the HttpServletRequest object, but unfortunately I was getting
> > NullPointerExceptions with findStaticResource() method.
> >
> > Thoughts?
> > Chris
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: Chain Getting Original URI

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
That doesn't solve my original problem Gabriel.  

What I need is a way that I can determine which Action threw the exception so that I could include that Request URI in the exception email and logged entry.

I think if I use a redirect result type, to Struts when it redirects it is considered a new request and thus I loose what the original action was that created the exception in the first place.

Hmm - Anyone else have any thoughts or suggestions?

Chris


-----Original Message-----
From: Gabriel Belingueres [mailto:belingueres@gmail.com] 
Sent: Tuesday, January 26, 2010 8:06 PM
To: Struts Users Mailing List
Subject: Re: Chain Getting Original URI

(I found the chain result type somewhat problematic, so I avoid it
every time I can.)

Having said that, if your action ONLY captures the exception, log it,
email it and then forward the output to an error.jsp page, AND you are
using Log4J you may find useful to attach more than one appender to
the log category (one that logs it to some file, and other that emails
it, see the SMTPAppender), then you could avoid the chained action
execution.

2010/1/26 CRANFORD, CHRIS <Ch...@setech.com>:
>
> Our Struts2 application has java.lang.Exception mapped to a global
> result called 'error'.  Our 'error' global result is setup as a CHAIN
> type to send the user to our ExceptionHandlerAction.  This action is
> designed to capture the exception, log it, email it to an administration
> mailbox and then forward the user to our error.jsp page.
>
> When ExceptionHandlerAction is invoked, I need to be able to find out
> what the original request URI was so that it can be included in the log
> and notification.  Is there a way to get the chain history and get the
> first action invoked?  If so, could someone explain it to me?
>
> I had originally set our base action to implement ServletRequestAware
> and set the HttpServletRequest object, but unfortunately I was getting
> NullPointerExceptions with findStaticResource() method.
>
> Thoughts?
> Chris
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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




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


Re: Chain Getting Original URI

Posted by Gabriel Belingueres <be...@gmail.com>.
(I found the chain result type somewhat problematic, so I avoid it
every time I can.)

Having said that, if your action ONLY captures the exception, log it,
email it and then forward the output to an error.jsp page, AND you are
using Log4J you may find useful to attach more than one appender to
the log category (one that logs it to some file, and other that emails
it, see the SMTPAppender), then you could avoid the chained action
execution.

2010/1/26 CRANFORD, CHRIS <Ch...@setech.com>:
>
> Our Struts2 application has java.lang.Exception mapped to a global
> result called 'error'.  Our 'error' global result is setup as a CHAIN
> type to send the user to our ExceptionHandlerAction.  This action is
> designed to capture the exception, log it, email it to an administration
> mailbox and then forward the user to our error.jsp page.
>
> When ExceptionHandlerAction is invoked, I need to be able to find out
> what the original request URI was so that it can be included in the log
> and notification.  Is there a way to get the chain history and get the
> first action invoked?  If so, could someone explain it to me?
>
> I had originally set our base action to implement ServletRequestAware
> and set the HttpServletRequest object, but unfortunately I was getting
> NullPointerExceptions with findStaticResource() method.
>
> Thoughts?
> Chris
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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