Skip to content

Commit 44b81db

Browse files
committed
[http] extract Multipart code into new ServletRequestMultipartWrapper
Mostly in the usage of felix-jetty-light there is the cases where you do not need the multipart support and can remove the dependencies of common-fileupload and common-io. To be able to do this we could not load a instantiate a class that imports common-fileupload classes. So we have to free the old class ServletRequestWrapper of this imports and add a ServletRequestMultipartWrapper that still have the multipart support. Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
1 parent f572bd8 commit 44b81db

File tree

5 files changed

+388
-265
lines changed

5 files changed

+388
-265
lines changed

http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,25 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
137137
final ExtServletContext servletContext = pr.handler.getContext();
138138
final RequestInfo requestInfo = new RequestInfo(pr.servletPath, pr.pathInfo, null, req.getRequestURI(),
139139
pr.handler.getName(), pr.matchedPattern, pr.matchValue, pr.match, false);
140-
final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext, requestInfo, null,
141-
pr.handler.getServletInfo().isAsyncSupported(),
142-
pr.handler.getMultipartConfig(),
143-
pr.handler.getMultipartSecurityContext());
140+
141+
MultipartConfig multipartConfig = pr.handler.getMultipartConfig();
142+
HttpServletRequest wrappedRequest;
143+
if(multipartConfig==null){
144+
wrappedRequest = new ServletRequestWrapper(req,
145+
servletContext,
146+
requestInfo,
147+
null,
148+
pr.handler.getServletInfo().isAsyncSupported(),
149+
pr.handler.getMultipartSecurityContext());
150+
}else {
151+
wrappedRequest = new ServletRequestMultipartWrapper(req,
152+
servletContext,
153+
requestInfo,
154+
null,
155+
pr.handler.getServletInfo().isAsyncSupported(),
156+
multipartConfig,
157+
pr.handler.getMultipartSecurityContext());
158+
}
144159
final FilterHandler[] filterHandlers = handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
145160

146161
try

http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,25 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser
6767

6868
try
6969
{
70-
final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
71-
this.resolution.handler.getContext(),
72-
this.requestInfo,
73-
DispatcherType.FORWARD,
74-
this.resolution.handler.getServletInfo().isAsyncSupported(),
75-
this.resolution.handler.getMultipartConfig(),
76-
this.resolution.handler.getMultipartSecurityContext());
70+
MultipartConfig multipartConfig = this.resolution.handler.getMultipartConfig();
71+
ServletRequestWrapper req;
72+
if (multipartConfig == null) {
73+
req = new ServletRequestWrapper((HttpServletRequest) request,
74+
this.resolution.handler.getContext(),
75+
this.requestInfo,
76+
DispatcherType.FORWARD,
77+
this.resolution.handler.getServletInfo().isAsyncSupported(),
78+
this.resolution.handler.getMultipartSecurityContext());
79+
80+
} else {
81+
req = new ServletRequestMultipartWrapper((HttpServletRequest) request,
82+
this.resolution.handler.getContext(),
83+
this.requestInfo,
84+
DispatcherType.FORWARD,
85+
this.resolution.handler.getServletInfo().isAsyncSupported(),
86+
multipartConfig,
87+
this.resolution.handler.getMultipartSecurityContext());
88+
}
7789
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
7890
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
7991

@@ -104,13 +116,26 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser
104116
@Override
105117
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
106118
{
107-
final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
108-
this.resolution.handler.getContext(),
109-
this.requestInfo,
110-
DispatcherType.INCLUDE,
111-
this.resolution.handler.getServletInfo().isAsyncSupported(),
112-
this.resolution.handler.getMultipartConfig(),
113-
this.resolution.handler.getMultipartSecurityContext());
119+
MultipartConfig multipartConfig = this.resolution.handler.getMultipartConfig();
120+
ServletRequestWrapper req;
121+
if (multipartConfig == null) {
122+
req = new ServletRequestWrapper((HttpServletRequest) request,
123+
this.resolution.handler.getContext(),
124+
this.requestInfo,
125+
DispatcherType.INCLUDE,
126+
this.resolution.handler.getServletInfo().isAsyncSupported(),
127+
this.resolution.handler.getMultipartSecurityContext());
128+
} else {
129+
req = new ServletRequestMultipartWrapper((HttpServletRequest) request,
130+
this.resolution.handler.getContext(),
131+
this.requestInfo,
132+
DispatcherType.INCLUDE,
133+
this.resolution.handler.getServletInfo().isAsyncSupported(),
134+
multipartConfig,
135+
this.resolution.handler.getMultipartSecurityContext());
136+
137+
}
138+
114139
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
115140
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
116141

0 commit comments

Comments
 (0)