[jira] [Commented] (CXF-7923) String.split via fastpath instead of precompiled Pattern

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (CXF-7923) String.split via fastpath instead of precompiled Pattern

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CXF-7923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16712959#comment-16712959 ]

ASF GitHub Bot commented on CXF-7923:
-------------------------------------

amarkevich closed pull request #481: CXF-7923 String.split via fastpath instead of precompiled Pattern
URL: https://github.com/apache/cxf/pull/481
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 f35cd11f0bb..70de5596406 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 @@
 
 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 static String getSharedPackageName(List<Class<?>> classes) {
         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 static String getSharedPackageName(List<Class<?>> classes) {
         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 2657d15020f..c06db7b2f18 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.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 static String diff(String str1, String str2) {
         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 a346e9635c3..d3d740baae0 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;
 
@@ -36,50 +34,6 @@ public void testDiff() throws Exception {
         assertEquals("http://local/SoapContext/SoapPort/", StringUtils.diff(str3, str1));
     }
 
-    @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 6115bb50660..d307708b151 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 @@
 
 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 @@ private String getCookieSeparatorFromProperty() {
         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 MediaType getMediaType() {
         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 7a68b788623..f6a6b9dc44d 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.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 void testNoRequestHeader() throws Exception {
     @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 void testGetHeaderNameValue() throws Exception {
     @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 void testGetHeaderWithQuotes1() throws Exception {
     @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 void testGetHeaderWithQuotes2() throws Exception {
     @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 void testGetHeaderWithQuotes3() throws Exception {
     @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 void testGetHeaders() throws Exception {
     @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 void testMediaType() throws Exception {
     @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 void testGetMissingContentLength() throws Exception {
     @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 void testGetEmptyHeader() throws Exception {
     @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 void testGetDate() throws Exception {
     @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 void testGetHeaderString() throws Exception {
     @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 void testGetHeaderString2() throws Exception {
     @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 void testGetHeader2() throws Exception {
     @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 void testGetMediaTypes() throws Exception {
     @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 void testGetNoMediaTypes() throws Exception {
     @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 void testGetNoLanguages() throws Exception {
     @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 void testGetHeader() throws Exception {
     @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 void testGetNullLanguage() throws Exception {
     @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 void testGetLanguage() throws Exception {
     @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 void testSingleAcceptableLanguages() throws Exception {
     @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 void testGetCookies() throws Exception {
     @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 void testGetCookieWithAttributes() throws Exception {
     @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 void testGetCookiesWithAttributes() throws Exception {
     @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 void testGetCookiesWithComma() throws Exception {
     @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 void testInvalidCookieSeparator() throws Exception {
     @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 void testMultipleAcceptableLanguages() throws Exception {
     }
 
 
-    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 void testUnmodifiableRequestHeaders() throws Exception {
         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 eb7a1b9189a..249dd329daa 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.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 @@ private AuthorizationPolicy getAuthorizationPolicyFromMessage(String credentials
         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);
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


> String.split via fastpath instead of precompiled Pattern
> --------------------------------------------------------
>
>                 Key: CXF-7923
>                 URL: https://issues.apache.org/jira/browse/CXF-7923
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 3.2.7
>            Reporter: Alexey Markevich
>            Assignee: Alexey Markevich
>            Priority: Major
>             Fix For: 3.3.0
>
>
> Initial PR https://github.com/apache/cxf/pull/479



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)