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: package org.directwebremoting;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.ServletException;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23: import javax.servlet.http.HttpSession;
24:
25: /**
26: * Class to enable us to access servlet parameters.
27: * @author Joe Walker [joe at getahead dot ltd dot uk]
28: */
29: public interface WebContext extends ServerContext {
30: /**
31: * Get the script session that represents the currently viewed page in the
32: * same way that an HttpSession represents a cookie.
33: * @return A browser object for this user
34: */
35: ScriptSession getScriptSession();
36:
37: /**
38: * What is the URL of the current page.
39: * This includes 'http://', up to (but not including) '?' or '#'
40: * @return The URL of the current page
41: */
42: String getCurrentPage();
43:
44: /**
45: * Returns the current session associated with this request, or if the
46: * request does not have a session, creates one.
47: * @return Returns the http session.
48: * @see HttpServletRequest#getSession()
49: */
50: HttpSession getSession();
51:
52: /**
53: * Returns the current HttpSession associated with this request or, if
54: * there is no current session and create is true, returns a new session.
55: * If create is false and the request has no valid HttpSession, this method
56: * returns null.
57: * @param create false to return null if there's no current session
58: * @return the session associated with this request
59: * @see HttpServletRequest#getSession(boolean)
60: */
61: HttpSession getSession(boolean create);
62:
63: /**
64: * Accessor for the http request information.
65: * @return Returns the request.
66: */
67: HttpServletRequest getHttpServletRequest();
68:
69: /**
70: * Accessor for the http response bean.
71: * <p>You can't use this request to directly reply to the response or to add
72: * headers or cookies.
73: * @return Returns the response.
74: */
75: HttpServletResponse getHttpServletResponse();
76:
77: /**
78: * An attribute used by {@link WebContext#forwardToString(String)} to inform
79: * anyone that wants to know that this is a request from DWR.
80: */
81: public static final String ATTRIBUTE_DWR = "org.directwebremoting";
82:
83: /**
84: * Forward a request to a given URL and catch the data written to it.
85: * It is possible to distinguish requests that arrive normally and requests
86: * that come from a DWR forwardToString() by the presence of a request
87: * attribute. Before the request is forwarded, DWR will call:
88: * <pre>
89: * request.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
90: * </pre>
91: * @param url The URL to forward to
92: * @return The text that results from forwarding to the given URL
93: * @throws IOException if the target resource throws this exception
94: * @throws ServletException if the target resource throws this exception
95: * @throws IllegalStateException if the response was already committed
96: */
97: String forwardToString(String url) throws ServletException,
98: IOException;
99: }
|