You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Chisholm <Da...@i2.com> on 2000/06/21 06:40:02 UTC

Does struts provide hooks for app-specific initialization?

I've developed my own action framework, and I'm considering switching to
struts given all of the benefits of an open source jakarta project, etc,
etc.

But I've come across a few issues that struts doesn't appear to have the
flexibility (yet) to address.

1.  App-specific initialization

Is there anyplace in struts where I can add a hook to perform application
specific initialization when the struts action servlet is loaded?  If not,
is there some other recommended method of doing this?

In the framework I'm working on, I defined an initialization interface for
applications to implement.  An application's concrete class is specified in
a property file, and when loaded, the action servlet instantiated and
executes the concrete class.  Typical dynamic class loading stuff.

2.  Request pre-processing

Is there a central point in struts where I can examine and modify all
requests before they are delegated to an Action?

I use request pre-processing to perform common actions such as validating
sessions and parsing out cross site scripting special characters from
requests.  The request pre-processor class is configurable by the
application just as the app-specific initialization class is.

3.  Page parameterization

Is there any way to declare output page parameters?

In the applications that I'm working with, many of the pages are
inter-changeable between different workflows, and we make each page
independent of other pages and actions.

A typical action that a page invokes is 'next', and it's up to the 'next'
action to figure out what exactly to do.  The 'next' action is actually a
composite Action that searches for the next Action in the workflow, executes
it, and returns that Action's jsp page.

To make this work, pages have to declare what their output is, and this
allows the 'next' action to forward that output to the next page.

Ideally, pages would also declare what beans that they require and actions
would declare what parameters they require and what beans they output.  Then
we could perform static analysis of the configuration files to find
mis-matches between actions and pages, but that's another to-do item on my
list.

So does anyone have some information/ideas about how to handle these issues
with struts?

David




RE: Does struts provide hooks for app-specific initialization?

Posted by David Chisholm <Da...@i2.com>.
Thanks for both suggestions.  This is probably how I'll implement it except
that I will likely override the ActionServlet.process(req, resp) method
instead of processActionInstance() because I need to override the processing
at the highest level.
Thanks again,
David


> -----Original Message-----
> From: jhut@inst.strykercorp.com [mailto:jhut@inst.strykercorp.com]
> Sent: Wednesday, June 21, 2000 7:24 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: Does struts provide hooks for app-specific initialization?
>
>
> On Tue, 20 Jun 2000, David Chisholm wrote:
>
> > 1.  App-specific initialization
> >
> > Is there anyplace in struts where I can add a hook to perform
> application
> > specific initialization when the struts action servlet is
> loaded?  If not,
> > is there some other recommended method of doing this?
>
> The Struts ActionServlet has a couple of convenient places to plug in you
> custom behavior.  For custom application initialization you can extend
> ActionServlet like this:
>
> public class MyActionServlet
>     extends org.apache.struts.action.ActionServlet {
>
>     protected void initApplication() throws ServletException {
>         super.initApplication();
>         // do application-specific initialization
>     }
> }
>
>
> > 2.  Request pre-processing
> >
> > Is there a central point in struts where I can examine and modify all
> > requests before they are delegated to an Action?
>
> Same method as above, but do application-specific action before allowing
> the action to be processed:
>
> public class MyActionServlet
>     extends org.apache.struts.action.ActionServlet {
>
>     protected void processActionInstance(ActionMapping mapping,
>                                          ActionForm formInstance,
>                                          HttpServletRequest request,
>                                          HttpServletResponse response)
>         throws IOException, ServletException {
>
>         // do application-specific action
>
>         super.processActionInstance(mapping, formInstance,
>                                     request, response);
>         }
>
> }
>
> You could also choose to make the above servlets final, as well.
>
> Hope this helps,
>
> -jh
>
> --
> Jeff Hutchison <jh...@inst.strykercorp.com>
> Stryker Instruments, Kalamazoo, MI
>


Re: Does struts provide hooks for app-specific initialization?

Posted by jh...@inst.strykercorp.com.
On Tue, 20 Jun 2000, David Chisholm wrote:

> 1.  App-specific initialization
> 
> Is there anyplace in struts where I can add a hook to perform application
> specific initialization when the struts action servlet is loaded?  If not,
> is there some other recommended method of doing this?

The Struts ActionServlet has a couple of convenient places to plug in you
custom behavior.  For custom application initialization you can extend
ActionServlet like this:

public class MyActionServlet
    extends org.apache.struts.action.ActionServlet {

    protected void initApplication() throws ServletException {
        super.initApplication();
        // do application-specific initialization
    }
}


> 2.  Request pre-processing
> 
> Is there a central point in struts where I can examine and modify all
> requests before they are delegated to an Action?

Same method as above, but do application-specific action before allowing
the action to be processed:

public class MyActionServlet
    extends org.apache.struts.action.ActionServlet {

    protected void processActionInstance(ActionMapping mapping,
                                         ActionForm formInstance,
                                         HttpServletRequest request,
                                         HttpServletResponse response)
        throws IOException, ServletException {

        // do application-specific action

        super.processActionInstance(mapping, formInstance,
                                    request, response);
        }
  
}

You could also choose to make the above servlets final, as well.

Hope this helps,

-jh

-- 
Jeff Hutchison <jh...@inst.strykercorp.com>
Stryker Instruments, Kalamazoo, MI