You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Xavier Vanderstukken <xv...@ionicsoft.com> on 2005/12/07 17:26:22 UTC

custom plugins and exception

I have a plugin in my struts application to initialize the required 
ressources.
If for some reason the processing fails, I catch the exception and throw 
a ServletException but the jsp error mechanism in not used and the 
client receive a tomcat 404 page in place of my """beautifull ;-)""" 
error page (however I have no problem to use my error page when an error 
occurs in a classical struts action or jsp.

public void init(ActionServlet servlet, ModuleConfig config) throws 
ServletException {
      
        try{
            /*
             * Performs some checks here
             */          
          
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            throw new ServletException(ex);
        }
}

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


Re: custom plugins and exception

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Plugins are executed as a result of the call to ActionServlet.init(), so
it makes sense that the JSP error handling mechanism would not be involved
here.

I think the way you'd want to handle this situation involves two pieces...

(1) Create a class something like this:

    public class IsMyAppConfigured() {
      private static boolean configured = false;
      public static void setConfigured() {
        configured = true;
      }
      public static boolean isConfigured() {
        return configured;
      }
    }

    Make a call to IsMyAppConfigured.setConfigured() at the end of your
plugin if no problems occur.

(2) Create a filter that calls IsMyAppConfigured.isConfigured() and
redirects to your error page if false is returned.

Also, be sure **NOT** to throw that ServletException from the plug-in.  In
fact, handle **ANY** exception within the plugin.

The net result is that users will be sent to your error page if the plugin
doesn't complete successfully, and it won't matter if ActionServlet
started up or not, or if anything else (aside from the context of course)
started up right.

Also note that a plugin can theoretically be executed any time the
container wants to by virtue of ActionServlet being created and destroyed
as it sees fit.  In general, you are better off using a ContextListener
instead of a plugin, if your containers' servlet spec is up to it, because
they are guaranteed by the spec to execute only once.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Wed, December 7, 2005 11:26 am, Xavier Vanderstukken said:
> I have a plugin in my struts application to initialize the required
> ressources.
> If for some reason the processing fails, I catch the exception and throw
> a ServletException but the jsp error mechanism in not used and the
> client receive a tomcat 404 page in place of my """beautifull ;-)"""
> error page (however I have no problem to use my error page when an error
> occurs in a classical struts action or jsp.
>
> public void init(ActionServlet servlet, ModuleConfig config) throws
> ServletException {
>
>         try{
>             /*
>              * Performs some checks here
>              */
>
>         }
>         catch(Exception ex)
>         {
>             ex.printStackTrace();
>             throw new ServletException(ex);
>         }
> }
>
> ---------------------------------------------------------------------
> 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