• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.41
/src/main/java/com/meterware/servletunit/DispatchedRequestWrapper.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.servletunit;
21

22
import java.util.Enumeration;
23
import java.util.Hashtable;
24
import java.util.Map;
25

26
import javax.servlet.RequestDispatcher;
27
import javax.servlet.http.HttpServletRequest;
28
import javax.servlet.http.HttpServletRequestWrapper;
29

30
/**
31
 * This class represents a request dispatched via a RequestDispatcherImpl.
32
 **/
33
class DispatchedRequestWrapper extends HttpServletRequestWrapper {
34

35
    /** Request-specific information, including parameters and paths. **/
36
    private RequestContext _requestContext;
37

38
    /** The request being wrapped. **/
39
    private HttpServletRequest _baseRequest;
40

41
    /**
42
     * Creates the include request wrapper.
43
     *
44
     * @param request
45
     *            the request
46
     * @param dispatcher
47
     *            the dispatcher
48
     *
49
     * @return the http servlet request
50
     */
51
    static HttpServletRequest createIncludeRequestWrapper(HttpServletRequest request, RequestDispatcher dispatcher) {
52
        return new IncludeRequestWrapper(request, dispatcher);
1✔
53
    }
54

55
    /**
56
     * Creates the forward request wrapper.
57
     *
58
     * @param request
59
     *            the request
60
     * @param dispatcher
61
     *            the dispatcher
62
     *
63
     * @return the http servlet request
64
     */
65
    static HttpServletRequest createForwardRequestWrapper(HttpServletRequest request, RequestDispatcher dispatcher) {
66
        return new ForwardRequestWrapper(request, dispatcher);
1✔
67
    }
68

69
    /**
70
     * Instantiates a new dispatched request wrapper.
71
     *
72
     * @param baseRequest
73
     *            the base request
74
     * @param dispatcher
75
     *            the dispatcher
76
     */
77
    DispatchedRequestWrapper(HttpServletRequest baseRequest, RequestDispatcher dispatcher) {
78
        super(baseRequest);
1✔
79
        _baseRequest = baseRequest;
1✔
80
        _requestContext = (RequestContext) dispatcher;
1✔
81
        _requestContext.setParentRequest(baseRequest);
1✔
82
    }
1✔
83

84
    /**
85
     * Gets the base request.
86
     *
87
     * @return the base request
88
     */
89
    HttpServletRequest getBaseRequest() {
90
        return _baseRequest;
×
91
    }
92

93
    @Override
94
    public String getParameter(String s) {
95
        return _requestContext.getParameter(s);
1✔
96
    }
97

98
    @Override
99
    public Enumeration getParameterNames() {
100
        return _requestContext.getParameterNames();
×
101
    }
102

103
    @Override
104
    public String[] getParameterValues(String s) {
105
        return _requestContext.getParameterValues(s);
×
106
    }
107

108
    @Override
109
    public Map getParameterMap() {
110
        return _requestContext.getParameterMap();
×
111
    }
112

113
}
114

115
class IncludeRequestWrapper extends DispatchedRequestWrapper {
116

117
    static final String REQUEST_URI = "javax.servlet.include.request_uri";
118
    static final String CONTEXT_PATH = "javax.servlet.include.context_path";
119
    static final String SERVLET_PATH = "javax.servlet.include.servlet_path";
120
    static final String PATH_INFO = "javax.servlet.include.path_info";
121
    static final String QUERY_STRING = "javax.servlet.include.query_string";
122

123
    private Hashtable _attributes = new Hashtable<>();
1✔
124

125
    IncludeRequestWrapper(HttpServletRequest request, RequestDispatcher dispatcher) {
126
        super(request, dispatcher);
1✔
127
        _attributes.put(REQUEST_URI, ((RequestDispatcherImpl) dispatcher).getRequestURI());
1✔
128
        _attributes.put(CONTEXT_PATH, request.getContextPath());
1✔
129
        _attributes.put(SERVLET_PATH, ((RequestDispatcherImpl) dispatcher).getServletMetaData().getServletPath());
1✔
130
        final String pathInfo = ((RequestDispatcherImpl) dispatcher).getServletMetaData().getPathInfo();
1✔
131
        if (pathInfo != null) {
1!
132
            _attributes.put(PATH_INFO, pathInfo);
×
133
        }
134
    }
1✔
135

136
    @Override
137
    public Object getAttribute(String s) {
138
        Object result = _attributes.get(s);
1✔
139
        return result != null ? result : super.getAttribute(s);
1✔
140
    }
141

142
}
143

144
class ForwardRequestWrapper extends DispatchedRequestWrapper {
145

146
    private RequestDispatcherImpl _requestContext;
147

148
    ForwardRequestWrapper(HttpServletRequest request, RequestDispatcher dispatcher) {
149
        super(request, dispatcher);
1✔
150
        _requestContext = (RequestDispatcherImpl) dispatcher;
1✔
151
    }
1✔
152

153
    @Override
154
    public String getRequestURI() {
155
        return _requestContext.getRequestURI();
1✔
156
    }
157

158
    @Override
159
    public String getQueryString() {
160
        return super.getQueryString();
×
161
    }
162

163
    @Override
164
    public String getServletPath() {
165
        return _requestContext.getServletMetaData().getServletPath();
1✔
166
    }
167

168
    @Override
169
    public String getPathInfo() {
170
        return _requestContext.getServletMetaData().getPathInfo();
1✔
171
    }
172
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc