View Javadoc

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       * Returns the active HTTP request or <tt>null</tt> if one cannot be found.
22       */
23      @Nullable
24      HttpServletRequest getRequest();
25  
26      /**
27       * Returns the active HTTP response or <tt>null</tt> if one cannot be found.
28       */
29      @Nullable
30      HttpServletResponse getResponse();
31  
32      /**
33       * Returns the session associated with the active request or, if there is no current session and <tt>create</tt> is true,
34       * returns a new session.
35       *
36       * @param create should be <tt>true</tt> to create a new session for the active request or <tt>false</tt> to return
37       *               <tt>null</tt> if there is no current session
38       * @return the HttpSession associated with this request or <tt>null</tt> if <tt>create</tt> is false and the request has
39       * no session, or if there is no active request
40       */
41      @Nullable
42      HttpSession getSession(boolean create);
43  }