cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buhhu...@apache.org
Subject [cxf] branch master updated: CXF-7923 String.split via fastpath instead of precompiled Pattern (#481)
Date Fri, 07 Dec 2018 15:13:44 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new cd55616  CXF-7923 String.split via fastpath instead of precompiled Pattern (#481)
cd55616 is described below

commit cd55616673c20a6cde063904686b318ce175c71f
Author: Alexey Markevich <amarkevich@talend.com>
AuthorDate: Fri Dec 7 18:13:39 2018 +0300

    CXF-7923 String.split via fastpath instead of precompiled Pattern (#481)
    
    * CXF-7923 String.split via fastpath instead of precompiled Pattern
    
    * fix checkstyle
---
 .../org/apache/cxf/common/util/PackageUtils.java   |   5 +-
 .../org/apache/cxf/common/util/StringUtils.java    |  54 +----
 .../apache/cxf/common/util/StringUtilsTest.java    |  46 ----
 .../org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java |  18 +-
 .../apache/cxf/jaxrs/impl/HttpHeadersImplTest.java | 251 +++++++--------------
 .../transport/http/AbstractHTTPDestination.java    |  10 +-
 6 files changed, 108 insertions(+), 276 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
index f35cd11..70de559 100644
--- a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
@@ -21,6 +21,7 @@ package org.apache.cxf.common.util;
 
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -57,7 +58,7 @@ public final class PackageUtils {
         List<String> currentParts = new ArrayList<>();
         for (Class<?> cls : classes) {
             if (!Proxy.isProxyClass(cls)) {
-                lParts.add(StringUtils.getParts(getPackageName(cls), "\\."));
+                lParts.add(Arrays.asList(getPackageName(cls).split("\\.")));
             }
         }
         for (int i = 0; i < lParts.get(0).size(); i++) {
@@ -76,7 +77,7 @@ public final class PackageUtils {
         StringBuilder sb = new StringBuilder();
         for (String part : currentParts) {
             if (sb.length() > 0) {
-                sb.append(".");
+                sb.append('.');
             }
             sb.append(part);
         }
diff --git a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
index 2657d15..c06db7b 100644
--- a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
@@ -25,37 +25,18 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Predicate;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.stream.Stream;
 
 public final class StringUtils {
-    private static final Map<String, Pattern> PATTERN_MAP = new ConcurrentHashMap<>();
+
     private static final Predicate<String> NOT_EMPTY = (String s) -> !s.isEmpty();
 
     private StringUtils() {
     }
 
-    /* String.split via fastpath preferred */
-    public static String[] split(String s, String regex) {
-        return split(s, regex, 0);
-    }
-    @Deprecated
-    public static String[] split(String s, String regex, int limit) {
-        Pattern p = PATTERN_MAP.computeIfAbsent(regex, key -> Pattern.compile(key));
-        return p.split(s, limit);
-    }
-    @Deprecated
-    public static Stream<String> splitAsStream(String s, String regex) {
-        Pattern p = PATTERN_MAP.computeIfAbsent(regex, key -> Pattern.compile(key));
-        return p.splitAsStream(s);
-    }
-
     public static boolean isFileExist(String file) {
         return new File(file).exists() && new File(file).isFile();
     }
@@ -91,39 +72,6 @@ public final class StringUtils {
         return str1;
     }
 
-    public static List<String> getParts(String str, String separator) {
-        String[] parts = split(str, separator);
-        List<String> ret = new ArrayList<>(parts.length);
-        for (String part : parts) {
-            if (!isEmpty(part)) {
-                ret.add(part);
-            }
-        }
-        return ret;
-    }
-
-    public static String getFirstNotEmpty(String str, String separator) {
-        List<String> parts = Arrays.asList(split(str, separator));
-        for (String part : parts) {
-            if (!isEmpty(part)) {
-                return part;
-            }
-        }
-        return str;
-    }
-
-    public static String getFirstNotEmpty(List<String> list) {
-        if (isEmpty(list)) {
-            return null;
-        }
-        for (String item : list) {
-            if (!isEmpty(item)) {
-                return item;
-            }
-        }
-        return null;
-    }
-
     public static List<String> getFound(String contents, String regex) {
         if (isEmpty(regex) || isEmpty(contents)) {
             return null;
diff --git a/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java b/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
index a346e96..d3d740b 100644
--- a/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/StringUtilsTest.java
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.common.util;
 
-import java.util.List;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -37,50 +35,6 @@ public class StringUtilsTest extends Assert {
     }
 
     @Test
-    public void testGetFirstNotEmpty() throws Exception {
-        assertEquals("greetMe", StringUtils.getFirstNotEmpty("/greetMe/me/CXF", "/"));
-        assertEquals("greetMe", StringUtils.getFirstNotEmpty("greetMe/me/CXF", "/"));
-    }
-
-    @Test
-    public void testGetParts() throws Exception {
-        String str = "/greetMe/me/CXF";
-        List<String> parts = StringUtils.getParts(str, "/");
-        assertEquals(3, parts.size());
-        assertEquals("greetMe", parts.get(0));
-        assertEquals("me", parts.get(1));
-        assertEquals("CXF", parts.get(2));
-    }
-
-    @Test
-    public void testGetPartsWithSingleSpace() throws Exception {
-        String str = "a b";
-        List<String> parts = StringUtils.getParts(str, " ");
-        assertEquals(2, parts.size());
-        assertEquals("a", parts.get(0));
-        assertEquals("b", parts.get(1));
-    }
-
-    @Test
-    public void testGetPartsWithManySpaces() throws Exception {
-        String str = "a  b";
-        List<String> parts = StringUtils.getParts(str, " ");
-        assertEquals(2, parts.size());
-        assertEquals("a", parts.get(0));
-        assertEquals("b", parts.get(1));
-    }
-
-    @Test
-    public void testSplitWithDot() throws Exception {
-        String str = "a.b.c";
-        String[] parts = StringUtils.split(str, "\\.", -1);
-        assertEquals(3, parts.length);
-        assertEquals("a", parts[0]);
-        assertEquals("b", parts[1]);
-        assertEquals("c", parts[2]);
-    }
-
-    @Test
     public void testGetFound() throws Exception {
         String regex = "velocity-\\d+\\.\\d+\\.jar";
 
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
index 6115bb5..d307708 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
@@ -50,11 +50,14 @@ import org.apache.cxf.message.MessageUtils;
 
 public class HttpHeadersImpl implements HttpHeaders {
 
-    private static final String HEADER_SPLIT_PROPERTY =
+    static final String HEADER_SPLIT_PROPERTY =
         "org.apache.cxf.http.header.split";
-    private static final String COOKIE_SEPARATOR_PROPERTY =
+    static final String COOKIE_SEPARATOR_PROPERTY =
         "org.apache.cxf.http.cookie.separator";
     private static final String COOKIE_SEPARATOR_CRLF = "crlf";
+    private static final String COOKIE_SEPARATOR_CRLF_EXPRESSION = "\r\n";
+    private static final Pattern COOKIE_SEPARATOR_CRLF_PATTERN =
+            Pattern.compile(COOKIE_SEPARATOR_CRLF_EXPRESSION);
     private static final String DEFAULT_SEPARATOR = ",";
     private static final String DEFAULT_COOKIE_SEPARATOR = ";";
     private static final String DOLLAR_CHAR = "$";
@@ -145,7 +148,7 @@ public class HttpHeadersImpl implements HttpHeaders {
         if (cookiePropValue != null) {
             String separator = cookiePropValue.toString().trim();
             if (COOKIE_SEPARATOR_CRLF.equals(separator)) {
-                return "\r\n";
+                return COOKIE_SEPARATOR_CRLF_EXPRESSION;
             }
             if (separator.length() != 1) {
                 throw ExceptionUtils.toInternalServerErrorException(null, null);
@@ -254,10 +257,15 @@ public class HttpHeadersImpl implements HttpHeaders {
         return getHeaderValues(headerName, originalValue, DEFAULT_SEPARATOR);
     }
 
-    private List<String> getHeaderValues(String headerName, String originalValue, String
sep) {
+    private static List<String> getHeaderValues(String headerName, String originalValue,
String sep) {
         if (!originalValue.contains(QUOTE)
             || HEADERS_WITH_POSSIBLE_QUOTES.contains(headerName)) {
-            String[] ls = StringUtils.split(originalValue, sep);
+            final String[] ls; 
+            if (COOKIE_SEPARATOR_CRLF_EXPRESSION != sep) {
+                ls = originalValue.split(sep);
+            } else {
+                ls = COOKIE_SEPARATOR_CRLF_PATTERN.split(originalValue);
+            }
             if (ls.length == 1) {
                 return Collections.singletonList(ls[0].trim());
             }
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
index 7a68b78..f6a6b9d 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.jaxrs.impl;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
@@ -40,32 +39,16 @@ import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 public class HttpHeadersImplTest extends Assert {
 
-    private IMocksControl control;
-
-    @Before
-    public void setUp() {
-        control = EasyMock.createNiceControl();
-    }
-
     @Test
     public void testNoRequestHeader() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        MetadataMap<String, String> headers =
-            createHeader("COMPLEX_HEADER",  "b=c; param=c, a=b;param=b");
-        EasyMock.expectLastCall().andReturn(headers);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        control.replay();
+        Message m = createMessage(createHeader("COMPLEX_HEADER",  "b=c; param=c, a=b;param=b"));
+
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> values = h.getRequestHeader("HEADER");
         assertNull(values);
@@ -74,14 +57,9 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderNameValue() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        MetadataMap<String, String> headers =
-            createHeader("COMPLEX_HEADER",  "b=c; param=c, a=b;param=b");
-        EasyMock.expectLastCall().andReturn(headers);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        control.replay();
+        Message m = createMessage(createHeader("COMPLEX_HEADER",  "b=c; param=c, a=b;param=b"));
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
+
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> values = h.getRequestHeader("COMPLEX_HEADER");
         assertNotNull(values);
@@ -93,16 +71,13 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderWithQuotes1() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers = createHeader("COMPLEX_HEADER",
             "a1=\"a\", a2=\"a\";param, b, b;param, c1=\"c, d, e\", "
             + "c2=\"c, d, e\";param, a=b, a=b;p=p1, a2=\"a\";param=p,"
             + "a3=\"a\";param=\"p,b\"");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(headers);
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
+
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> values = h.getRequestHeader("COMPLEX_HEADER");
         assertNotNull(values);
@@ -122,14 +97,11 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderWithQuotes2() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers =
             createHeader("X-WSSE", "UsernameToken Username=\"Foo\", Nonce=\"bar\"");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(headers);
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
+
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> values = h.getRequestHeader("X-WSSE");
         assertNotNull(values);
@@ -142,14 +114,11 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderWithQuotes3() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers =
             createHeader("COMPLEX_HEADER", "\"value with space\"");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(headers);
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
+
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> values = h.getRequestHeader("COMPLEX_HEADER");
         assertNotNull(values);
@@ -162,12 +131,9 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaders() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(createHeaders());
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true").anyTimes();
-        control.replay();
+        Message m = createMessage(createHeaders());
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
+
         HttpHeaders h = new HttpHeadersImpl(m);
         MultivaluedMap<String, String> hs = h.getRequestHeaders();
         List<String> acceptValues = hs.get("Accept");
@@ -181,10 +147,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testMediaType() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(createHeaders());
-        control.replay();
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
         assertEquals(MediaType.valueOf("*/*"), h.getMediaType());
     }
@@ -192,8 +155,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetMissingContentLength() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, new MetadataMap<String, String>());
+        Message m = createMessage(new MetadataMap<String, String>());
         HttpHeaders h = new HttpHeadersImpl(m);
         assertEquals(-1, h.getLength());
     }
@@ -201,8 +163,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetContentLength() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, createHeaders());
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
         assertEquals(10, h.getLength());
     }
@@ -237,8 +198,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetDate() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, createHeaders());
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
 
         List<String> dateValues = h.getRequestHeader("Date");
@@ -254,8 +214,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderString() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, createHeaders());
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
 
         String date = h.getHeaderString("Date");
@@ -265,8 +224,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeaderString2() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, createHeaders());
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
 
         String date = h.getHeaderString("a");
@@ -276,8 +234,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeader2() throws Exception {
 
-        Message m = new MessageImpl();
-        m.put(Message.PROTOCOL_HEADERS, createHeaders());
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
 
         List<String> values = h.getRequestHeader("a");
@@ -289,10 +246,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetMediaTypes() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(createHeaders());
-        control.replay();
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
         List<MediaType> acceptValues = h.getAcceptableMediaTypes();
         assertEquals(3, acceptValues.size());
@@ -304,10 +258,8 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetNoMediaTypes() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
-        control.replay();
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, Collections.emptyMap());
         HttpHeaders h = new HttpHeadersImpl(m);
         List<MediaType> acceptValues = h.getAcceptableMediaTypes();
         assertEquals(1, acceptValues.size());
@@ -317,10 +269,8 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetNoLanguages() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
-        control.replay();
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, Collections.emptyMap());
         HttpHeaders h = new HttpHeadersImpl(m);
         List<Locale> locales = h.getAcceptableLanguages();
         assertEquals(1, locales.size());
@@ -330,12 +280,8 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetHeader() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true");
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(createHeaders());
-        control.replay();
+        Message m = createMessage(createHeaders());
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
         HttpHeaders h = new HttpHeadersImpl(m);
         List<String> acceptValues = h.getRequestHeader("Accept");
         assertEquals(3, acceptValues.size());
@@ -354,10 +300,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetNullLanguage() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(createHeaders());
-        control.replay();
+        Message m = createMessage(createHeaders());
         HttpHeaders h = new HttpHeadersImpl(m);
         assertNull(h.getLanguage());
     }
@@ -365,12 +308,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetLanguage() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.CONTENT_LANGUAGE, "en-US");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(createHeader(HttpHeaders.CONTENT_LANGUAGE, "en-US"));
         HttpHeaders h = new HttpHeadersImpl(m);
         assertEquals("en_US", h.getLanguage().toString());
     }
@@ -378,12 +316,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testSingleAcceptableLanguages() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(createHeader(HttpHeaders.ACCEPT_LANGUAGE, "en"));
         HttpHeaders h = new HttpHeadersImpl(m);
         List<Locale> languages = h.getAcceptableLanguages();
         assertEquals(1, languages.size());
@@ -393,11 +326,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetCookies() throws Exception {
 
-        Message m = new MessageImpl();
-        m.setExchange(new ExchangeImpl());
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "a=$b;c=d");
-        m.put(Message.PROTOCOL_HEADERS, headers);
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=$b;c=d"));
         HttpHeaders h = new HttpHeadersImpl(m);
         Map<String, Cookie> cookies = h.getCookies();
         assertEquals(2, cookies.size());
@@ -408,11 +337,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetCookieWithAttributes() throws Exception {
 
-        Message m = new MessageImpl();
-        m.setExchange(new ExchangeImpl());
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "$Version=1;a=b");
-        m.put(Message.PROTOCOL_HEADERS, headers);
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "$Version=1;a=b"));
         HttpHeaders h = new HttpHeadersImpl(m);
         Map<String, Cookie> cookies = h.getCookies();
         assertEquals(1, cookies.size());
@@ -424,11 +349,7 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetCookiesWithAttributes() throws Exception {
 
-        Message m = new MessageImpl();
-        m.setExchange(new ExchangeImpl());
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "$Version=1;a=b, $Version=1;c=d");
-        m.put(Message.PROTOCOL_HEADERS, headers);
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "$Version=1;a=b, $Version=1;c=d"));
         HttpHeaders h = new HttpHeadersImpl(m);
         Map<String, Cookie> cookies = h.getCookies();
         assertEquals(2, cookies.size());
@@ -444,14 +365,26 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testGetCookiesWithComma() throws Exception {
 
-        Message m = new MessageImpl();
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d"));
         Exchange ex = new ExchangeImpl();
         ex.setInMessage(m);
-        ex.put("org.apache.cxf.http.cookie.separator", ",");
+        ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, ",");
+        m.setExchange(ex);
+        HttpHeaders h = new HttpHeadersImpl(m);
+        Map<String, Cookie> cookies = h.getCookies();
+        assertEquals(2, cookies.size());
+        assertEquals("b", cookies.get("a").getValue());
+        assertEquals("d", cookies.get("c").getValue());
+    }
+
+    @Test
+    public void testGetCookiesWithCRLF() throws Exception {
+
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b\r\nc=d"));
+        Exchange ex = new ExchangeImpl();
+        ex.setInMessage(m);
+        ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, "crlf");
         m.setExchange(ex);
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "a=b,c=d");
-        m.put(Message.PROTOCOL_HEADERS, headers);
         HttpHeaders h = new HttpHeadersImpl(m);
         Map<String, Cookie> cookies = h.getCookies();
         assertEquals(2, cookies.size());
@@ -462,14 +395,11 @@ public class HttpHeadersImplTest extends Assert {
     @Test(expected = InternalServerErrorException.class)
     public void testInvalidCookieSeparator() throws Exception {
 
-        Message m = new MessageImpl();
+        Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d"));
         Exchange ex = new ExchangeImpl();
         ex.setInMessage(m);
-        ex.put("org.apache.cxf.http.cookie.separator", "(e+)+");
+        ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, "(e+)+");
         m.setExchange(ex);
-        MetadataMap<String, String> headers = createHeaders();
-        headers.putSingle(HttpHeaders.COOKIE, "a=b,c=d");
-        m.put(Message.PROTOCOL_HEADERS, headers);
         HttpHeaders h = new HttpHeadersImpl(m);
         h.getCookies();
     }
@@ -477,13 +407,10 @@ public class HttpHeadersImplTest extends Assert {
     @Test
     public void testMultipleAcceptableLanguages() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers =
             createHeader(HttpHeaders.ACCEPT_LANGUAGE,
                          "en;q=0.7, en-gb;q=0.8, da, zh-Hans-SG;q=0.9");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(headers);
         HttpHeaders h = new HttpHeadersImpl(m);
         List<Locale> languages = h.getAcceptableLanguages();
         assertEquals(4, languages.size());
@@ -494,40 +421,14 @@ public class HttpHeadersImplTest extends Assert {
     }
 
 
-    private MetadataMap<String, String> createHeaders() {
-        MetadataMap<String, String> hs = new MetadataMap<>();
-        hs.add("Accept", "text/bar;q=0.6");
-        hs.add("Accept", "text/*;q=1,application/xml");
-        hs.putSingle("Content-Type", "*/*");
-        hs.putSingle("Date", "Tue, 21 Oct 2008 17:00:00 GMT");
-        hs.putSingle("Content-Length", "10");
-        List<String> values = new ArrayList<>();
-        values.add("1");
-        values.add("2");
-        hs.addAll("a", values);
-        return hs;
-    }
-
-    private MetadataMap<String, String> createHeader(String name, String... values)
{
-        MetadataMap<String, String> hs = new MetadataMap<>();
-        List<String> list = new ArrayList<>();
-        list.addAll(Arrays.asList(values));
-        hs.put(name, list);
-        return hs;
-    }
-
-    @Test
+    @Test(expected = UnsupportedOperationException.class)
     public void testUnmodifiableRequestHeaders() throws Exception {
 
-        Message m = control.createMock(Message.class);
-        m.getContextualProperty("org.apache.cxf.http.header.split");
-        EasyMock.expectLastCall().andReturn("true").anyTimes();
-        m.get(Message.PROTOCOL_HEADERS);
         MetadataMap<String, String> headers =
             createHeader(HttpHeaders.ACCEPT_LANGUAGE,
                          "en;q=0.7, en-gb;q=0.8, da");
-        EasyMock.expectLastCall().andReturn(headers);
-        control.replay();
+        Message m = createMessage(headers);
+        m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
         HttpHeaders h = new HttpHeadersImpl(m);
         List<Locale> languages = h.getAcceptableLanguages();
         assertEquals(3, languages.size());
@@ -538,11 +439,31 @@ public class HttpHeadersImplTest extends Assert {
         MultivaluedMap<String, String> rHeaders = h.getRequestHeaders();
         List<String> acceptL = rHeaders.get(HttpHeaders.ACCEPT_LANGUAGE);
         assertEquals(3, acceptL.size());
-        try {
-            rHeaders.clear();
-            fail();
-        } catch (UnsupportedOperationException ex) {
-            // expected
-        }
+
+        rHeaders.clear();
     }
+
+    private static MetadataMap<String, String> createHeaders() {
+        MetadataMap<String, String> hs = new MetadataMap<>();
+        hs.add("Accept", "text/bar;q=0.6");
+        hs.add("Accept", "text/*;q=1,application/xml");
+        hs.putSingle("Content-Type", "*/*");
+        hs.putSingle("Date", "Tue, 21 Oct 2008 17:00:00 GMT");
+        hs.putSingle("Content-Length", "10");
+        hs.addAll("a", Arrays.asList("1", "2"));
+        return hs;
+    }
+
+    private static MetadataMap<String, String> createHeader(String name, String...
values) {
+        MetadataMap<String, String> hs = new MetadataMap<>();
+        hs.put(name, Arrays.asList(values));
+        return hs;
+    }
+
+    private static Message createMessage(MetadataMap<String, String> headers) {
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        return m;
+    }
+
 }
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
index eb7a1b9..249dd32 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
@@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets;
 import java.security.Principal;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -167,10 +166,11 @@ public abstract class AbstractHTTPDestination
         if (credentials == null || StringUtils.isEmpty(credentials.trim())) {
             return null;
         }
-        List<String> creds = StringUtils.getParts(credentials, " ");
-        String authType = creds.get(0);
-        if ("Basic".equals(authType) && creds.size() == 2) {
-            String authEncoded = creds.get(1);
+
+        final String[] creds = credentials.split(" ");
+        String authType = creds[0];
+        if ("Basic".equals(authType) && creds.length == 2) {
+            String authEncoded = creds[1];
             try {
                 byte[] authBytes = Base64Utility.decode(authEncoded);
 


Mime
View raw message