View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2016 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.caravan.jaxws.publisher.impl;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  /**
26   * Manages request/response context of incoming HTTP requests using a ThreadLocal.
27   */
28  public final class RequestContext {
29  
30    private static ThreadLocal<RequestContext> threadLocal = new ThreadLocal<RequestContext>();
31  
32    private final HttpServletRequest request;
33    private final HttpServletResponse response;
34  
35    /**
36     * @param request Request
37     * @param response Response
38     */
39    public RequestContext(HttpServletRequest request, HttpServletResponse response) {
40      this.request = request;
41      this.response = response;
42    }
43  
44    /**
45     * @return Request
46     */
47    public HttpServletRequest getRequest() {
48      return request;
49    }
50  
51    /**
52     * @return Response
53     */
54    public HttpServletResponse getResponse() {
55      return response;
56    }
57  
58    /**
59     * @return Context for current request
60     */
61    public static RequestContext getRequestContext() {
62      return threadLocal.get();
63    }
64  
65    public static ThreadLocal<RequestContext> getThreadLocal() {
66      return threadLocal;
67    }
68  
69  }