View Javadoc
1   package com.atlassian.plugin.refimpl;
2   
3   import javax.servlet.ServletContext;
4   import javax.servlet.http.HttpServletRequest;
5   import javax.servlet.http.HttpServletResponse;
6   
7   /**
8    * Class used to store and access the currently running http request in the refapp.
9    */
10  
11  public class CurrentHttpRequest {
12      private static final ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>();
13      private static final ThreadLocal<HttpServletResponse> response = new ThreadLocal<HttpServletResponse>();
14  
15      public static ServletContext getContext() {
16          return getRequest().getSession().getServletContext();
17      }
18  
19      /**
20       * Gets the current http request that is stored in this class (each time a new request comes in this is changed).
21       */
22  
23      public static HttpServletRequest getRequest() {
24          return request.get();
25      }
26  
27      /**
28       * @param httpRequest the request
29       */
30      public static void setRequest(HttpServletRequest httpRequest) {
31          request.set(httpRequest);
32      }
33  
34      /**
35       * @param httpResponse the response
36       */
37      static void setResponse(HttpServletResponse httpResponse) {
38          response.set(httpResponse);
39      }
40  
41      public static HttpServletResponse getResponse() {
42          return response.get();
43      }
44  }