You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/04/10 17:10:04 UTC

[cxf] branch master updated (c355564 -> cc0155e)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from c355564  CXF-7693 - If JwtConstants.EXPECTED_CLAIM_AUDIENCE is set then it must be present in the token
     new 4b84baa  Defining constants for caching in a separate file
     new cc0155e  CXF-7688 - AttachmentDeserializer does not respect "org.apache.cxf.io.CachedOutputStream.Threshold" property

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../cxf/attachment/AttachmentDeserializer.java     | 14 ++---
 .../org/apache/cxf/attachment/AttachmentUtil.java  |  5 +-
 .../java/org/apache/cxf/io/CachedConstants.java    | 71 ++++++++++++++++++++++
 .../java/org/apache/cxf/io/CachedOutputStream.java | 21 ++++---
 .../main/java/org/apache/cxf/io/CachedWriter.java  | 15 ++---
 .../org/apache/cxf/io/CachedOutputStreamTest.java  | 41 ++++++++++++-
 .../org/apache/cxf/io/CachedStreamTestBase.java    | 14 ++---
 7 files changed, 148 insertions(+), 33 deletions(-)
 create mode 100644 core/src/main/java/org/apache/cxf/io/CachedConstants.java

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf] 01/02: Defining constants for caching in a separate file

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 4b84baa96a71431bb471763765c188165f83c1ca
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 10 16:55:26 2018 +0100

    Defining constants for caching in a separate file
---
 .../java/org/apache/cxf/io/CachedConstants.java    | 71 ++++++++++++++++++++++
 .../java/org/apache/cxf/io/CachedOutputStream.java | 21 ++++---
 .../main/java/org/apache/cxf/io/CachedWriter.java  | 15 ++---
 .../org/apache/cxf/io/CachedStreamTestBase.java    | 14 ++---
 4 files changed, 97 insertions(+), 24 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 0ef7a24..b966ee4 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");
+    static {
+        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;
             }
@@ -566,16 +567,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;
@@ -584,9 +584,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 9fd4b66..0f697a4 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java
@@ -56,7 +56,7 @@ public class CachedWriter extends Writer {
 
     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 +126,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;
             }
@@ -562,7 +562,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");
@@ -571,9 +571,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");
@@ -589,7 +590,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 0bf6a79..f71979e 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,9 +225,9 @@ 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);
 

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf] 02/02: CXF-7688 - AttachmentDeserializer does not respect "org.apache.cxf.io.CachedOutputStream.Threshold" property

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit cc0155e28ffff033690188caf86fa87e509b7617
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 10 17:31:44 2018 +0100

    CXF-7688 - AttachmentDeserializer does not respect "org.apache.cxf.io.CachedOutputStream.Threshold" property
---
 .../cxf/attachment/AttachmentDeserializer.java     | 14 ++++----
 .../org/apache/cxf/attachment/AttachmentUtil.java  |  5 ++-
 .../org/apache/cxf/io/CachedOutputStreamTest.java  | 41 +++++++++++++++++++++-
 3 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
index 92de751..7f46ec5 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
@@ -57,7 +57,7 @@ public class AttachmentDeserializer {
      * The maximum MIME Header Length. The default is 300.
      */
     public static final String ATTACHMENT_MAX_HEADER_SIZE = "attachment-max-header-size";
-    public static final int DEFAULT_MAX_HEADER_SIZE = 
+    public static final int DEFAULT_MAX_HEADER_SIZE =
         SystemPropertyAction.getInteger("org.apache.cxf.attachment-max-header-size", 300);
 
     public static final int THRESHOLD = 1024 * 100; //100K (byte unit)
@@ -69,15 +69,16 @@ public class AttachmentDeserializer {
 
     private static final Logger LOG = LogUtils.getL7dLogger(AttachmentDeserializer.class);
 
+    private static final int PUSHBACK_AMOUNT = 2048;
+
     private boolean lazyLoading = true;
 
-    private int pbAmount = 2048;
     private PushbackInputStream stream;
     private int createCount;
     private int closedCount;
     private boolean closed;
 
-    private byte boundary[];
+    private byte[] boundary;
 
     private String contentType;
 
@@ -134,8 +135,7 @@ public class AttachmentDeserializer {
             }
             boundary = boundaryString.getBytes("utf-8");
 
-            stream = new PushbackInputStream(message.getContent(InputStream.class),
-                                             pbAmount);
+            stream = new PushbackInputStream(message.getContent(InputStream.class), PUSHBACK_AMOUNT);
             if (!readTillFirstBoundary(stream, boundary)) {
                 throw new IOException("Couldn't find MIME boundary: " + boundaryString);
             }
@@ -151,7 +151,7 @@ public class AttachmentDeserializer {
             }
             val = AttachmentUtil.getHeader(ih, "Content-Transfer-Encoding");
 
-            MimeBodyPartInputStream mmps = new MimeBodyPartInputStream(stream, boundary, pbAmount);
+            MimeBodyPartInputStream mmps = new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT);
             InputStream ins = AttachmentUtil.decode(mmps, val);
             if (ins != mmps) {
                 ih.remove("Content-Transfer-Encoding");
@@ -293,7 +293,7 @@ public class AttachmentDeserializer {
      */
     private Attachment createAttachment(Map<String, List<String>> headers) throws IOException {
         InputStream partStream =
-            new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount),
+            new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT),
                                       this);
         createCount++;
 
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
index c11fa63..0496ec2 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -53,8 +53,10 @@ import javax.activation.MailcapCommandMap;
 import javax.activation.URLDataSource;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.io.CachedConstants;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
@@ -177,7 +179,8 @@ public final class AttachmentUtil {
             } else {
                 bos.setThreshold(Long.parseLong((String)threshold));
             }
-        } else {
+        } else if (SystemPropertyAction.getProperty(CachedConstants.THRESHOLD_SYS_PROP) == null) {
+            // Use the default AttachmentDeserializer Threshold only if there is no system property defined
             bos.setThreshold(AttachmentDeserializer.THRESHOLD);
         }
 
diff --git a/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java b/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
index 7d4366a..9a8299f 100644
--- a/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
@@ -22,6 +22,13 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.cxf.attachment.AttachmentUtil;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+
+import org.junit.Test;
 
 public class CachedOutputStreamTest extends CachedStreamTestBase {
 
@@ -62,7 +69,7 @@ public class CachedOutputStreamTest extends CachedStreamTestBase {
     @Override
     protected File getTmpFile(String result, Object cache) throws IOException {
         CachedOutputStream cos = (CachedOutputStream)cache;
-        cos.write(result.getBytes("utf-8"));
+        cos.write(result.getBytes(StandardCharsets.UTF_8));
         cos.flush();
         cos.getOut().close();
         return cos.getTempFile();
@@ -82,6 +89,38 @@ public class CachedOutputStreamTest extends CachedStreamTestBase {
     protected String readPartiallyFromStreamObject(Object cache, int len) throws IOException {
         return readPartiallyFromStream((InputStream)cache, len);
     }
+
+    @Test
+    public void testUseSysPropsWithAttachmentDeserializer() throws Exception {
+        String old = System.getProperty(CachedConstants.THRESHOLD_SYS_PROP);
+        try {
+            System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
+            reloadDefaultProperties();
+            CachedOutputStream cache = new CachedOutputStream();
+
+            Message message = new MessageImpl();
+            AttachmentUtil.setStreamedAttachmentProperties(message, cache);
+
+            File tmpfile = getTmpFile("Hello World!", cache);
+            assertNull("expects no tmp file", tmpfile);
+            cache.close();
+
+            System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, "4");
+            reloadDefaultProperties();
+            cache = new CachedOutputStream();
+            AttachmentUtil.setStreamedAttachmentProperties(message, cache);
+
+            tmpfile = getTmpFile("Hello World!", cache);
+            assertNotNull("expects a tmp file", tmpfile);
+            assertTrue("expects a tmp file", tmpfile.exists());
+            cache.close();
+            assertFalse("expects no tmp file", tmpfile.exists());
+        } finally {
+            if (old != null) {
+                System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old);
+            }
+        }
+    }
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.