Mea culpa ! ;) You're right ! The request ....
 I must be very tired ....(I'm entering in the 11th hour of work now).
 I'll kick myself home now :)

Thanks,
Ovidiu


----- Original Message ----- 
From: "Kris Schneider" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Thursday, November 20, 2003 6:56 PM
Subject: Re: Simulating multiple inheritance for Action and DispatchAction


Okay, I'll keep playing ;-). The ExceptionHandler provides the following method:

public ActionForward execute(Exception ex,
                             ExceptionConfig ae,
                             ActionMapping mapping,
                             ActionForm formInstance,
                             HttpServletRequest request,
                             HttpServletResponse response)
  throws ServletException

Don't you think there might be a way to get a handle to the ServletContext
through one of those args?

Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:

> Thanks anyway.
> In fact it would be a little bit difficult to use ExceptionHandler since it
> doesn't have a reference to the servlet. And I'm gonna tell you why I need
> it
> ..:).
> The so called GeneralImpl, implements a method to retrive error messages
> (based
> on their code) from database(I'm not using any internationalization) using
> the
> servlet context in which I'm storing an oracle connection pool
> (OracleOciConnectionPool created using a plugin).
>
> So all my error messages are retrivied from the database using this method
> (I
> know there is DBRessources which can integrates with struts but my
> requirements
> are to use the same and only OCI connection pool used by the rest of the
> application)
>
> The only solution to use ExceptionHandler, as far as I can see, would be to
> implement my own RequestProcessor and to modify processException method
> something like this
>
> processException(..........){
> ...................
>      try {
>             ExceptionHandler handler = (ExceptionHandler)
>             RequestUtils.applicationInstance(config.getHandler());
>             if(handler instanceof MyHandler){
>                 ((MyHandler)handler).setServlet(servlet);
>             }
>             return (handler.execute(exception, config, mapping, form,
>                                     request, response));
>         } catch (Exception e) {
>             throw new ServletException(e);
>         }
> }
> and in MyHandler I'll have a method to get the error messages from the db
> and
> the setServlet method.
> What do you think ? It could work ?
>
> Ovidiu
>
> ----- Original Message ----- 
> From: "Kris Schneider" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Thursday, November 20, 2003 6:06 PM
> Subject: Re: Simulating multiple inheritance for Action and DispatchAction
>
>
> Sorry, nothing to point you to off the top of my head, except for the
> struts-example app that ships with Struts. It illustrates the simplest
> usage:
>
> <action path="/logon"
>         type="org.apache.struts.webapp.example.LogonAction"
>         name="logonForm"
>         scope="session"
>         input="logon">
>   <exception key="expired.password"
>
> type="org.apache.struts.webapp.example.ExpiredPasswordException"
>              path="/changePassword.jsp"/>
> </action>
>
> Here, the default handler (org.apache.struts.action.ExceptionHandler) is used
> so
> the <exception> element omits the "handler" attribute. The default handler
> will
> take the value of the "key" attribute and use it to construct an
> ActionError
> instance. It will also use that key to add the error instance to an
> ActionErrors
> instance that will be stored in either request or session scope under
> Globals.ERROR_KEY. The default handler will then create an ActionForward
> based
> on the value of the "path" attribute (or it will use
> mapping.getInputForward()
> if "path" is not provided).
>
> Hm, that's a lot of verbage for the "simplest" case ;-)...
>
> Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:
>
> > In fact, in the catch(Exception ex) branch there should be a return
> > mapping.findForward("generalError"); which I didn't include in the
> example
> > .
> > But generally you're approach is better, and more appropriate.
> > Do yoy have any real examples on Exception handlers, or any links to
> which
> > you
> > may point me ?
> >
> > Thanks,
> > Ovidiu
> >
> > ----- Original Message ----- 
> > From: "Kris Schneider" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Thursday, November 20, 2003 4:36 PM
> > Subject: Re: Simulating multiple inheritance for Action and
> DispatchAction
> >
> >
> > Well, what if you don't provide a handler (or a standard servlet error
> page)?
> > An
> > unhandled exception will be propogated to the container which will return
> a
> > status code 500 to your users. I wouldn't really call the resulting
> generic
> > "internal server error" user friendly.
> >
> > BTW, your code for catching Exception just prints a stacktrace, logs a
> > message,
> > and then falls through to return whatever "forward" has been set to
> > (null?).
> >
> > Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:
> >
> > > For BaseException there is not really a need to catch it in BaseAction,
> > > because
> > > I'll have a handler, but for Exception I don't know. Is it a good
> > practice
> > > to
> > > declare may own handler?
> > >
> > > Ovidiu
> > >
> > > ----- Original Message ----- 
> > > From: "Kris Schneider" <[EMAIL PROTECTED]>
> > > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > > Sent: Thursday, November 20, 2003 4:02 PM
> > > Subject: Re: Simulating multiple inheritance for Action and
> > DispatchAction
> > >
> > >
> > > Why not just declare handlers for *both* BaseException and Exception in
> > > struts-config?
> > >
> > > Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:
> > >
> > > > I agree with you regarding the leading I ;
> > > > I've implemented the setServlet method after sending the mail :)
> > > > Yes you're right about GeneralImpl it must be final .
> > > > I'm overiding execute just for BaseAction of course :), and I do it
> to
> > > > catch
> > > > exception that are not applicational
> > > > Something like this
> > > >     try{
> > > >
> > > >         forward = executeAction(....);
> > > >     }catch(BaseException bex){
> > > >         log.error(bex);
> > > >         //to be catched by the handlers declared in struts-config.xml
> > > >         throw bex
> > > >     }catch(Exception ex){
> > > >         ex.printStackTrace();
> > > >         log.fatal(e);
> > > >     }
> > > >     return forward;
> > > >
> > > > Ovidiu
> > > >
> > > >
> > > > ----- Original Message ----- 
> > > > From: "Kris Schneider" <[EMAIL PROTECTED]>
> > > > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > > > Sent: Thursday, November 20, 2003 2:13 PM
> > > > Subject: Re: Simulating multiple inheritance for Action and
> > > DispatchAction
> > > >
> > > >
> > > > The general approach is probably fine, although naming interfaces
> with
> > a
> > > > leading
> > > > "I" makes me gag ;-). However, this seems like a bad idea:
> > > >
> > > > public abstract class BaseAction extends Action implements IGeneral {
> > > >   private static GeneralImpl general;
> > > >   public BaseAction() {
> > > >     general = new GeneralImpl(servlet);
> > > >   }
> > > > ...
> > > > }
> > > >
> > > > Every time an instance of BaseAction is created, the *static* field
> > > > "general"
> > > > gets reset. Also, where is BaseAction getting the "servlet" arg to
> pass
> > > to
> > > > the
> > > > GeneralImpl constructor? Instead, perhaps:
> > > >
> > > > public abstract class BaseAction extends Action implements IGeneral {
> > > >   private final IGeneral general;
> > > >   public BaseAction() {
> > > >     this.general = new GeneralImpl();
> > > >   }
> > > >   public void setServlet(ActionServlet servlet) {
> > > >     super.setServlet(servlet);
> > > >     this.general.setServlet(sevlet);
> > > >   }
> > > > ...
> > > > }
> > > >
> > > > Of course, that means adding a setServlet method to IGeneral and
> > > > GeneralImpl.
> > > > I'm also not sure why you'd override execute just to call
> > executeAction.
> > > > You
> > > > certainly wouldn't want to override DispatchAction's execute method,
> > > right?
> > > >
> > > > Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:
> > > >
> > > > > Hi,
> > > > > In my application I need to have my Actions and my DispatchActions.
> > > > > Each one of this actions must have the same base class in which I
> > have
> > > > > common
> > > > > methods to both of them.
> > > > > My solution is to first declare an interface IGeneral in which I'm
> > > > declaring
> > > > > the
> > > > > common methods, then create an implementation
> class,GeneralImpl.Next
> > > thind
> > > > to
> > > > > do
> > > > > would be to create my base classes BaseAction and
> BaseDispatchAction
> > > and
> > > > > this
> > > > > two must implement IGeneral, and in their implementation they
> should
> > > > delegate
> > > > > to
> > > > > a private static member of type GeneralImpl, which will handle this
> > > > > methods.
> > > > > Example:
> > > > > <code>
> > > > >     public interface IGeneral{
> > > > >         public Connection getConnection() throws SQLException;
> > > > >         ...........
> > > > >         public User getUser(HttpServletRequest req);
> > > > >     }
> > > > > </code>
> > > > >
> > > > >
> > > > > Then I'm creating the implementation for this methods:
> > > > >
> > > > >
> > > > > <code>
> > > > >     public class GeneralImpl implements IGeneral{
> > > > >         private ActionServlet servlet;
> > > > >         public GeneralImpl(ActionServlet srv){
> > > > >             servlet = srv;
> > > > >         }
> > > > >         public Connection getConnection() throws SQLException{
> > > > >             //code here
> > > > >         }
> > > > >         ...........
> > > > >         public User getUser(HttpServletRequest req){
> > > > >             //code here
> > > > >         }
> > > > >     }
> > > > > </code>
> > > > >
> > > > > Now I create the base Actions
> > > > >
> > > > > <code>
> > > > >     public abstract class BaseAction extends Action implements
> > IGeneral
> > > {
> > > > >             private static GeneralImpl general;
> > > > >             public BaseAction (){
> > > > >                 general = new GeneralImpl(servlet);
> > > > >             }
> > > > >             public ActionForward execute(ActionMapping
> > > mapping,ActionForm
> > > > > form,HttpServletRequest request,HttpServletResponse response){
> > > > >                 return executeAction(ActionMapping
> mapping,ActionForm
> > > > > form,HttpServletRequest request,HttpServletResponse response)
> > > > >             }
> > > > >             public abstract executeAction(ActionMapping
> > > > mapping,ActionForm
> > > > > form,HttpServletRequest request,HttpServletResponse response);
> > > > >             public Connection getConnection() throws SQLException{
> > > > >                 return general.getConnection();
> > > > >             }
> > > > >             public User getUser(HttpServletRequest req){
> > > > >                 return general.getUser(req);
> > > > >             }
> > > > >     }
> > > > > </code>
> > > > > The same for the DipatchAction.
> > > > >
> > > > > The question is anoybody has used something like this ? It this a
> > good
> > > > thing
> > > > > to
> > > > > do it ?
> > > > >
> > > > > Tanks in advance and sorry if  the text  it's too long
> > > > > Ovidiu
> > > >
> > > > -- 
> > > > Kris Schneider <mailto:[EMAIL PROTECTED]>
> > > > D.O.Tech       <http://www.dotech.com/>
> > >
> > > -- 
> > > Kris Schneider <mailto:[EMAIL PROTECTED]>
> > > D.O.Tech       <http://www.dotech.com/>
> >
> > -- 
> > Kris Schneider <mailto:[EMAIL PROTECTED]>
> > D.O.Tech       <http://www.dotech.com/>
>
> -- 
> Kris Schneider <mailto:[EMAIL PROTECTED]>
> D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.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]

Reply via email to