01: /*
02: * $Id: RedeployableActionServlet.java 481833 2006-12-03 17:32:52Z niallp $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * <p>
35: * WebLogic (at least v6 and v7) attempts to serialize the TilesRequestProcessor
36: * when re-deploying the Webapp in development mode. The TilesRequestProcessor
37: * is not serializable, and loses the Tiles definitions. This results in
38: * NullPointerException and/or NotSerializableException when using the app after
39: * automatic redeploy.
40: * </p>
41: * <p>
42: * This bug report proposes a workaround for this problem, in the hope it will
43: * help others and maybe motivate an actual fix.
44: * </p>
45: * <p>
46: * The attached class extends the Struts Action servlet and fixes the problem by
47: * reloading the Tiles definitions when they have disappeared.
48: * </p>
49: * <p>
50: * For background discussion see
51: * http://issues.apache.org/bugzilla/show_bug.cgi?id=26322
52: * </p>
53: * @version $Rev: 481833 $ $Date: 2006-12-03 11:32:52 -0600 (Sun, 03 Dec 2006) $
54: * @since 1.2.1
55: */
56: public class RedeployableActionServlet extends ActionServlet {
57: private TilesRequestProcessor tileProcessor;
58:
59: protected synchronized RequestProcessor getRequestProcessor(
60: ModuleConfig config) throws ServletException {
61:
62: if (tileProcessor != null) {
63: TilesRequestProcessor processor = (TilesRequestProcessor) super
64: .getRequestProcessor(config);
65: return processor;
66: }
67:
68: // reset the request processor
69: String requestProcessorKey = Globals.REQUEST_PROCESSOR_KEY
70: + config.getPrefix();
71: getServletContext().removeAttribute(requestProcessorKey);
72:
73: // create a new request processor instance
74: TilesRequestProcessor processor = (TilesRequestProcessor) super
75: .getRequestProcessor(config);
76:
77: tileProcessor = processor;
78:
79: try {
80: // reload Tiles defs
81: DefinitionsFactory factory = processor
82: .getDefinitionsFactory();
83: factory.init(factory.getConfig(), getServletContext());
84: // System.out.println("reloaded tiles-definitions");
85: } catch (DefinitionsFactoryException e) {
86: e.printStackTrace();
87: }
88:
89: return processor;
90: }
91: }
|