KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > server > RequestDispatcherWrapper


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

20 package org.apache.cactus.server;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.servlet.RequestDispatcher JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.ServletRequest JavaDoc;
27 import javax.servlet.ServletResponse JavaDoc;
28
29 /**
30  * Wrapper around <code>RequestDispatcher</code> which overrides the
31  * <code>forward()</code> and <code>include</code> methods to use the original
32  * HTTP request object instead of the simulated one used by Cactus.
33  *
34  * @version $Id: RequestDispatcherWrapper.java,v 1.1 2004/05/22 11:34:48 vmassol Exp $
35  */

36 public class RequestDispatcherWrapper implements RequestDispatcher JavaDoc
37 {
38     /**
39      * The original request dispatcher object
40      */

41     private RequestDispatcher JavaDoc originalDispatcher;
42
43     /**
44      * @param theOriginalDispatcher the original request dispatcher object
45      */

46     public RequestDispatcherWrapper(RequestDispatcher JavaDoc theOriginalDispatcher)
47     {
48         this.originalDispatcher = theOriginalDispatcher;
49     }
50
51     /**
52      * Call the original <code>RequestDispatcher</code> <code>forward()</code>
53      * method but with the original HTTP request (not the simulation one which
54      * would make the servlet engine choke !).
55      *
56      * @param theRequest the simulation HTTP request
57      * @param theResponse the original HTTP response
58      * @exception IOException {@link RequestDispatcher#forward}
59      * @exception ServletException {@link RequestDispatcher#forward}
60      */

61     public void forward(ServletRequest JavaDoc theRequest, ServletResponse JavaDoc theResponse)
62         throws IOException JavaDoc, ServletException JavaDoc
63     {
64         // Always pass the original request to the forward() call.
65
if (HttpServletRequestWrapper.class.isAssignableFrom(
66             theRequest.getClass()))
67         {
68             HttpServletRequestWrapper request =
69                 (HttpServletRequestWrapper) theRequest;
70
71             this.originalDispatcher.forward(request.getOriginalRequest(),
72                 theResponse);
73         }
74         else
75         {
76             this.originalDispatcher.forward(theRequest, theResponse);
77         }
78     }
79
80     /**
81      * Call the original <code>RequestDispatcher</code> <code>include()</code>
82      * method but with the original HTTP request (not the simulation one which
83      * would make the servlet engine choke !).
84      *
85      * @param theRequest the simulation HTTP request
86      * @param theResponse the original HTTP response
87      * @exception IOException {@link RequestDispatcher#forward}
88      * @exception ServletException {@link RequestDispatcher#forward}
89      */

90     public void include(ServletRequest JavaDoc theRequest, ServletResponse JavaDoc theResponse)
91         throws IOException JavaDoc, ServletException JavaDoc
92     {
93         // Always pass the original request to the forward() call.
94
if (HttpServletRequestWrapper.class.isAssignableFrom(
95             theRequest.getClass()))
96         {
97             HttpServletRequestWrapper request =
98                 (HttpServletRequestWrapper) theRequest;
99
100             this.originalDispatcher.include(request.getOriginalRequest(),
101                 theResponse);
102         }
103         else
104         {
105             this.originalDispatcher.include(theRequest, theResponse);
106         }
107     }
108 }
109
Popular Tags