01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2004 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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;
23:
24: import javax.servlet.RequestDispatcher;
25: import javax.servlet.ServletException;
26: import javax.servlet.ServletRequest;
27: import javax.servlet.ServletResponse;
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 238991 2004-05-22 11:34:50Z vmassol $
35: */
36: public class RequestDispatcherWrapper implements RequestDispatcher {
37: /**
38: * The original request dispatcher object
39: */
40: private RequestDispatcher originalDispatcher;
41:
42: /**
43: * @param theOriginalDispatcher the original request dispatcher object
44: */
45: public RequestDispatcherWrapper(
46: RequestDispatcher theOriginalDispatcher) {
47: this .originalDispatcher = theOriginalDispatcher;
48: }
49:
50: /**
51: * Call the original <code>RequestDispatcher</code> <code>forward()</code>
52: * method but with the original HTTP request (not the simulation one which
53: * would make the servlet engine choke !).
54: *
55: * @param theRequest the simulation HTTP request
56: * @param theResponse the original HTTP response
57: * @exception IOException {@link RequestDispatcher#forward}
58: * @exception ServletException {@link RequestDispatcher#forward}
59: */
60: public void forward(ServletRequest theRequest,
61: ServletResponse theResponse) throws IOException,
62: ServletException {
63: // Always pass the original request to the forward() call.
64: if (HttpServletRequestWrapper.class.isAssignableFrom(theRequest
65: .getClass())) {
66: HttpServletRequestWrapper request = (HttpServletRequestWrapper) theRequest;
67:
68: this .originalDispatcher.forward(request
69: .getOriginalRequest(), theResponse);
70: } else {
71: this .originalDispatcher.forward(theRequest, theResponse);
72: }
73: }
74:
75: /**
76: * Call the original <code>RequestDispatcher</code> <code>include()</code>
77: * method but with the original HTTP request (not the simulation one which
78: * would make the servlet engine choke !).
79: *
80: * @param theRequest the simulation HTTP request
81: * @param theResponse the original HTTP response
82: * @exception IOException {@link RequestDispatcher#forward}
83: * @exception ServletException {@link RequestDispatcher#forward}
84: */
85: public void include(ServletRequest theRequest,
86: ServletResponse theResponse) throws IOException,
87: ServletException {
88: // Always pass the original request to the forward() call.
89: if (HttpServletRequestWrapper.class.isAssignableFrom(theRequest
90: .getClass())) {
91: HttpServletRequestWrapper request = (HttpServletRequestWrapper) theRequest;
92:
93: this.originalDispatcher.include(request
94: .getOriginalRequest(), theResponse);
95: } else {
96: this.originalDispatcher.include(theRequest, theResponse);
97: }
98: }
99: }
|