cziegeler commented on code in PR #367: URL: https://github.com/apache/felix-dev/pull/367#discussion_r1912729481
########## http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletRequestWrapper.java: ########## @@ -411,143 +381,17 @@ public boolean isAsyncSupported() return this.asyncSupported; } - private RequestContext getMultipartContext() { - final RequestContext multipartContext; - if (!POST_METHOD.equalsIgnoreCase(this.getMethod())) { - multipartContext = null; - } else { - multipartContext = new RequestContext() { - - @Override - public InputStream getInputStream() throws IOException { - return ServletRequestWrapper.this.getInputStream(); - } - - @Override - public String getContentType() { - return ServletRequestWrapper.this.getContentType(); - } - - @Override - public int getContentLength() { - return ServletRequestWrapper.this.getContentLength(); - } - - @Override - public String getCharacterEncoding() { - return ServletRequestWrapper.this.getCharacterEncoding(); - } - }; - } - return multipartContext; - } - - private Collection<PartImpl> checkMultipart() throws IOException, ServletException { - if ( parts == null ) { - final RequestContext multipartContext = getMultipartContext(); - if ( multipartContext != null && FileUploadBase.isMultipartContent(multipartContext) ) { - if ( this.multipartConfig == null) { - throw new IllegalStateException("Multipart not enabled for servlet."); - } - - if ( System.getSecurityManager() == null ) { - handleMultipart(multipartContext); - } else { - final AccessControlContext ctx = bundleForSecurityCheck.adapt(AccessControlContext.class); - final IOException ioe = AccessController.doPrivileged(new PrivilegedAction<IOException>() { - - @Override - public IOException run() { - try { - handleMultipart(multipartContext); - } catch ( final IOException ioe) { - return ioe; - } - return null; - } - }, ctx); - if ( ioe != null ) { - throw ioe; - } - } - - } else { - throw new ServletException("Not a multipart request"); - } - } - return parts; - } - - private void handleMultipart(final RequestContext multipartContext) throws IOException { - // Create a new file upload handler - final FileUpload upload = new FileUpload(); - upload.setSizeMax(this.multipartConfig.multipartMaxRequestSize); - upload.setFileSizeMax(this.multipartConfig.multipartMaxFileSize); - upload.setFileItemFactory(new DiskFileItemFactory(this.multipartConfig.multipartThreshold, - new File(this.multipartConfig.multipartLocation))); - upload.setFileCountMax(this.multipartConfig.multipartMaxFileCount); - // Parse the request - List<FileItem> items = null; - try { - items = upload.parseRequest(multipartContext); - } catch (final FileUploadException fue) { - throw new IOException("Error parsing multipart request", fue); - } - this.parts = new ArrayList<>(); - for(final FileItem item : items) { - this.parts.add(new PartImpl(item)); - } - } - @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Collection<Part> getParts() throws IOException, ServletException { - return (Collection)checkMultipart(); - + return null; Review Comment: According to the servlet spec, this method either throws a ServletException if the request is not a multipart request or always returns a collection. It never returns null. Throwing an exception seems to be the right thing -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@felix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org