Re: ensuring valid forwards

2005-06-14 Thread Adam Hardy
The best way that I have found to counter this is to stick rigidly to a 
limited set of forward names, such as 'display', 'failed', 'insert', 
'delete'.  Hard-code them in a utility class as string finals, or as an 
enum if you use jdk 1.5.


Make it part of your coding convention only to refer to map forwards 
from the utility class, so you are using only these strings as forward 
names.


To avoid the problem with the blank page, set up global forwards with 
those names as well, and send them to an error page with an obvious 
error msg. The global forwards will be used by default when there is no 
local map-forward in your action mapping.


I know there are often situations where a page has many possible 
consequent actions so you might not want to define your map-forward name 
set so rigidly. However such pages are big and cumbersome with lots of 
command buttons and I prefer to break them down into smaller pages.


Regards
Adam






On 13/06/05 21:15nbsp;Hubert Rabago wrote:

I recently checked in a change that would log a warning if
mapping.findForward was called with a forward name that wasn't
recognized.  This change didn't make it to the 1.2.7 release, but is
available from nightly builds.  Apart from that, it wouldn't be too
hard to customize/extend your Struts installation to handle it the way
you'd wish.  You can use a custom request processor that'd log or
redirect or even use a custom ActionMapping class that can intercept
findForward() calls.

Hubert


On 6/13/05, Dan Tenenbaum [EMAIL PROTECTED] wrote:


My codebase has a lot of lines like this in struts actions:
return mapping.findForward(foo);

If I make a typo and it turns out that foo is not a valid forward
according to the struts config file, when I hit the action in the
browser, I get a blank page. Not my designated error page.

Is there some sort of struts-centric way to ensure that an exception
is thrown and my error page appears? I just want to know if there is
an existing mechanism to do this. I could easily write a method to do
it (to be called instead of mapping.findForward()) but it seems that
this is something Struts should handle.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-14 Thread Dave Newton

David Whipple wrote:


I would really like to see this as well.
 


+1

I had a very convoluted solution involving pre-processing my 
java/jsp/xml files (mostly for the automagic creation of web app 
documentation along with the bulk of CRUD actions/form 
pre-population/etc.) but an exception might be handy.


Should it be configurable?

Dave



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-14 Thread Frank W. Zammetti
FYI, just added Bugzilla ticket # 35361 regarding this.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Tue, June 14, 2005 7:53 am, David Whipple said:
 I would really like to see this as well.





  Frank W.
  Zammetti
  [EMAIL PROTECTED]  To
  com  Struts Users Mailing List
user@struts.apache.org
  06/13/2005 05:59   cc
  PM
Subject
Re: ensuring valid forwards
  Please respond to
Struts Users
Mailing List
  [EMAIL PROTECTED]
   he.org






 Yeah, that seemed a little too easy :)

 I would think it should throw an exception... Any Struts devs out there
 have an opinion?  I know someone (I forget who, sorry!) just mentioned
 they added a warning that didn't make it into 1.2.7... A warning is
 good, but I would personally think an exception would be better because
 it's a pretty severe situation that deserves immediate attention (also a
 situation that theoretically would never happen outside development...
 at least, QA procedures better make that true! :) ).

 Frank

 Dan Tenenbaum wrote:
 On 6/13/05, Frank W. Zammetti [EMAIL PROTECTED] wrote:

But again, I'm not certain this type of problem will be caught because
 I'm
not even sure an exception is thrown in such a case.  If it isn't that
strikes me as a bug.  Anyone else know for sure?



 I don't think it does throw an exception. I tried putting just the
 findForward() line in a try/catch block and nothing was thrown. Also,
 no stack traces appear in my tomcat log except a broken pipe error
 when trying to render the error page (there is nothing weird in the
 error page itself that would cause this).

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






 --
 Frank W. Zammetti
 Founder and Chief Software Architect
 Omnytex Technologies
 http://www.omnytex.com


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ensuring valid forwards

2005-06-13 Thread Dan Tenenbaum
My codebase has a lot of lines like this in struts actions:
return mapping.findForward(foo);

If I make a typo and it turns out that foo is not a valid forward
according to the struts config file, when I hit the action in the
browser, I get a blank page. Not my designated error page.

Is there some sort of struts-centric way to ensure that an exception
is thrown and my error page appears? I just want to know if there is
an existing mechanism to do this. I could easily write a method to do
it (to be called instead of mapping.findForward()) but it seems that
this is something Struts should handle.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-13 Thread Frank W. Zammetti
You can configure a global exception handler, although I'm not 100% sure
it will catch this type of problem.

You can find the documentation online in the usual place, but it basically
amounts to this in struts-config:

  global-exceptions
exception handler=com.my.company.handlers.GlobalExceptionHandler
type=java.lang.Exception
key=key_is_required_by_dtd_but_this_app_does_not_need_it_so_this_is_just_a_dummy_value
/
  /global-exceptions

As the rather long text indicates, key is required, but at least in my
case I have never used it, so I just stick any old value in there.  Come
to think of it, I am not even sure how it is meant to be used!

Beyond that, your exception handler class has to extend ExceptionHandler,
and beyond that it looks very much like an Action with a slightly
different execute() signature:


public ActionForward execute(Exception e, ExceptionConfig config,
   ActionMapping mapping, ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException

You can do whatever you like, and ultimately return a forward to your
exception page... I suggest getting this particular forward right at least
:) LOL

But again, I'm not certain this type of problem will be caught because I'm
not even sure an exception is thrown in such a case.  If it isn't that
strikes me as a bug.  Anyone else know for sure?

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Mon, June 13, 2005 3:45 pm, Dan Tenenbaum said:
 My codebase has a lot of lines like this in struts actions:
 return mapping.findForward(foo);

 If I make a typo and it turns out that foo is not a valid forward
 according to the struts config file, when I hit the action in the
 browser, I get a blank page. Not my designated error page.

 Is there some sort of struts-centric way to ensure that an exception
 is thrown and my error page appears? I just want to know if there is
 an existing mechanism to do this. I could easily write a method to do
 it (to be called instead of mapping.findForward()) but it seems that
 this is something Struts should handle.

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-13 Thread Hubert Rabago
I recently checked in a change that would log a warning if
mapping.findForward was called with a forward name that wasn't
recognized.  This change didn't make it to the 1.2.7 release, but is
available from nightly builds.  Apart from that, it wouldn't be too
hard to customize/extend your Struts installation to handle it the way
you'd wish.  You can use a custom request processor that'd log or
redirect or even use a custom ActionMapping class that can intercept
findForward() calls.

Hubert


On 6/13/05, Dan Tenenbaum [EMAIL PROTECTED] wrote:
 My codebase has a lot of lines like this in struts actions:
 return mapping.findForward(foo);
 
 If I make a typo and it turns out that foo is not a valid forward
 according to the struts config file, when I hit the action in the
 browser, I get a blank page. Not my designated error page.
 
 Is there some sort of struts-centric way to ensure that an exception
 is thrown and my error page appears? I just want to know if there is
 an existing mechanism to do this. I could easily write a method to do
 it (to be called instead of mapping.findForward()) but it seems that
 this is something Struts should handle.
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-13 Thread Dan Tenenbaum
On 6/13/05, Frank W. Zammetti [EMAIL PROTECTED] wrote:
 But again, I'm not certain this type of problem will be caught because I'm
 not even sure an exception is thrown in such a case.  If it isn't that
 strikes me as a bug.  Anyone else know for sure?
 

I don't think it does throw an exception. I tried putting just the
findForward() line in a try/catch block and nothing was thrown. Also,
no stack traces appear in my tomcat log except a broken pipe error
when trying to render the error page (there is nothing weird in the
error page itself that would cause this).

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ensuring valid forwards

2005-06-13 Thread Michael Jouravlev
It was discussed, but I could not find a bug in Bugzilla. Yep,
choosing between an exception and blank screen, I would prefer an
exception with forward name.

Michael.

On 6/13/05, Frank W. Zammetti [EMAIL PROTECTED] wrote:
 Yeah, that seemed a little too easy :)
 
 I would think it should throw an exception... Any Struts devs out there
 have an opinion?  I know someone (I forget who, sorry!) just mentioned
 they added a warning that didn't make it into 1.2.7... A warning is
 good, but I would personally think an exception would be better because
 it's a pretty severe situation that deserves immediate attention (also a
 situation that theoretically would never happen outside development...
 at least, QA procedures better make that true! :) ).
 
 Frank
 
 Dan Tenenbaum wrote:
  On 6/13/05, Frank W. Zammetti [EMAIL PROTECTED] wrote:
 
 But again, I'm not certain this type of problem will be caught because I'm
 not even sure an exception is thrown in such a case.  If it isn't that
 strikes me as a bug.  Anyone else know for sure?
 
 
 
  I don't think it does throw an exception. I tried putting just the
  findForward() line in a try/catch block and nothing was thrown. Also,
  no stack traces appear in my tomcat log except a broken pipe error
  when trying to render the error page (there is nothing weird in the
  error page itself that would cause this).
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 
 --
 Frank W. Zammetti
 Founder and Chief Software Architect
 Omnytex Technologies
 http://www.omnytex.com
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]