1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "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 jakarta.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
30
31 /**
32 * <p>
33 * WebLogic (at least v6 and v7) attempts to serialize the TilesRequestProcessor
34 * when re-deploying the Webapp in development mode. The TilesRequestProcessor
35 * is not serializable, and loses the Tiles definitions. This results in
36 * NullPointerException and/or NotSerializableException when using the app after
37 * automatic redeploy.
38 * </p>
39 * <p>
40 * This bug report proposes a workaround for this problem, in the hope it will
41 * help others and maybe motivate an actual fix.
42 * </p>
43 * <p>
44 * The attached class extends the Struts Action servlet and fixes the problem by
45 * reloading the Tiles definitions when they have disappeared.
46 * </p>
47 * <p>
48 * For background discussion see
49 * http://issues.apache.org/bugzilla/show_bug.cgi?id=26322
50 * </p>
51 * @version $Rev$ $Date$
52 * @since 1.2.1
53 */
54 public class RedeployableActionServlet extends ActionServlet {
55 private static final long serialVersionUID = -3277829251603784258L;
56
57 private TilesRequestProcessor tileProcessor;
58
59 protected synchronized RequestProcessor
60 getRequestProcessor(ModuleConfig config) throws ServletException {
61
62 if (tileProcessor != null) {
63 TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
64 return processor;
65 }
66
67 // reset the request processor
68 String requestProcessorKey = Globals.REQUEST_PROCESSOR_KEY +
69 config.getPrefix();
70 getServletContext().removeAttribute(requestProcessorKey);
71
72 // create a new request processor instance
73 TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
74
75 tileProcessor = processor;
76
77 try {
78 // reload Tiles defs
79 DefinitionsFactory factory = processor.getDefinitionsFactory();
80 factory.init(factory.getConfig(), getServletContext());
81 // System.out.println("reloaded tiles-definitions");
82 } catch (DefinitionsFactoryException e) {
83 e.printStackTrace();
84 }
85
86 return processor;
87 }
88 }