summaryrefslogtreecommitdiffhomepage
path: root/src/java/nginx/unit/IncludeRequestWrapper.java
blob: 67a51b247a564f14d57cbad6f119de38b4002599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package nginx.unit;

import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;

public class IncludeRequestWrapper implements DynamicPathRequest
{
    private final Request request_;

    private final Object orig_servlet_path_attr;
    private final Object orig_path_info_attr;
    private final Object orig_uri_attr;
    private final Object orig_context_path_attr;
    private final Object orig_query_string_attr;

    private final DispatcherType orig_dtype;

    private String filter_path_;

    public IncludeRequestWrapper(ServletRequest request)
    {
        if (request instanceof Request) {
            request_ = (Request) request;
        } else {
            request_ = (Request) request.getAttribute(Request.BARE);
        }

        orig_servlet_path_attr = request_.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
        orig_path_info_attr = request_.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
        orig_uri_attr = request_.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
        orig_context_path_attr = request_.getAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH);
        orig_query_string_attr = request_.getAttribute(RequestDispatcher.INCLUDE_QUERY_STRING);

        orig_dtype = request_.getDispatcherType();

        request_.setAttribute_(RequestDispatcher.INCLUDE_CONTEXT_PATH, request_.getContextPath());
    }

    @Override
    public void setDispatcherType(DispatcherType type)
    {
        request_.setDispatcherType(type);
    }

    @Override
    public void setServletPath(String servlet_path, String path_info)
    {
        setServletPath(servlet_path, servlet_path, path_info);
    }

    @Override
    public void setServletPath(String filter_path, String servlet_path, String path_info)
    {
        request_.setAttribute_(RequestDispatcher.INCLUDE_SERVLET_PATH, servlet_path);
        request_.setAttribute_(RequestDispatcher.INCLUDE_PATH_INFO, path_info);
        filter_path_ = filter_path;
    }

    @Override
    public void setRequestURI(String uri)
    {
        request_.setAttribute_(RequestDispatcher.INCLUDE_REQUEST_URI, uri);
    }

    @Override
    public void setQueryString(String query)
    {
        request_.setAttribute_(RequestDispatcher.INCLUDE_QUERY_STRING, query);
    }

    @Override
    public String getFilterPath()
    {
        return filter_path_;
    }

    public void close()
    {
        request_.setDispatcherType(orig_dtype);

        request_.setAttribute_(RequestDispatcher.INCLUDE_SERVLET_PATH, orig_servlet_path_attr);
        request_.setAttribute_(RequestDispatcher.INCLUDE_PATH_INFO, orig_path_info_attr);
        request_.setAttribute_(RequestDispatcher.INCLUDE_REQUEST_URI, orig_uri_attr);
        request_.setAttribute_(RequestDispatcher.INCLUDE_CONTEXT_PATH, orig_context_path_attr);
        request_.setAttribute_(RequestDispatcher.INCLUDE_QUERY_STRING, orig_query_string_attr);
    }
}