KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > controller > FacesServlet


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 /*
14  * Created on 28.07.2004
15  *
16  */

17 package com.tonbeller.wcf.controller;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.RequestDispatcher JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23 import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.log4j.Logger;
28
29 import com.tonbeller.wcf.utils.SoftException;
30 import com.tonbeller.wcf.utils.UrlUtils;
31
32 /**
33  * Ersatz fuer das FacesServlet, dass unter Oracle manchmal in einen illegalen
34  * state kommt und an alle clients arrayoutofboundsexception schickt.
35  *
36  * Fehler trat bei VERSORGE im Oracle 10 Application Server mit Oracle DB auf
37  * (mit Tomcat oder MySQL funktioniert es): Daten versorgen, dabei eine
38  * Fakt Spalte mit text befuellen, so dass eine Exception entsteht. Browser
39  * mit der Exception offen lasssen und versorge nochmal starten. Wenn man das
40  * ein paar mal macht, knallt es mit
41  * <pre>
42  * java.lang.IndexOutOfBoundsException
43  * at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:1448)
44  * at javax.faces.webapp.UIComponentTag.createChild(UIComponentTag.java:1047)
45  * at javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java:742)
46  * at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:423)
47  * </pre>
48  * @author av
49  */

50 public class FacesServlet extends HttpServlet JavaDoc {
51   final String JavaDoc errorJSP = null;
52
53   private static Logger logger = Logger.getLogger(FacesServlet.class);
54
55   protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
56       throws ServletException JavaDoc, IOException JavaDoc {
57     doPost(request, response);
58   }
59
60   protected void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc,
61       IOException JavaDoc {
62     String JavaDoc facesUri = req.getServletPath();
63     String JavaDoc jspUri = UrlUtils.forceExtension(facesUri, ".faces", ".jsp");
64
65     if (facesUri.equals(jspUri))
66       throw new ServletException JavaDoc("faces mapped to jsp");
67
68     if (logger.isInfoEnabled())
69       logger.info("FacesServlet: " + facesUri + " -> " + jspUri);
70     RequestDispatcher JavaDoc rd = req.getRequestDispatcher(jspUri);
71     if (rd == null)
72       throw new IllegalArgumentException JavaDoc("could not find RequestDispatcher for " + jspUri);
73     try {
74       rd.forward(req, res);
75     } catch (Exception JavaDoc e) {
76       logger.error(null, e);
77       if (errorJSP != null) {
78         try {
79           logger.error("redirecting to error page " + errorJSP, e);
80           req.setAttribute("javax.servlet.jsp.jspException", e);
81           req.getRequestDispatcher(errorJSP).forward(req, res);
82         } catch (Exception JavaDoc e2) {
83           // there was an error displaying the error page. We
84
// ignore the second error and display the original error
85
// instead
86
throw new SoftException(e);
87         }
88       } else
89         throw new SoftException(e);
90     }
91   }
92
93 }
Popular Tags