cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1213457 - in /cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging: JDKBugHacks.java LogUtils.java
Date Mon, 12 Dec 2011 21:56:43 GMT
Author: dkulp
Date: Mon Dec 12 21:56:43 2011
New Revision: 1213457

URL: http://svn.apache.org/viewvc?rev=1213457&view=rev
Log:
[CXF-3867] Add a couple methods for keeping the URLConnection
defaultUsesCaches thing set to true.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java?rev=1213457&r1=1213456&r2=1213457&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java Mon
Dec 12 21:56:43 2011
@@ -19,16 +19,22 @@
 
 package org.apache.cxf.common.logging;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import javax.imageio.ImageIO;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
+import org.apache.cxf.common.util.StringUtils;
 
 /**
  * This is called from LogUtils as LogUtils is almost always one of the VERY
@@ -47,6 +53,41 @@ final class JDKBugHacks {
         //not constructed
     }
     
+    private static boolean skipHack(final String key) {
+        String cname = null;
+        try {
+            cname = AccessController.doPrivileged(new PrivilegedAction<String>() {
+                public String run() {
+                    return System.getProperty(key);
+                }
+            });
+            if (StringUtils.isEmpty(cname)) {
+                InputStream ins = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream("META-INF/cxf/" + key);
+                if (ins == null) {
+                    ins = ClassLoader.getSystemResourceAsStream("META-INF/cxf/" + key);
+                }
+                if (ins != null) {
+                    BufferedReader din = new BufferedReader(new InputStreamReader(ins));
+                    try {
+                        cname = din.readLine();
+                        if (cname != null) {
+                            cname.trim();
+                        }
+                    } finally {
+                        din.close();
+                    }
+                }
+            }
+        } catch (Throwable t) {
+            //ignore
+        }
+        if (cname == null) {
+            cname = "false";
+        }
+        return Boolean.parseBoolean(cname);
+    }
+    
     public static void doHacks() {
         try {
             // Use the system classloader as the victim for all this
@@ -67,14 +108,17 @@ final class JDKBugHacks {
                     // JAXB does this and thus affects us pretty badly.
                     // Doesn't matter that this JAR doesn't exist - just as long as
                     // the URL is well-formed
-                    URL url = new URL("jar:file://dummy.jar!/");
-                    URLConnection uConn = new URLConnection(url) {
-                        @Override
-                        public void connect() throws IOException {
-                            // NOOP
-                        }
-                    };
-                    uConn.setDefaultUseCaches(false);
+                    boolean skip = skipHack("org.apache.cxf.JDKBugHacks.defaultUsesCaches");
+                    if (!skip) {
+                        URL url = new URL("jar:file://dummy.jar!/");
+                        URLConnection uConn = new URLConnection(url) {
+                            @Override
+                            public void connect() throws IOException {
+                                // NOOP
+                            }
+                        };
+                        uConn.setDefaultUseCaches(false);
+                    }
                 } catch (Throwable e) {
                     //ignore
                 }

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1213457&r1=1213456&r2=1213457&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java Mon
Dec 12 21:56:43 2011
@@ -24,6 +24,8 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.text.MessageFormat;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
@@ -33,7 +35,6 @@ import java.util.logging.Logger;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.SystemPropertyAction;
 
 
 /**
@@ -67,7 +68,18 @@ public final class LogUtils {
         JDKBugHacks.doHacks();
         
         try {
-            String cname = SystemPropertyAction.getPropertyOrNull(KEY);
+            
+            String cname = null;
+            try {
+                cname = AccessController.doPrivileged(new PrivilegedAction<String>()
{
+                    public String run() {
+                        return System.getProperty(KEY);
+                    }
+                });
+            } catch (Throwable t) {
+                //ignore - likely security exception or similar that won't allow
+                //access to the system properties.   We'll continue with other methods
+            }
             if (StringUtils.isEmpty(cname)) {
                 InputStream ins = Thread.currentThread().getContextClassLoader()
                     .getResourceAsStream("META-INF/cxf/" + KEY);



Mime
View raw message