1 5 package com.opensymphony.webwork.dispatcher; 6 7 import com.opensymphony.webwork.WebWorkStatics; 8 import com.opensymphony.webwork.dispatcher.mapper.ActionMapperFactory; 9 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.ServletConfig ; 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServlet ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import java.io.IOException ; 19 20 58 public class ServletDispatcher extends HttpServlet implements WebWorkStatics { 59 61 64 protected static final Log LOG = LogFactory.getLog(ServletDispatcher.class); 65 66 73 public void init(ServletConfig servletConfig) throws ServletException { 74 super.init(servletConfig); 75 DispatcherUtils.initialize(getServletContext()); 76 } 77 78 88 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { 89 ActionMapping mapping = ActionMapperFactory.getMapper().getMapping(request); 90 if (mapping == null) { 91 try { 92 response.sendError(404); 93 } catch (IOException e) { 94 LOG.error("Could not send 404 after not finding any ActionMapping", e); 95 } 96 return; 97 } 98 99 DispatcherUtils du = DispatcherUtils.getInstance(); 100 du.prepare(request, response); 101 102 try { 103 request = du.wrapRequest(request, getServletContext()); 104 } catch (IOException e) { 105 String message = "Could not wrap servlet request with MultipartRequestWrapper!"; 106 LOG.error(message, e); 107 du.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, new ServletException (message, e)); 108 return; 109 } 110 111 du.serviceAction(request, response, getServletContext(), mapping); 112 } 113 } 114 | Popular Tags |