Home » Struts-1.3.10 » org.apache.struts » actions » [javadoc | source]

    1   package org.apache.struts.actions;
    2   
    3   import javax.servlet.ServletException;
    4   
    5   import org.apache.struts.Globals;
    6   import org.apache.struts.action.ActionServlet;
    7   import org.apache.struts.action.RequestProcessor;
    8   import org.apache.struts.config.ModuleConfig;
    9   import org.apache.struts.tiles.DefinitionsFactory;
   10   import org.apache.struts.tiles.DefinitionsFactoryException;
   11   import org.apache.struts.tiles.TilesRequestProcessor;
   12   
   13   
   14   /**
   15    * <p>
   16    * WebLogic (at least v6 and v7) attempts to serialize the TilesRequestProcessor
   17    * when re-deploying the Webapp in development mode. The TilesRequestProcessor
   18    * is not serializable, and loses the Tiles definitions. This results in
   19    * NullPointerException and/or NotSerializableException when using the app after
   20    * automatic redeploy.
   21    * </p>
   22    * <p>
   23    * This bug report proposes a workaround for this problem, in the hope it will
   24    * help others and maybe motivate an actual fix.
   25    * </p>
   26    * <p>
   27    * The attached class extends the Struts Action servlet and fixes the problem by
   28    * reloading the Tiles definitions when they have disappeared.
   29    * </p>
   30    * <p>
   31    * For background discussion see
   32    * http://issues.apache.org/bugzilla/show_bug.cgi?id=26322
   33    * </p>
   34    * @version $Rev: 54954 $ $Date: 2004-10-17 07:40:12 +0100 (Sun, 17 Oct 2004) $
   35    * @since 1.2.1
   36    */
   37   public class RedeployableActionServlet extends ActionServlet {
   38       private TilesRequestProcessor tileProcessor;
   39   
   40       protected synchronized RequestProcessor
   41               getRequestProcessor(ModuleConfig config) throws ServletException {
   42   
   43           if (tileProcessor != null) {
   44               TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
   45               return processor;
   46           }
   47   
   48           // reset the request processor
   49           String requestProcessorKey = Globals.REQUEST_PROCESSOR_KEY +
   50                   config.getPrefix();
   51           getServletContext().removeAttribute(requestProcessorKey);
   52   
   53           // create a new request processor instance
   54           TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
   55   
   56           tileProcessor = processor;
   57   
   58           try {
   59               // reload Tiles defs
   60               DefinitionsFactory factory = processor.getDefinitionsFactory();
   61               factory.init(factory.getConfig(), getServletContext());
   62               // System.out.println("reloaded tiles-definitions");
   63           } catch (DefinitionsFactoryException e) {
   64               e.printStackTrace();
   65           }
   66   
   67           return processor;
   68       }
   69   }

Home » Struts-1.3.10 » org.apache.struts » actions » [javadoc | source]