cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1424024 - in /cxf/branches/2.5.x-fixes: common/common/src/main/java/org/apache/cxf/common/util/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ rt/transport...
Date Wed, 19 Dec 2012 18:51:59 GMT
Author: dkulp
Date: Wed Dec 19 18:51:59 2012
New Revision: 1424024

URL: http://svn.apache.org/viewvc?rev=1424024&view=rev
Log:
Merged revisions 1424007 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1424007 | dkulp | 2012-12-19 13:28:46 -0500 (Wed, 19 Dec 2012) | 10 lines

  Merged revisions 1423981 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1423981 | dkulp | 2012-12-19 12:43:48 -0500 (Wed, 19 Dec 2012) | 2 lines

    Start to use some precompiled patterns for common places where we split strings

  ........

........

Modified:
    cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
    cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
    cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
    cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
    cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/uri/URISupport.java

Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
(original)
+++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
Wed Dec 19 18:51:59 2012
@@ -24,14 +24,38 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public final class StringUtils {
-
+    public static final Map<String, Pattern> PATTERN_MAP = new HashMap<String, Pattern>();
+    static {
+        String patterns[] = {"/", " ", ":", "," , ";", "="}; 
+        for (String p : patterns) {
+            PATTERN_MAP.put(p, Pattern.compile(p));
+        }
+    }
+        
     private StringUtils() {
     }
+    
+    public static String[] split(String s, String regex) {
+        Pattern p = PATTERN_MAP.get(regex);
+        if (p != null) {
+            return p.split(s);
+        }
+        return s.split(regex);
+    }
+    public static String[] split(String s, String regex, int limit) {
+        Pattern p = PATTERN_MAP.get(regex);
+        if (p != null) {
+            return p.split(s, limit);
+        }
+        return s.split(regex, limit);
+    }
 
     public static String extract(String string, String startToken, String endToken) {
         int start = string.indexOf(startToken) + startToken.length();
@@ -112,7 +136,7 @@ public final class StringUtils {
     
     public static List<String> getParts(String str, String seperator) {
         List<String> ret = new ArrayList<String>();
-        List<String> parts = Arrays.asList(str.split(seperator));
+        List<String> parts = Arrays.asList(split(str, seperator));
         for (String part : parts) {
             if (!isEmpty(part)) {
                 ret.add(part);
@@ -122,7 +146,7 @@ public final class StringUtils {
     }
     
     public static String getFirstNotEmpty(String str, String seperator) {
-        List<String> parts = Arrays.asList(str.split(seperator));
+        List<String> parts = Arrays.asList(split(str, seperator));
         for (String part : parts) {
             if (!isEmpty(part)) {
                 return part;

Modified: cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Wed Dec 19 18:51:59 2012
@@ -149,9 +149,10 @@ public abstract class AbstractHTTPDestin
         if (credentials == null || StringUtils.isEmpty(credentials.trim())) {
             return null;
         }
-        String authType = credentials.split(" ")[0];
+        String creds[] = StringUtils.split(credentials, " ");
+        String authType = creds[0];
         if ("Basic".equals(authType)) {
-            String authEncoded = credentials.split(" ")[1];
+            String authEncoded = creds[1];
             try {
                 String authDecoded = new String(Base64Utility.decode(authEncoded));
                 int idx = authDecoded.indexOf(':');

Modified: cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
Wed Dec 19 18:51:59 2012
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
@@ -70,11 +71,11 @@ public class Cookies {
         }
     
         for (String header : headers) {
-            String[] cookies = header.split(",");
+            String[] cookies = StringUtils.split(header, ",");
             for (String cookie : cookies) {
-                String[] parts = cookie.split(";");
+                String[] parts = StringUtils.split(cookie, ";");
     
-                String[] kv = parts[0].split("=", 2);
+                String[] kv = StringUtils.split(parts[0], "=", 2);
                 if (kv.length != 2) {
                     continue;
                 }
@@ -83,7 +84,7 @@ public class Cookies {
                 Cookie newCookie = new Cookie(name, value);
     
                 for (int i = 1; i < parts.length; i++) {
-                    kv = parts[i].split("=", 2);
+                    kv = StringUtils.split(parts[i], "=", 2);
                     name = kv[0].trim();
                     value = (kv.length > 1) ? kv[1].trim() : null;
                     if (name.equalsIgnoreCase(Cookie.DISCARD_ATTRIBUTE)) {

Modified: cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
Wed Dec 19 18:51:59 2012
@@ -102,7 +102,7 @@ public abstract class AbstractHTTPServle
     protected static List<Pattern> parseListSequence(String values) {
         if (values != null) {
             List<Pattern> list = new LinkedList<Pattern>();
-            String[] pathValues = values.split(" ");
+            String[] pathValues = StringUtils.split(values, " ");
             for (String value : pathValues) {
                 String theValue = value.trim();
                 if (theValue.length() > 0) {
@@ -119,9 +119,13 @@ public abstract class AbstractHTTPServle
         if (sequence != null) {
             sequence = sequence.trim();
             Map<String, String> map = new HashMap<String, String>();
-            String[] pairs = sequence.split(" ");
+            String[] pairs = StringUtils.split(sequence, " ");
             for (String pair : pairs) {
-                String[] value = pair.split("=");
+                String thePair = pair.trim();
+                if (thePair.length() == 0) {
+                    continue;
+                }
+                String[] value = StringUtils.split(thePair, "=");
                 if (value.length == 2) {
                     map.put(value[0].trim(), value[1].trim());
                 } else {

Modified: cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
Wed Dec 19 18:51:59 2012
@@ -45,6 +45,7 @@ import javax.jms.Topic;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.SOAPConstants;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.MessageUtils;
@@ -343,7 +344,7 @@ public final class JMSUtils {
         String contentType = ct.toLowerCase();
         String enc = null;
 
-        String[] tokens = contentType.split(";");
+        String[] tokens = StringUtils.split(contentType, ";");
         for (String token : tokens) {
             int index = token.indexOf("charset=");
             if (index >= 0) {

Modified: cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/uri/URISupport.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/uri/URISupport.java?rev=1424024&r1=1424023&r2=1424024&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/uri/URISupport.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/uri/URISupport.java
Wed Dec 19 18:51:59 2012
@@ -27,6 +27,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cxf.common.util.StringUtils;
+
 /**
  * URI utilities.
  *
@@ -114,7 +116,7 @@ public final class URISupport {
         try {
             Map rc = new HashMap();
             if (uri != null) {
-                String[] parameters = uri.split("&");
+                String[] parameters = StringUtils.split(uri, "&");
                 for (String parameter : parameters) {
                     int p = parameter.indexOf("=");
                     if (p >= 0) {



Mime
View raw message