This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch 3.1.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 146880e5bd28ef4ec3174861ce3b4a2d76a1030f Author: Colm O hEigeartaigh <cohei...@apache.org> AuthorDate: Tue Apr 10 16:55:26 2018 +0100 Defining constants for caching in a separate file (cherry picked from commit 4b84baa96a71431bb471763765c188165f83c1ca) # Conflicts: # core/src/main/java/org/apache/cxf/io/CachedOutputStream.java # core/src/main/java/org/apache/cxf/io/CachedWriter.java # core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java --- .../java/org/apache/cxf/io/CachedConstants.java | 71 ++++++++++++++++++++++ .../java/org/apache/cxf/io/CachedOutputStream.java | 21 ++++--- .../main/java/org/apache/cxf/io/CachedWriter.java | 16 ++--- .../org/apache/cxf/io/CachedStreamTestBase.java | 18 +++--- 4 files changed, 99 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/apache/cxf/io/CachedConstants.java b/core/src/main/java/org/apache/cxf/io/CachedConstants.java new file mode 100644 index 0000000..f8e32b7 --- /dev/null +++ b/core/src/main/java/org/apache/cxf/io/CachedConstants.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.io; + +public final class CachedConstants { + + /** + * The directory name for storing the temporary files. None is specified by default. + */ + public static final String OUTPUT_DIRECTORY_SYS_PROP = + "org.apache.cxf.io.CachedOutputStream.OutputDirectory"; + + /** + * The threshold value in bytes to switch from memory to file caching. The default value is 128K for + * CachedOutputStream and 64K for CachedWriter. + */ + public static final String THRESHOLD_SYS_PROP = + "org.apache.cxf.io.CachedOutputStream.Threshold"; + + /** + * The threshold value in bytes to switch from memory to file caching. The default value is 128K for + * CachedOutputStream and 64K for CachedWriter. + */ + public static final String THRESHOLD_BUS_PROP = + "bus.io.CachedOutputStream.Threshold"; + + /** + * The data size in bytes to limit the maximum data size to be cached. No max size is set by default. + */ + public static final String MAX_SIZE_SYS_PROP = + "org.apache.cxf.io.CachedOutputStream.MaxSize"; + + /** + * The data size in bytes to limit the maximum data size to be cached. No max size is set by default. + */ + public static final String MAX_SIZE_BUS_PROP = + "bus.io.CachedOutputStream.MaxSize"; + + /** + * The cipher transformation name for encrypting the cached content. None is specified by default. + */ + public static final String CIPHER_TRANSFORMATION_SYS_PROP = + "org.apache.cxf.io.CachedOutputStream.CipherTransformation"; + + /** + * The cipher transformation name for encrypting the cached content. None is specified by default. + */ + public static final String CIPHER_TRANSFORMATION_BUS_PROP = + "bus.io.CachedOutputStream.CipherTransformation"; + + private CachedConstants() { + // complete + } +} diff --git a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java index 7f241b0..9490dba 100644 --- a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java +++ b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java @@ -48,13 +48,14 @@ import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.helpers.LoadingByteArrayOutputStream; public class CachedOutputStream extends OutputStream { + private static final File DEFAULT_TEMP_DIR; private static int defaultThreshold; private static long defaultMaxSize; private static String defaultCipherTransformation; + static { - - String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.OutputDirectory"); + String s = SystemPropertyAction.getPropertyOrNull(CachedConstants.OUTPUT_DIRECTORY_SYS_PROP); if (s != null) { File f = new File(s); if (f.exists() && f.isDirectory()) { @@ -106,15 +107,15 @@ public class CachedOutputStream extends OutputStream { private void readBusProperties() { Bus b = BusFactory.getThreadDefaultBus(false); if (b != null) { - String v = getBusProperty(b, "bus.io.CachedOutputStream.Threshold", null); + String v = getBusProperty(b, CachedConstants.THRESHOLD_BUS_PROP, null); if (v != null && threshold == defaultThreshold) { threshold = Integer.parseInt(v); } - v = getBusProperty(b, "bus.io.CachedOutputStream.MaxSize", null); + v = getBusProperty(b, CachedConstants.MAX_SIZE_BUS_PROP, null); if (v != null) { maxSize = Integer.parseInt(v); } - v = getBusProperty(b, "bus.io.CachedOutputStream.CipherTransformation", null); + v = getBusProperty(b, CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP, null); if (v != null) { cipherTransformation = v; } @@ -569,16 +570,15 @@ public class CachedOutputStream extends OutputStream { public static void setDefaultMaxSize(long l) { if (l == -1) { - String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.MaxSize", - "-1"); + String s = SystemPropertyAction.getProperty(CachedConstants.MAX_SIZE_SYS_PROP, "-1"); l = Long.parseLong(s); } defaultMaxSize = l; } + public static void setDefaultThreshold(int i) { if (i == -1) { - String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold", - "-1"); + String s = SystemPropertyAction.getProperty(CachedConstants.THRESHOLD_SYS_PROP, "-1"); i = Integer.parseInt(s); if (i <= 0) { i = 128 * 1024; @@ -587,9 +587,10 @@ public class CachedOutputStream extends OutputStream { defaultThreshold = i; } + public static void setDefaultCipherTransformation(String n) { if (n == null) { - n = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.CipherTransformation"); + n = SystemPropertyAction.getPropertyOrNull(CachedConstants.CIPHER_TRANSFORMATION_SYS_PROP); } defaultCipherTransformation = n; } diff --git a/core/src/main/java/org/apache/cxf/io/CachedWriter.java b/core/src/main/java/org/apache/cxf/io/CachedWriter.java index dfcf3c4..99a0cca 100644 --- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java +++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java @@ -55,8 +55,7 @@ public class CachedWriter extends Writer { private static String defaultCipherTransformation; static { - - String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.OutputDirectory"); + String s = SystemPropertyAction.getPropertyOrNull(CachedConstants.OUTPUT_DIRECTORY_SYS_PROP); if (s == null) { // lookup the deprecated property s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedWriter.OutputDirectory"); @@ -126,15 +125,15 @@ public class CachedWriter extends Writer { private void readBusProperties() { Bus b = BusFactory.getThreadDefaultBus(false); if (b != null) { - String v = getBusProperty(b, "bus.io.CachedOutputStream.Threshold", null); + String v = getBusProperty(b, CachedConstants.THRESHOLD_BUS_PROP, null); if (v != null && threshold == defaultThreshold) { threshold = Integer.parseInt(v); } - v = getBusProperty(b, "bus.io.CachedOutputStream.MaxSize", null); + v = getBusProperty(b, CachedConstants.MAX_SIZE_BUS_PROP, null); if (v != null) { maxSize = Integer.parseInt(v); } - v = getBusProperty(b, "bus.io.CachedOutputStream.CipherTransformation", null); + v = getBusProperty(b, CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP, null); if (v != null) { cipherTransformation = v; } @@ -566,7 +565,7 @@ public class CachedWriter extends Writer { public static void setDefaultMaxSize(long l) { if (l == -1) { - String s = System.getProperty("org.apache.cxf.io.CachedOutputStream.MaxSize"); + String s = System.getProperty(CachedConstants.MAX_SIZE_SYS_PROP); if (s == null) { // lookup the deprecated property s = System.getProperty("org.apache.cxf.io.CachedWriter.MaxSize", "-1"); @@ -575,9 +574,10 @@ public class CachedWriter extends Writer { } defaultMaxSize = l; } + public static void setDefaultThreshold(int i) { if (i == -1) { - String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold"); + String s = SystemPropertyAction.getProperty(CachedConstants.THRESHOLD_SYS_PROP); if (s == null) { // lookup the deprecated property s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedWriter.Threshold", "-1"); @@ -593,7 +593,7 @@ public class CachedWriter extends Writer { public static void setDefaultCipherTransformation(String n) { if (n == null) { - n = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.CipherTransformation"); + n = SystemPropertyAction.getPropertyOrNull(CachedConstants.CIPHER_TRANSFORMATION_SYS_PROP); } defaultCipherTransformation = n; } diff --git a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java index ec56639..074e835 100755 --- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java +++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java @@ -188,16 +188,16 @@ public abstract class CachedStreamTestBase extends Assert { @Test public void testUseSysProps() throws Exception { - String old = System.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold"); + String old = System.getProperty(CachedConstants.THRESHOLD_SYS_PROP); try { - System.clearProperty("org.apache.cxf.io.CachedOutputStream.Threshold"); + System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP); reloadDefaultProperties(); Object cache = createCache(); File tmpfile = getTmpFile("Hello World!", cache); assertNull("expects no tmp file", tmpfile); close(cache); - - System.setProperty("org.apache.cxf.io.CachedOutputStream.Threshold", "4"); + + System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, "4"); reloadDefaultProperties(); cache = createCache(); tmpfile = getTmpFile("Hello World!", cache); @@ -207,7 +207,7 @@ public abstract class CachedStreamTestBase extends Assert { assertFalse("expects no tmp file", tmpfile.exists()); } finally { if (old != null) { - System.setProperty("org.apache.cxf.io.CachedOutputStream.Threshold", old); + System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old); } } } @@ -225,10 +225,10 @@ public abstract class CachedStreamTestBase extends Assert { IMocksControl control = EasyMock.createControl(); Bus b = control.createMock(Bus.class); - EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.Threshold")).andReturn("4"); - EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.MaxSize")).andReturn(null); - EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.CipherTransformation")).andReturn(null); - + EasyMock.expect(b.getProperty(CachedConstants.THRESHOLD_BUS_PROP)).andReturn("4"); + EasyMock.expect(b.getProperty(CachedConstants.MAX_SIZE_BUS_PROP)).andReturn(null); + EasyMock.expect(b.getProperty(CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP)).andReturn(null); + BusFactory.setThreadDefaultBus(b); control.replay(); -- To stop receiving notification emails like this one, please contact cohei...@apache.org.