xref: /unit/src/java/nginx/unit/IncludeRequestWrapper.java (revision 1121:c0468d3daf98)
1 package nginx.unit;
2 
3 import javax.servlet.DispatcherType;
4 import javax.servlet.MultipartConfigElement;
5 import javax.servlet.RequestDispatcher;
6 import javax.servlet.ServletRequest;
7 
8 public class IncludeRequestWrapper implements DynamicPathRequest
9 {
10     private final Request request_;
11 
12     private final Object orig_servlet_path_attr;
13     private final Object orig_path_info_attr;
14     private final Object orig_uri_attr;
15     private final Object orig_context_path_attr;
16     private final Object orig_query_string_attr;
17 
18     private final MultipartConfigElement orig_multipart_config;
19 
20     private final DispatcherType orig_dtype;
21 
22     private String filter_path_;
23 
IncludeRequestWrapper(ServletRequest request)24     public IncludeRequestWrapper(ServletRequest request)
25     {
26         if (request instanceof Request) {
27             request_ = (Request) request;
28         } else {
29             request_ = (Request) request.getAttribute(Request.BARE);
30         }
31 
32         orig_servlet_path_attr = request_.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
33         orig_path_info_attr = request_.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
34         orig_uri_attr = request_.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
35         orig_context_path_attr = request_.getAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH);
36         orig_query_string_attr = request_.getAttribute(RequestDispatcher.INCLUDE_QUERY_STRING);
37 
38         orig_multipart_config = request_.getMultipartConfig();
39 
40         orig_dtype = request_.getDispatcherType();
41 
42         request_.setAttribute_(RequestDispatcher.INCLUDE_CONTEXT_PATH, request_.getContextPath());
43     }
44 
45     @Override
setDispatcherType(DispatcherType type)46     public void setDispatcherType(DispatcherType type)
47     {
48         request_.setDispatcherType(type);
49     }
50 
51     @Override
setServletPath(String servlet_path, String path_info)52     public void setServletPath(String servlet_path, String path_info)
53     {
54         setServletPath(servlet_path, servlet_path, path_info);
55     }
56 
57     @Override
setServletPath(String filter_path, String servlet_path, String path_info)58     public void setServletPath(String filter_path, String servlet_path, String path_info)
59     {
60         request_.setAttribute_(RequestDispatcher.INCLUDE_SERVLET_PATH, servlet_path);
61         request_.setAttribute_(RequestDispatcher.INCLUDE_PATH_INFO, path_info);
62         filter_path_ = filter_path;
63     }
64 
65     @Override
setRequestURI(String uri)66     public void setRequestURI(String uri)
67     {
68         request_.setAttribute_(RequestDispatcher.INCLUDE_REQUEST_URI, uri);
69     }
70 
71     @Override
setQueryString(String query)72     public void setQueryString(String query)
73     {
74         request_.setAttribute_(RequestDispatcher.INCLUDE_QUERY_STRING, query);
75     }
76 
77     @Override
getFilterPath()78     public String getFilterPath()
79     {
80         return filter_path_;
81     }
82 
setMultipartConfig(MultipartConfigElement mce)83     public void setMultipartConfig(MultipartConfigElement mce)
84     {
85         request_.setMultipartConfig(mce);
86     }
87 
close()88     public void close()
89     {
90         request_.setDispatcherType(orig_dtype);
91 
92         request_.setAttribute_(RequestDispatcher.INCLUDE_SERVLET_PATH, orig_servlet_path_attr);
93         request_.setAttribute_(RequestDispatcher.INCLUDE_PATH_INFO, orig_path_info_attr);
94         request_.setAttribute_(RequestDispatcher.INCLUDE_REQUEST_URI, orig_uri_attr);
95         request_.setAttribute_(RequestDispatcher.INCLUDE_CONTEXT_PATH, orig_context_path_attr);
96         request_.setAttribute_(RequestDispatcher.INCLUDE_QUERY_STRING, orig_query_string_attr);
97 
98         request_.setMultipartConfig(orig_multipart_config);
99     }
100 }
101