Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-util/src/main')
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java26
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java10
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java39
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java22
4 files changed, 90 insertions, 7 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
index 72f53fb6e3..8b3ef9702e 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
@@ -63,6 +63,7 @@ public class MultiPartInputStreamParser
protected File _tmpDir;
protected File _contextTmpDir;
protected boolean _deleteOnExit;
+ protected boolean _writeFilesWithFilenames;
@@ -94,9 +95,19 @@ public class MultiPartInputStreamParser
protected void open()
throws IOException
{
- //Write to a buffer in memory until we discover we've exceed the
- //MultipartConfig fileSizeThreshold
- _out = _bout= new ByteArrayOutputStream2();
+ //We will either be writing to a file, if it has a filename on the content-disposition
+ //and otherwise a byte-array-input-stream, OR if we exceed the getFileSizeThreshold, we
+ //will need to change to write to a file.
+ if (isWriteFilesWithFilenames() && _filename != null && _filename.trim().length() > 0)
+ {
+ createFile();
+ }
+ else
+ {
+ //Write to a buffer in memory until we discover we've exceed the
+ //MultipartConfig fileSizeThreshold
+ _out = _bout= new ByteArrayOutputStream2();
+ }
}
protected void close()
@@ -751,6 +762,15 @@ public class MultiPartInputStreamParser
_deleteOnExit = deleteOnExit;
}
+ public void setWriteFilesWithFilenames (boolean writeFilesWithFilenames)
+ {
+ _writeFilesWithFilenames = writeFilesWithFilenames;
+ }
+
+ public boolean isWriteFilesWithFilenames ()
+ {
+ return _writeFilesWithFilenames;
+ }
public boolean isDeleteOnExit()
{
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
index ef6a74bd82..acdf703e18 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.util.thread;
import java.lang.reflect.Constructor;
import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.log.Log;
@@ -53,6 +54,15 @@ public interface ExecutionStrategy
*/
public void execute();
+
+ /**
+ * A task that can handle {@link RejectedExecutionException}
+ */
+ public interface Rejectable
+ {
+ public void reject();
+ }
+
/**
* <p>A producer of {@link Runnable} tasks to run.</p>
* <p>The {@link ExecutionStrategy} will repeatedly invoke {@link #produce()} until
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
index d3053221b0..4643775e6a 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.util.thread.strategy;
import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -140,7 +141,15 @@ public class ExecuteProduceConsume implements ExecutionStrategy, Runnable
while (_threadpool!=null && _threadpool.isLowOnThreads())
{
LOG.debug("EWYK low resources {}",this);
- _lowresources.execute();
+ try
+ {
+ _lowresources.execute();
+ }
+ catch(Throwable e)
+ {
+ // just warn if lowresources execute fails and keep producing
+ LOG.warn(e);
+ }
}
// no longer low resources so produceAndRun normally
@@ -204,13 +213,37 @@ public class ExecuteProduceConsume implements ExecutionStrategy, Runnable
// Spawn a new thread to continue production by running the produce loop.
if (LOG.isDebugEnabled())
LOG.debug("{} dispatch",this);
- _executor.execute(this);
+ try
+ {
+ _executor.execute(this);
+ }
+ catch(RejectedExecutionException e)
+ {
+ // If we cannot execute, then discard/reject the task and keep producing
+ LOG.debug(e);
+ LOG.warn("RejectedExecution {}",task);
+ try
+ {
+ if (task instanceof Rejectable)
+ ((Rejectable)task).reject();
+ }
+ catch (Exception x)
+ {
+ e.addSuppressed(x);
+ LOG.warn(e);
+ }
+ finally
+ {
+ task=null;
+ }
+ }
}
// Run the task.
if (LOG.isDebugEnabled())
LOG.debug("{} run {}",this,task);
- task.run();
+ if (task != null)
+ task.run();
if (LOG.isDebugEnabled())
LOG.debug("{} ran {}",this,task);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
index 64903a6fbd..9310c05d5f 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.util.thread.strategy;
import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -55,7 +56,26 @@ public class ProduceExecuteConsume implements ExecutionStrategy
break;
// Execute the task.
- _executor.execute(task);
+ try
+ {
+ _executor.execute(task);
+ }
+ catch(RejectedExecutionException e)
+ {
+ // Discard/reject tasks that cannot be executed
+ if (task instanceof Rejectable)
+ {
+ try
+ {
+ ((Rejectable)task).reject();
+ }
+ catch (Throwable x)
+ {
+ e.addSuppressed(x);
+ LOG.warn(e);
+ }
+ }
+ }
}
}

Back to the top