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