1 13 17 package com.tonbeller.wcf.controller; 18 19 import java.io.IOException ; 20 21 import javax.servlet.RequestDispatcher ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServlet ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.apache.log4j.Logger; 28 29 import com.tonbeller.wcf.utils.SoftException; 30 import com.tonbeller.wcf.utils.UrlUtils; 31 32 50 public class FacesServlet extends HttpServlet { 51 final String errorJSP = null; 52 53 private static Logger logger = Logger.getLogger(FacesServlet.class); 54 55 protected void doGet(HttpServletRequest request, HttpServletResponse response) 56 throws ServletException , IOException { 57 doPost(request, response); 58 } 59 60 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException , 61 IOException { 62 String facesUri = req.getServletPath(); 63 String jspUri = UrlUtils.forceExtension(facesUri, ".faces", ".jsp"); 64 65 if (facesUri.equals(jspUri)) 66 throw new ServletException ("faces mapped to jsp"); 67 68 if (logger.isInfoEnabled()) 69 logger.info("FacesServlet: " + facesUri + " -> " + jspUri); 70 RequestDispatcher rd = req.getRequestDispatcher(jspUri); 71 if (rd == null) 72 throw new IllegalArgumentException ("could not find RequestDispatcher for " + jspUri); 73 try { 74 rd.forward(req, res); 75 } catch (Exception 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 e2) { 83 throw new SoftException(e); 87 } 88 } else 89 throw new SoftException(e); 90 } 91 } 92 93 } | Popular Tags |