Skip to content

Commit 748a935

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 748a935

File tree

5 files changed

+386
-267
lines changed

5 files changed

+386
-267
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,24 @@ 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+
}else {
150+
wrappedRequest = new ServletRequestMultipartWrapper(req,
151+
servletContext,
152+
requestInfo,
153+
null,
154+
pr.handler.getServletInfo().isAsyncSupported(),
155+
multipartConfig,
156+
pr.handler.getMultipartSecurityContext());
157+
}
144158
final FilterHandler[] filterHandlers = handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
145159

146160
try

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

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,24 @@ 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+
79+
} else {
80+
req = new ServletRequestMultipartWrapper((HttpServletRequest) request,
81+
this.resolution.handler.getContext(),
82+
this.requestInfo,
83+
DispatcherType.FORWARD,
84+
this.resolution.handler.getServletInfo().isAsyncSupported(),
85+
multipartConfig,
86+
this.resolution.handler.getMultipartSecurityContext());
87+
}
7788
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
7889
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
7990

@@ -104,13 +115,25 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser
104115
@Override
105116
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
106117
{
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());
118+
MultipartConfig multipartConfig = this.resolution.handler.getMultipartConfig();
119+
ServletRequestWrapper req;
120+
if (multipartConfig == null) {
121+
req = new ServletRequestWrapper((HttpServletRequest) request,
122+
this.resolution.handler.getContext(),
123+
this.requestInfo,
124+
DispatcherType.INCLUDE,
125+
this.resolution.handler.getServletInfo().isAsyncSupported());
126+
} else {
127+
req = new ServletRequestMultipartWrapper((HttpServletRequest) request,
128+
this.resolution.handler.getContext(),
129+
this.requestInfo,
130+
DispatcherType.INCLUDE,
131+
this.resolution.handler.getServletInfo().isAsyncSupported(),
132+
multipartConfig,
133+
this.resolution.handler.getMultipartSecurityContext());
134+
135+
}
136+
114137
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
115138
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
116139

0 commit comments

Comments
 (0)