KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > WebRequestServicerPipelineBridge


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.services.impl;
16
17 import java.io.IOException JavaDoc;
18
19 import javax.servlet.ServletException JavaDoc;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.apache.tapestry.services.RequestGlobals;
24 import org.apache.tapestry.services.ServletRequestServicer;
25 import org.apache.tapestry.services.WebRequestServicer;
26 import org.apache.tapestry.web.ServletWebRequest;
27 import org.apache.tapestry.web.ServletWebResponse;
28 import org.apache.tapestry.web.WebRequest;
29 import org.apache.tapestry.web.WebResponse;
30
31 /**
32  * Bridges from the <code>tapestry.request.ServletRequestServicerPipeline</code> to the
33  * <code>tapestry.request.WebRequestServicerPipeline</code>. Also, stores the web request and
34  * web response into {@link org.apache.tapestry.services.RequestGlobals}. Intercepts runtime
35  * exceptions and throws them wrapped as {@link javax.servlet.ServletException}.
36  *
37  * @author Howard M. Lewis Ship
38  * @since 4.0
39  */

40 public class WebRequestServicerPipelineBridge implements ServletRequestServicer
41 {
42     private RequestGlobals _requestGlobals;
43
44     private WebRequestServicer _webRequestServicer;
45
46     public void service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
47             throws IOException JavaDoc, ServletException JavaDoc
48     {
49         _requestGlobals.store(request, response);
50
51         WebRequest webRequest = new ServletWebRequest(request, response);
52         WebResponse webResponse = new ServletWebResponse(response);
53
54         try
55         {
56             _webRequestServicer.service(webRequest, webResponse);
57         }
58         catch (RuntimeException JavaDoc ex)
59         {
60             throw new ServletException JavaDoc(ex);
61         }
62     }
63
64     public void setRequestGlobals(RequestGlobals requestGlobals)
65     {
66         _requestGlobals = requestGlobals;
67     }
68
69     public void setWebRequestServicer(WebRequestServicer webRequestServicer)
70     {
71         _webRequestServicer = webRequestServicer;
72     }
73 }
Popular Tags