diff src/org/eclipse/jetty/server/Request.java @ 859:3dcc52e17535

simplify multipart
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 21 Sep 2016 16:15:19 -0600
parents fa6158f29c45
children df84a1741687
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/Request.java	Wed Sep 21 15:02:19 2016 -0600
+++ b/src/org/eclipse/jetty/server/Request.java	Wed Sep 21 16:15:19 2016 -0600
@@ -46,7 +46,6 @@
 import javax.servlet.AsyncEvent;
 import javax.servlet.AsyncListener;
 import javax.servlet.DispatcherType;
-import javax.servlet.MultipartConfigElement;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -89,7 +88,6 @@
 import org.eclipse.jetty.util.LazyList;
 import org.eclipse.jetty.util.MultiException;
 import org.eclipse.jetty.util.MultiMap;
-import org.eclipse.jetty.util.MultiPartInputStream;
 import org.eclipse.jetty.util.StringUtil;
 import org.eclipse.jetty.util.URIUtil;
 import org.eclipse.jetty.util.UrlEncoded;
@@ -136,41 +134,6 @@
 	private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault());
 	private static final int __NONE = 0, _STREAM = 1, __READER = 2;
 
-	public static class MultiPartCleanerListener implements ServletRequestListener
-	{
-
-		@Override
-		public void requestDestroyed(ServletRequestEvent sre)
-		{
-			//Clean up any tmp files created by MultiPartInputStream
-			MultiPartInputStream mpis = (MultiPartInputStream)sre.getServletRequest().getAttribute(__MULTIPART_INPUT_STREAM);
-			if (mpis != null)
-			{
-				ContextHandler.Context context = (ContextHandler.Context)sre.getServletRequest().getAttribute(__MULTIPART_CONTEXT);
-
-				//Only do the cleanup if we are exiting from the context in which a servlet parsed the multipart files
-				if (context == sre.getServletContext())
-				{
-					try
-					{
-						mpis.deleteParts();
-					}
-					catch (MultiException e)
-					{
-						sre.getServletContext().log("Errors deleting multipart tmp files", e);
-					}
-				}
-			}
-		}
-
-		@Override
-		public void requestInitialized(ServletRequestEvent sre)
-		{
-			//nothing to do, multipart config set up by ServletHolder.handle()
-		}
-		
-	}
-	
 	
 	/* ------------------------------------------------------------ */
 	public static Request getRequest(HttpServletRequest request)
@@ -219,8 +182,6 @@
 	private Buffer _timeStampBuffer;
 	private HttpURI _uri;
 	
-	private MultiPartInputStream _multiPartInputStream; //if the request is a multi-part mime
-	
 	/* ------------------------------------------------------------ */
 	public Request()
 	{
@@ -1389,8 +1350,6 @@
 		_parameters = null;
 		_paramsExtracted = false;
 		_inputState = __NONE;
-
-		_multiPartInputStream = null;
 	}
 
 	/* ------------------------------------------------------------ */
@@ -1834,63 +1793,13 @@
 	/* ------------------------------------------------------------ */
 	public Part getPart(String name) throws IOException, ServletException
 	{                
-		getParts();
-		return _multiPartInputStream.getPart(name);
+		throw new UnsupportedOperationException();
 	}
 
 	/* ------------------------------------------------------------ */
 	public Collection<Part> getParts() throws IOException, ServletException
 	{
-		if (getContentType() == null || !getContentType().startsWith("multipart/form-data"))
-			throw new ServletException("Content-Type != multipart/form-data");
-		
-		if (_multiPartInputStream == null)
-			_multiPartInputStream = (MultiPartInputStream)getAttribute(__MULTIPART_INPUT_STREAM);
-		
-		if (_multiPartInputStream == null)
-		{
-			MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT);
-			
-			if (config == null)
-				throw new IllegalStateException("No multipart config for servlet");
-			
-			_multiPartInputStream = new MultiPartInputStream(getInputStream(), 
-															 getContentType(), config, 
-															 (_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null));
-			
-			setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
-			setAttribute(__MULTIPART_CONTEXT, _context);
-			Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing 
-			for (Part p:parts)
-			{
-				MultiPartInputStream.MultiPart mp = (MultiPartInputStream.MultiPart)p;
-				if (mp.getContentDispositionFilename() == null)
-				{
-					//Servlet Spec 3.0 pg 23, parts without filenames must be put into init params
-					String charset = null;
-					if (mp.getContentType() != null)
-						charset = MimeTypes.getCharsetFromContentType(new ByteArrayBuffer(mp.getContentType()));
-
-					ByteArrayOutputStream os = null;
-					InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file
-					try
-					{
-						os = new ByteArrayOutputStream();
-						IO.copy(is, os);
-						String content=new String(os.toByteArray(),charset==null?StringUtil.__UTF8:charset);   
-						getParameter(""); //cause params to be evaluated
-						getParameters().add(mp.getName(), content);
-					}
-					finally
-					{
-						IO.close(os);
-						IO.close(is);
-					}
-				}
-			}
-		}
-
-		return _multiPartInputStream.getParts();
+		throw new UnsupportedOperationException();
 	}
 
 	/* ------------------------------------------------------------ */