1 28 29 package com.caucho.server.webapp; 30 31 import com.caucho.server.connection.AbstractHttpResponse; 32 import com.caucho.server.connection.CauchoRequest; 33 import com.caucho.server.connection.RequestAdapter; 34 35 import javax.servlet.FilterChain ; 36 import javax.servlet.RequestDispatcher ; 37 import javax.servlet.ServletException ; 38 import javax.servlet.ServletRequest ; 39 import javax.servlet.ServletResponse ; 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import java.io.IOException ; 43 import java.io.OutputStream ; 44 import java.io.PrintWriter ; 45 46 class NamedDispatcherImpl implements RequestDispatcher { 47 private WebApp _webApp; 48 private FilterChain _filterChain; 49 private String _queryString; 50 51 NamedDispatcherImpl(FilterChain filterChain, String queryString, 52 WebApp webApp) 53 { 54 _filterChain = filterChain; 55 _queryString = queryString; 56 _webApp = webApp; 57 } 58 59 public void include(ServletRequest request, ServletResponse response) 60 throws IOException , ServletException 61 { 62 HttpServletResponse res = (HttpServletResponse ) response; 63 64 RequestAdapter reqAdapt = null; 65 if (! (request instanceof CauchoRequest)) { 66 reqAdapt = RequestAdapter.create(); 67 reqAdapt.init((HttpServletRequest ) request, res, _webApp); 68 request = reqAdapt; 69 } 70 CauchoRequest req = (CauchoRequest) request; 71 72 75 DispatchResponse subResponse = DispatchResponse.createDispatch(); 76 subResponse.setRequest(req); 77 subResponse.setNextResponse(res); 78 subResponse.start(); 80 81 try { 82 _filterChain.doFilter(req, subResponse); 83 } finally { 84 subResponse.finish(); 85 } 86 87 if (reqAdapt != null) 88 RequestAdapter.free(reqAdapt); 89 90 DispatchResponse.free(subResponse); 91 } 92 93 96 public void forward(ServletRequest req, ServletResponse res) 97 throws ServletException , IOException 98 { 99 res.resetBuffer(); 100 101 res.setContentLength(-1); 102 103 _filterChain.doFilter(req, res); 104 105 if (res instanceof AbstractHttpResponse) { 109 ((AbstractHttpResponse) res).finish(); 110 } 111 else { 112 try { 113 OutputStream os = res.getOutputStream(); 114 if (os != null) 115 os.close(); 116 } catch (IllegalStateException e) { 117 } 118 119 try { 120 PrintWriter out = res.getWriter(); 121 if (out != null) 122 out.close(); 123 } catch (IllegalStateException e1) { 124 } 125 126 } 127 128 137 138 145 } 146 } 147 148 | Popular Tags |