01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.myfaces.webapp;
17:
18: import org.apache.commons.logging.Log;
19: import org.apache.commons.logging.LogFactory;
20: import org.apache.myfaces.shared_impl.webapp.webxml.DelegatedFacesServlet;
21:
22: import javax.faces.webapp.FacesServlet;
23: import javax.servlet.*;
24: import java.io.IOException;
25:
26: /**
27: * Derived FacesServlet that can be used for debugging purpose
28: * and to fix the Weblogic startup issue (FacesServlet is initialized before ServletContextListener).
29: *
30: * @author Manfred Geiler (latest modification by $Author: mbr $)
31: * @version $Revision: 511514 $ $Date: 2007-02-25 14:47:48 +0100 (So, 25 Feb 2007) $
32: */
33: public class MyFacesServlet implements Servlet, DelegatedFacesServlet {
34: private static final Log log = LogFactory
35: .getLog(MyFacesServlet.class);
36:
37: private final FacesServlet delegate = new FacesServlet();
38:
39: private FacesInitializer _facesInitializer;
40:
41: protected FacesInitializer getFacesInitializer() {
42: if (_facesInitializer == null) {
43: _facesInitializer = new DefaultFacesInitializer();
44: }
45: return _facesInitializer;
46: }
47:
48: public void setFacesInitializer(FacesInitializer facesInitializer) {
49: _facesInitializer = facesInitializer;
50: }
51:
52: public void destroy() {
53: delegate.destroy();
54: }
55:
56: public ServletConfig getServletConfig() {
57: return delegate.getServletConfig();
58: }
59:
60: public String getServletInfo() {
61: return delegate.getServletInfo();
62: }
63:
64: public void init(ServletConfig servletConfig)
65: throws ServletException {
66: //Check, if ServletContextListener already called
67: ServletContext servletContext = servletConfig
68: .getServletContext();
69: Boolean b = (Boolean) servletContext
70: .getAttribute(StartupServletContextListener.FACES_INIT_DONE);
71: if (b == null || b.booleanValue() == false) {
72: if (log.isWarnEnabled())
73: log.warn("ServletContextListener not yet called");
74: getFacesInitializer().initFaces(
75: servletConfig.getServletContext());
76: }
77: delegate.init(servletConfig);
78: log.info("MyFacesServlet for context '"
79: + servletConfig.getServletContext().getRealPath("/")
80: + "' initialized.");
81: }
82:
83: public void service(ServletRequest request, ServletResponse response)
84: throws IOException, ServletException {
85: if (log.isTraceEnabled())
86: log.trace("MyFacesServlet service start");
87: delegate.service(request, response);
88: if (log.isTraceEnabled())
89: log.trace("MyFacesServlet service finished");
90: }
91:
92: }
|