cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7443] Updating transport-level Headers to work with List of Objects
Date Thu, 13 Jul 2017 11:28:40 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes ff59c7404 -> 3a5b6e31b


[CXF-7443] Updating transport-level Headers to work with List of Objects


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3a5b6e31
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3a5b6e31
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3a5b6e31

Branch: refs/heads/3.1.x-fixes
Commit: 3a5b6e31b182d68ef0db47ba907be369321ba9c6
Parents: ff59c74
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Jul 13 12:14:37 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Jul 13 12:28:24 2017 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/transport/http/Headers.java  | 25 +++++++++++---------
 .../apache/cxf/transport/http/HeadersTest.java  | 20 ++++++++--------
 2 files changed, 24 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3a5b6e31/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
index 8aecbd3..c66b4b9 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
@@ -72,7 +72,7 @@ public class Headers {
     private static final Logger LOG = LogUtils.getL7dLogger(Headers.class);
 
     private static final List<String> SENSITIVE_HEADERS = Arrays.asList("Authorization",
"Proxy-Authorization");
-    private static final List<String> SENSITIVE_HEADER_MARKER = Arrays.asList("***");
+    private static final List<Object> SENSITIVE_HEADER_MARKER = Arrays.asList((Object)"***");
     private static final String ALLOW_LOGGING_SENSITIVE_HEADERS = "allow.logging.sensitive.headers";
     /**
      * Known HTTP headers whose values have to be represented as individual HTTP headers
@@ -119,8 +119,8 @@ public class Headers {
      * filtered keys), so it should be used sparingly - i.e. only when debug is
      * enabled.
      */
-    static String toString(Map<String, List<String>> headers, boolean logSensitiveHeaders)
{
-        Map<String, List<String>> filteredHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
+    static String toString(Map<String, List<Object>> headers, boolean logSensitiveHeaders)
{
+        Map<String, List<Object>> filteredHeaders = new TreeMap<String, List<Object>>(String.CASE_INSENSITIVE_ORDER);
         filteredHeaders.putAll(headers);
         if (!logSensitiveHeaders) {
             for (String filteredKey : SENSITIVE_HEADERS) {
@@ -311,16 +311,16 @@ public class Headers {
      * @param level   The Logging Level.
      * @param headers The Message protocol headers.
      */
-    static void logProtocolHeaders(Logger logger, Level level, 
-                                   Map<String, List<String>> headersMap,
+    static void logProtocolHeaders(Logger logger, Level level,
+                                   Map<String, List<Object>> headersMap,
                                    boolean logSensitiveHeaders) {
         if (logger.isLoggable(level)) {
-            for (Map.Entry<String, List<String>> entry : headersMap.entrySet())
{
+            for (Map.Entry<String, List<Object>> entry : headersMap.entrySet())
{
                 String key = entry.getKey();
                 boolean sensitive = !logSensitiveHeaders && SENSITIVE_HEADERS.contains(key);
-                List<String> headerList = sensitive ? SENSITIVE_HEADER_MARKER : entry.getValue();
-                for (String value : headerList) {
-                    logger.log(level, key + ": " 
+                List<Object> headerList = sensitive ? SENSITIVE_HEADER_MARKER : entry.getValue();
+                for (Object value : headerList) {
+                    logger.log(level, key + ": "
                         + (value == null ? "<null>" : value.toString()));
                 }
             }
@@ -367,7 +367,9 @@ public class Headers {
         }
          
         transferProtocolHeadersToURLConnection(connection);
-        logProtocolHeaders(LOG, Level.FINE, headers, logSensitiveHeaders());
+        
+        Map<String, List<Object>> theHeaders = CastUtils.cast(headers);
+        logProtocolHeaders(LOG, Level.FINE, theHeaders, logSensitiveHeaders());
     }
 
     public String determineContentType() {
@@ -456,7 +458,8 @@ public class Headers {
             headers.put(Message.CONTENT_TYPE, Collections.singletonList(req.getContentType()));
         }
         if (LOG.isLoggable(Level.FINE)) {
-            LOG.log(Level.FINE, "Request Headers: " + toString(headers, 
+            Map<String, List<Object>> theHeaders = CastUtils.cast(headers);
+            LOG.log(Level.FINE, "Request Headers: " + toString(theHeaders,
                                                                logSensitiveHeaders()));
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3a5b6e31/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HeadersTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HeadersTest.java
b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HeadersTest.java
index 480521c..27e1f1c 100755
--- a/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HeadersTest.java
+++ b/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HeadersTest.java
@@ -95,11 +95,11 @@ public class HeadersTest extends Assert {
 
     @Test
     public void sensitiveHeadersTest() {
-        Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
-        headerMap.put("Authorization", Arrays.asList("FAIL"));
-        headerMap.put("Proxy-Authorization", Arrays.asList("FAIL"));
-        headerMap.put("Content-Type", Arrays.asList("application/xml"));
-        headerMap.put("Accept", Arrays.asList("text/plain"));
+        Map<String, List<Object>> headerMap = new HashMap<String, List<Object>>();
+        headerMap.put("Authorization", Arrays.asList((Object)"FAIL"));
+        headerMap.put("Proxy-Authorization", Arrays.asList((Object)"FAIL"));
+        headerMap.put("Content-Type", Arrays.asList((Object)"application/xml"));
+        headerMap.put("Accept", Arrays.asList((Object)"text/plain"));
 
         String loggedString = Headers.toString(headerMap, false);
         assertFalse("The value of a sensitive header could be logged: " + loggedString, loggedString.contains("FAIL"));
@@ -112,11 +112,11 @@ public class HeadersTest extends Assert {
 
     @Test
     public void logProtocolHeadersTest() {
-        Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
-        headerMap.put("Normal-Header", Arrays.asList("normal"));
-        headerMap.put("Multivalue-Header", Arrays.asList("first", "second"));
-        headerMap.put("Authorization", Arrays.asList("myPassword"));
-        headerMap.put("Null-Header", Arrays.asList((String)null));
+        Map<String, List<Object>> headerMap = new HashMap<String, List<Object>>();
+        headerMap.put("Normal-Header", Arrays.asList((Object)"normal"));
+        headerMap.put("Multivalue-Header", Arrays.asList((Object)"first", (Object)"second"));
+        headerMap.put("Authorization", Arrays.asList((Object)"myPassword"));
+        headerMap.put("Null-Header", Arrays.asList((Object)null));
 
         //Set up test logger
         Logger logger = Logger.getAnonymousLogger();


Mime
View raw message