001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.services.impl; 016 017 import java.io.IOException; 018 019 import javax.servlet.ServletException; 020 import javax.servlet.http.HttpServletRequest; 021 import javax.servlet.http.HttpServletResponse; 022 023 import org.apache.tapestry.services.RequestGlobals; 024 import org.apache.tapestry.services.ServletRequestServicer; 025 import org.apache.tapestry.services.WebRequestServicer; 026 import org.apache.tapestry.web.ServletWebRequest; 027 import org.apache.tapestry.web.ServletWebResponse; 028 import org.apache.tapestry.web.WebRequest; 029 import org.apache.tapestry.web.WebResponse; 030 031 /** 032 * Bridges from the <code>tapestry.request.ServletRequestServicerPipeline</code> to the 033 * <code>tapestry.request.WebRequestServicerPipeline</code>. Also, stores the web request and 034 * web response into {@link org.apache.tapestry.services.RequestGlobals}. Intercepts runtime 035 * exceptions and throws them wrapped as {@link javax.servlet.ServletException}. 036 * 037 * <p>This service is responsible for for storing the http/web request wrappers into 038 * {@link RequestGlobals}.</p> 039 * 040 * @author Howard M. Lewis Ship 041 * @since 4.0 042 */ 043 public class WebRequestServicerPipelineBridge implements ServletRequestServicer 044 { 045 private RequestGlobals _requestGlobals; 046 047 private WebRequestServicer _webRequestServicer; 048 049 public void service(HttpServletRequest request, HttpServletResponse response) 050 throws IOException, ServletException 051 { 052 _requestGlobals.store(request, response); 053 054 WebRequest webRequest = new ServletWebRequest(request, response); 055 WebResponse webResponse = new ServletWebResponse(response); 056 057 _requestGlobals.store(webRequest, webResponse); 058 059 try 060 { 061 _webRequestServicer.service(webRequest, webResponse); 062 } 063 catch (RuntimeException ex) 064 { 065 throw new ServletException(ex); 066 } 067 } 068 069 public void setRequestGlobals(RequestGlobals requestGlobals) 070 { 071 _requestGlobals = requestGlobals; 072 } 073 074 public void setWebRequestServicer(WebRequestServicer webRequestServicer) 075 { 076 _webRequestServicer = webRequestServicer; 077 } 078 }