1 package com.atlassian.sal.api.web.context;
2
3 import javax.annotation.Nullable;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse;
6 import javax.servlet.http.HttpSession;
7
8 /**
9 * Provides access to the key objects provided by the servlet API when processing an HTTP request.
10 * <p/>
11 * Use this interface rather than making static calls to classes like <tt>ServletActionContext</tt> directly.
12 * <p/>
13 * Note that this interface makes no guarantees about which wrapper for the active request, response or session will be returned.
14 * Callers should not rely on retrieving any particular wrapper. It is only guaranteed to be populated on a http request thread,
15 * after login, and before decoration.
16 *
17 * @since 2.8
18 */
19 public interface HttpContext
20 {
21 /**
22 * Returns the active HTTP request or <tt>null</tt> if one cannot be found.
23 */
24 @Nullable HttpServletRequest getRequest();
25
26 /**
27 * Returns the active HTTP response or <tt>null</tt> if one cannot be found.
28 */
29 @Nullable HttpServletResponse getResponse();
30
31 /**
32 * Returns the session associated with the active request or, if there is no current session and <tt>create</tt> is true,
33 * returns a new session.
34 *
35 * @param create should be <tt>true</tt> to create a new session for the active request or <tt>false</tt> to return
36 * <tt>null</tt> if there is no current session
37 * @return the HttpSession associated with this request or <tt>null</tt> if <tt>create</tt> is false and the request has
38 * no session, or if there is no active request
39 */
40 @Nullable HttpSession getSession(boolean create);
41 }