Author: mmusaji
Date: 2011-06-15 07:29:59 -0400 (Wed, 15 Jun 2011)
New Revision: 14566
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP08_JBPAPP-6707/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
Log:
JBPAPP-6707 Add property org.jboss.mtom.maxMemSize allowing users to specify max mem size
of attachments before written to tmp file on disk
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP08_JBPAPP-6707/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
===================================================================
---
stack/native/branches/jbossws-native-2.0.1.SP2_CP08_JBPAPP-6707/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2011-06-14
15:45:29 UTC (rev 14565)
+++
stack/native/branches/jbossws-native-2.0.1.SP2_CP08_JBPAPP-6707/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2011-06-15
11:29:59 UTC (rev 14566)
@@ -62,6 +62,9 @@
private int contentLength;
private int maxMemorySize = 64 * 1024;
+
+ //JVM argument lets users specify maxMemorySize on start up - in KB.
+ private static final String MAX_MEMORY_SIZE_PROPERTY =
"org.jboss.mtom.maxMemSize";
/**
@@ -91,11 +94,23 @@
*/
public SwapableMemoryDataSource(InputStream inputStream, String contentType, int
maxMemorySize) throws IOException
{
- if (contentType != null)
+ if (contentType != null) {
this.contentType = contentType;
+ }
+
+ String property = System.getProperty(MAX_MEMORY_SIZE_PROPERTY);
+ if(property != null) {
+ try {
+ int maxMemSizeInt = Integer.valueOf(property);
+ this.maxMemorySize = maxMemSizeInt * 1024;
+ }catch(NumberFormatException nfe) {
+ this.maxMemorySize = maxMemorySize;
+ log.info("Invalid argument provided for " +
MAX_MEMORY_SIZE_PROPERTY + " - using default: " + this.maxMemorySize);
+ }
+ }else { //use default 64K for maxMemorySize
+ this.maxMemorySize = maxMemorySize;
+ }
- this.maxMemorySize = maxMemorySize;
-
load(inputStream);
}
@@ -108,15 +123,17 @@
int count = inputStream.read(buffer);
while (count > 0) {
os.write(buffer, 0, count);
-
- if (rbaos != null && rbaos.size() > maxMemorySize)
- {
- File tmpdir = IOUtils.createTempDirectory();
- swapFile = File.createTempFile(SWAP_PREFIX, SWAP_SUFFIX, tmpdir);
- swapFile.deleteOnExit();
- os = new FileOutputStream(swapFile);
- rbaos.writeTo(os);
- rbaos = null;
+
+ if(maxMemorySize > 0) { //never write to disk if negative number
+ if ((rbaos != null) && (rbaos.size() > maxMemorySize))
+ {
+ File tmpdir = IOUtils.createTempDirectory();
+ swapFile = File.createTempFile(SWAP_PREFIX, SWAP_SUFFIX, tmpdir);
+ swapFile.deleteOnExit();
+ os = new FileOutputStream(swapFile);
+ rbaos.writeTo(os);
+ rbaos = null;
+ }
}
count = inputStream.read(buffer);
Show replies by date