You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paweł Wielgus <po...@gmail.com> on 2009/06/23 10:41:48 UTC

Re: Exceptions thrown by constructor different from those thown by execute() ?

Hi Jan,
i'm not going into details of your solution but interceptors are a way
better tool for that job, search the list for authentication subjects.
You can also use libraries like acegi or similiar.

Best greetings,
Pawel Wielgus.

2009/6/22, Jan T. Kim <j....@uea.ac.uk>:
> Dear All,
>
> I'm trying to use exceptions to make sure a user is logged in, using
> struts 2.1.6. My idea is
>
>     * a subclass of ActionSupport that checks that a user is logged
>       in, and throws a NotLoggedInException if that's not the case
>
>     * all other action handlers are subclasses of that subclass
>
>     * use a global exception mapping to map the NotLoggedInException
>       to a suitable login action
>
> I can't seem to get this to work, I get a 500 response with a stack
> trace, saying "Unable to instantiate Action". If I arrange for the
> constructor to complete without an exception and for the execute()
> method to throw a NotLoggedInException, I get to the login action as
> I intend.
>
> So it seems that only exceptions thrown by execute(), but not those
> thrown by constructors, are handled as specified by the exception
> mappings (at least the global ones) -- is that right? And if so, why
> is that?
>
> Or do you thing I've just made some silly mistake here?
>
> Best regards, Jan
> --
>  +- Jan T. Kim -------------------------------------------------------+
>  |             email: j.kim@uea.ac.uk                                 |
>  |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
>  *-----=<  hierarchical systems are for files, not for humans  >=-----*
>
> ---------------------------------------------------------------------
> 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: Exceptions thrown by constructor different from those thown by execute() ?

Posted by Dave Newton <ne...@yahoo.com>.
Wes Wannemacher wrote:
> On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
> [...]
>> From a philosophical perspective, though -- no clue, I don't have a lot of
>> insight into why the devs make all the decisions they make.
>>
> [...]
> 
> The decisions I make are usually heavily weighted by how impressed
> girls will be :)

Hey, wait, that works for you?!

I've been following that strategy for years and so far it hasn't paid 
off. Maybe now that I can do really sexy byte-code manipulation I'll 
finally get that happy ending.

Dave

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by Wes Wannemacher <we...@wantii.com>.
On Tue, Jun 23, 2009 at 9:56 AM, Jan T. Kim<j....@uea.ac.uk> wrote:
[...]
> I (again) agree that an interceptor is more suited for security. I'm
> undecided whether this is an issue suitable for a JIRA, it's more that
> based on the documentation on Exception Configuration
> [http://struts.apache.org/2.0.14/docs/exception-configuration.html],
[...]

Based on the documentation, except for the second sentence on the page -

"The core idea is that an Exception thrown during the Action method
can be automatically caught and mapped to a predefined Result."

Don't worry about filing a JIRA, I can see where you are coming from.
I'd likely take the time to look at it since the difference between
throwing an exception in the action method and the action constructor
is subtle and I think many people want to use the exception-mapping to
catch any and all sorts of errors.

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by "Jan T. Kim" <j....@uea.ac.uk>.
On Tue, Jun 23, 2009 at 09:03:22AM -0400, Wes Wannemacher wrote:
> On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
> [...]
> > From a philosophical perspective, though -- no clue, I don't have a lot of
> > insight into why the devs make all the decisions they make.
> >
> [...]
> 
> The decisions I make are usually heavily weighted by how impressed
> girls will be :)
> 
> I would go against adding security via exceptions thrown by a
> constructor. In the default ObjectFactory for xwork, the flow for
> creating instances of classes is pretty easy to follow. The exception
> handling is deferred to callers (as evidenced by the various "throws
> Exception" qualifiers on the methods). The main reason I would be
> against it is that you aren't the one calling "new" on the classes. I
> can appreciate what you are trying to do, so file a JIRA and when we
> have time to investigate, we could probably implement it, but to solve
> your problem, the best bet is an interceptor.

I (again) agree that an interceptor is more suited for security. I'm
undecided whether this is an issue suitable for a JIRA, it's more that
based on the documentation on Exception Configuration
[http://struts.apache.org/2.0.14/docs/exception-configuration.html], I
would have anticipated that exceptions would be mapped as configured
by exception-mapping elements regardless of whether they're thrown
by execute() or by a constructor.

My guess is it's more likely this is an issue for documentation,
or perhaps it's a (not exceedingly) FAQ. Or perhaps it's just me,
as I've only started with struts a few weeks ago.

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by mu...@aol.com.
I see your point that there has to be some design to handle? that contingency
(exceptions coming from the constructor) but with so many opportunities for
us to do things via interceptors I would let the framework have a total monopoly
on the constructors. 

Essentially we (application developers) should be into
how the action behaves rather than how it comes into being.

But I do see your point that for completeness there has to be some definite
behavior that takes place if the exception is thrown.
Chris


-----Original Message-----
From: Jan T. Kim <j....@uea.ac.uk>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Thu, Jun 25, 2009 9:05 am
Subject: Re: Exceptions thrown by constructor different from those thown by execute() ?



Dear Chris,

On Thu, Jun 25, 2009 at 08:23:30AM -0400, musomesa@aol.com wrote:
> 
>  I am with the devs on this one -- typically the constructor of an object 
whose life cycle is managed by 
> the framework is off limits -- you wouldn't write code to throw exceptions 
from a servlet or
> EJB etc.

I agree that from an EJB provider's angle its quite possible to argue
that session bean's constructors shouldn't throw exceptions. From an
application assembler's perspective, though, I'd expect that a global
exception mapping would handle all exceptions of the specified class,
regardless of whether they are thrown by constructors or other methods
(and regardless of whether the exception is considered legitimate or
reasonable).

Best regards, Jan

> 
>  
> 
> -----Original Message-----
> From: Wes Wannemacher <we...@wantii.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Tue, Jun 23, 2009 9:03 am
> Subject: Re: Exceptions thrown by constructor different from those thown by  
execute() ?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
> [...]
> > From a philosophical perspective, though -- no clue, I don't have a lot of
> > insight into why the devs make all the decisions they make.
> >
> [...]
> 
> The decisions I make are usually heavily weighted by how impressed
> girls will be :)
> 
> I would go against adding security via exceptions thrown by a
> constructor. In the default ObjectFactory for xwork, the flow for
> creating instances of classes is pretty easy to follow. The exception
> handling is deferred to callers (as evidenced by the various "throws
> Exception" qualifiers on the methods). The main reason I would be
> against it is that you aren't the one calling "new" on the classes. I
> can appreciate what you are trying to do, so file a JIRA and when we
> have time to investigate, we could probably implement it, but to solve
> your problem, the best bet is an interceptor.
> 
> -Wes
> 
> -- 
> Wes Wannemacher
> Author - Struts 2 In Pr
actice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
>  
> 

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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



Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, Jun 25, 2009 at 9:05 AM, Jan T. Kim<j....@uea.ac.uk> wrote:
>
> I agree that from an EJB provider's angle its quite possible to argue
> that session bean's constructors shouldn't throw exceptions. From an
> application assembler's perspective, though, I'd expect that a global
> exception mapping would handle all exceptions of the specified class,
> regardless of whether they are thrown by constructors or other methods
> (and regardless of whether the exception is considered legitimate or
> reasonable).
>
> Best regards, Jan
>

I'm with you here, I plan on making this work in 2.1.8 (or at least
trying really hard). You will be hard-pressed to find people to agree
that throwing exceptions in your constructor as a way of enforcing
security is the right thing to do, *but* "global-exception-mappings"
is an ambiguous feature name, unless we are catching exceptions during
access and creation. So, although I don't quite agree with your
design, I still agree that it is something we should change... (Is
that a political explanation or what?)

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by "Jan T. Kim" <j....@uea.ac.uk>.
Dear Chris,

On Thu, Jun 25, 2009 at 08:23:30AM -0400, musomesa@aol.com wrote:
> 
>  I am with the devs on this one -- typically the constructor of an object whose life cycle is managed by 
> the framework is off limits -- you wouldn't write code to throw exceptions from a servlet or
> EJB etc.

I agree that from an EJB provider's angle its quite possible to argue
that session bean's constructors shouldn't throw exceptions. From an
application assembler's perspective, though, I'd expect that a global
exception mapping would handle all exceptions of the specified class,
regardless of whether they are thrown by constructors or other methods
(and regardless of whether the exception is considered legitimate or
reasonable).

Best regards, Jan

> 
>  
> 
> -----Original Message-----
> From: Wes Wannemacher <we...@wantii.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Tue, Jun 23, 2009 9:03 am
> Subject: Re: Exceptions thrown by constructor different from those thown by  execute() ?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
> [...]
> > From a philosophical perspective, though -- no clue, I don't have a lot of
> > insight into why the devs make all the decisions they make.
> >
> [...]
> 
> The decisions I make are usually heavily weighted by how impressed
> girls will be :)
> 
> I would go against adding security via exceptions thrown by a
> constructor. In the default ObjectFactory for xwork, the flow for
> creating instances of classes is pretty easy to follow. The exception
> handling is deferred to callers (as evidenced by the various "throws
> Exception" qualifiers on the methods). The main reason I would be
> against it is that you aren't the one calling "new" on the classes. I
> can appreciate what you are trying to do, so file a JIRA and when we
> have time to investigate, we could probably implement it, but to solve
> your problem, the best bet is an interceptor.
> 
> -Wes
> 
> -- 
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
>  
> 

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by mu...@aol.com.
 I am with the devs on this one -- typically the constructor of an object whose life cycle is managed by 
the framework is off limits -- you wouldn't write code to throw exceptions from a servlet or
EJB etc.
Chris

 

-----Original Message-----
From: Wes Wannemacher <we...@wantii.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Tue, Jun 23, 2009 9:03 am
Subject: Re: Exceptions thrown by constructor different from those thown by  execute() ?










On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
[...]
> From a philosophical perspective, though -- no clue, I don't have a lot of
> insight into why the devs make all the decisions they make.
>
[...]

The decisions I make are usually heavily weighted by how impressed
girls will be :)

I would go against adding security via exceptions thrown by a
constructor. In the default ObjectFactory for xwork, the flow for
creating instances of classes is pretty easy to follow. The exception
handling is deferred to callers (as evidenced by the various "throws
Exception" qualifiers on the methods). The main reason I would be
against it is that you aren't the one calling "new" on the classes. I
can appreciate what you are trying to do, so file a JIRA and when we
have time to investigate, we could probably implement it, but to solve
your problem, the best bet is an interceptor.

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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




 


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by Wes Wannemacher <we...@wantii.com>.
On Tue, Jun 23, 2009 at 8:50 AM, Jim Kiley<jh...@summa-tech.com> wrote:
[...]
> From a philosophical perspective, though -- no clue, I don't have a lot of
> insight into why the devs make all the decisions they make.
>
[...]

The decisions I make are usually heavily weighted by how impressed
girls will be :)

I would go against adding security via exceptions thrown by a
constructor. In the default ObjectFactory for xwork, the flow for
creating instances of classes is pretty easy to follow. The exception
handling is deferred to callers (as evidenced by the various "throws
Exception" qualifiers on the methods). The main reason I would be
against it is that you aren't the one calling "new" on the classes. I
can appreciate what you are trying to do, so file a JIRA and when we
have time to investigate, we could probably implement it, but to solve
your problem, the best bet is an interceptor.

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

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


Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by Jim Kiley <jh...@summa-tech.com>.
Presumably the code calling execute() wraps it in a try/catch, but the call
that is instantiating the action in the first place doesn't do that.  You'd
have to look at the source to be sure, but of course that's the nice part
about working on open-source projects.
>From a philosophical perspective, though -- no clue, I don't have a lot of
insight into why the devs make all the decisions they make.

jk

On Tue, Jun 23, 2009 at 5:12 AM, Jan T. Kim <j....@uea.ac.uk> wrote:

> On Tue, Jun 23, 2009 at 06:41:48AM -0200, Pawe? Wielgus wrote:
> > Hi Jan,
> > i'm not going into details of your solution but interceptors are a way
> > better tool for that job, search the list for authentication subjects.
> > You can also use libraries like acegi or similiar.
>
> thanks for this pointer, I agree that this is probably a bad example
> as such ad-hoc development of authentication mechanisms isn't really
> a good idea.
>
> My question is about exception handling in general, though: Why does
> my handler work as expected when the exception is thrown by execute(),
> but not when it's thrown by the constructor?
>
> Having run into this, I'd like to understand it before moving on.
>
> Best regards, Jan
>
> > 2009/6/22, Jan T. Kim <j....@uea.ac.uk>:
> > > Dear All,
> > >
> > > I'm trying to use exceptions to make sure a user is logged in, using
> > > struts 2.1.6. My idea is
> > >
> > >     * a subclass of ActionSupport that checks that a user is logged
> > >       in, and throws a NotLoggedInException if that's not the case
> > >
> > >     * all other action handlers are subclasses of that subclass
> > >
> > >     * use a global exception mapping to map the NotLoggedInException
> > >       to a suitable login action
> > >
> > > I can't seem to get this to work, I get a 500 response with a stack
> > > trace, saying "Unable to instantiate Action". If I arrange for the
> > > constructor to complete without an exception and for the execute()
> > > method to throw a NotLoggedInException, I get to the login action as
> > > I intend.
> > >
> > > So it seems that only exceptions thrown by execute(), but not those
> > > thrown by constructors, are handled as specified by the exception
> > > mappings (at least the global ones) -- is that right? And if so, why
> > > is that?
> > >
> > > Or do you thing I've just made some silly mistake here?
> > >
> > > Best regards, Jan
> > > --
> > >  +- Jan T. Kim -------------------------------------------------------+
> > >  |             email: j.kim@uea.ac.uk
> |
> > >  |             WWW:   http://www.cmp.uea.ac.uk/people/jtk
> |
> > >  *-----=<  hierarchical systems are for files, not for humans  >=-----*
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
>
> --
>  +- Jan T. Kim -------------------------------------------------------+
>  |             email: j.kim@uea.ac.uk                                 |
>  |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
>  *-----=<  hierarchical systems are for files, not for humans  >=-----*
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Jim Kiley
Senior Technical Consultant | Summa
[p] 412.258.3346
http://www.summa-tech.com

Re: Exceptions thrown by constructor different from those thown by execute() ?

Posted by "Jan T. Kim" <j....@uea.ac.uk>.
On Tue, Jun 23, 2009 at 06:41:48AM -0200, Pawe? Wielgus wrote:
> Hi Jan,
> i'm not going into details of your solution but interceptors are a way
> better tool for that job, search the list for authentication subjects.
> You can also use libraries like acegi or similiar.

thanks for this pointer, I agree that this is probably a bad example
as such ad-hoc development of authentication mechanisms isn't really
a good idea.

My question is about exception handling in general, though: Why does
my handler work as expected when the exception is thrown by execute(),
but not when it's thrown by the constructor?

Having run into this, I'd like to understand it before moving on.

Best regards, Jan

> 2009/6/22, Jan T. Kim <j....@uea.ac.uk>:
> > Dear All,
> >
> > I'm trying to use exceptions to make sure a user is logged in, using
> > struts 2.1.6. My idea is
> >
> >     * a subclass of ActionSupport that checks that a user is logged
> >       in, and throws a NotLoggedInException if that's not the case
> >
> >     * all other action handlers are subclasses of that subclass
> >
> >     * use a global exception mapping to map the NotLoggedInException
> >       to a suitable login action
> >
> > I can't seem to get this to work, I get a 500 response with a stack
> > trace, saying "Unable to instantiate Action". If I arrange for the
> > constructor to complete without an exception and for the execute()
> > method to throw a NotLoggedInException, I get to the login action as
> > I intend.
> >
> > So it seems that only exceptions thrown by execute(), but not those
> > thrown by constructors, are handled as specified by the exception
> > mappings (at least the global ones) -- is that right? And if so, why
> > is that?
> >
> > Or do you thing I've just made some silly mistake here?
> >
> > Best regards, Jan
> > --
> >  +- Jan T. Kim -------------------------------------------------------+
> >  |             email: j.kim@uea.ac.uk                                 |
> >  |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
> >  *-----=<  hierarchical systems are for files, not for humans  >=-----*
> >
> > ---------------------------------------------------------------------
> > 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
> 

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: j.kim@uea.ac.uk                                 |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

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