View Javadoc

1   package org.apache.struts.tiles;
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: 125675 $ $Date: 2005-01-19 15:21:34 -0700 (Wed, 19 Jan 2005) $
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  }