01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.directwebremoting.util;
18:
19: import javax.servlet.RequestDispatcher;
20: import javax.servlet.ServletRequest;
21: import javax.servlet.ServletResponse;
22:
23: import org.apache.commons.logging.LogFactory;
24: import org.apache.commons.logging.Log;
25:
26: /**
27: * Mock implementation of the RequestDispatcher interface.
28: * @author Rod Johnson
29: * @author Juergen Hoeller
30: * @author Joe Walker [joe at getahead dot ltd dot uk]
31: */
32: public class FakeRequestDispatcher implements RequestDispatcher {
33: /**
34: * Create a new FakeRequestDispatcher for the given URL.
35: * @param url the URL to dispatch to.
36: */
37: public FakeRequestDispatcher(String url) {
38: this .url = url;
39: }
40:
41: /* (non-Javadoc)
42: * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
43: */
44: public void forward(ServletRequest request, ServletResponse response) {
45: if (response.isCommitted()) {
46: throw new IllegalStateException(
47: "Cannot perform forward - response is already committed");
48: }
49:
50: if (!(response instanceof FakeHttpServletResponse)) {
51: throw new IllegalArgumentException(
52: "FakeRequestDispatcher requires FakeHttpServletResponse");
53: }
54:
55: ((FakeHttpServletResponse) response).setForwardedUrl(url);
56:
57: if (log.isDebugEnabled()) {
58: log.debug("FakeRequestDispatcher: forwarding to URL ["
59: + url + "]");
60: }
61: }
62:
63: /* (non-Javadoc)
64: * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
65: */
66: public void include(ServletRequest request, ServletResponse response) {
67: if (!(response instanceof FakeHttpServletResponse)) {
68: throw new IllegalArgumentException(
69: "FakeRequestDispatcher requires FakeHttpServletResponse");
70: }
71:
72: ((FakeHttpServletResponse) response).setIncludedUrl(url);
73:
74: if (log.isDebugEnabled()) {
75: log.debug("FakeRequestDispatcher: including URL [" + url
76: + "]");
77: }
78: }
79:
80: private final String url;
81:
82: /**
83: * The log stream
84: */
85: private static final Log log = LogFactory
86: .getLog(FakeRequestDispatcher.class);
87: }
|