You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/01/10 23:46:18 UTC

svn commit: r1229780 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/core/src/main/java/org/apache/cxf/transport/http/ rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ rt/javascript/javascript-rt/src/main/java/org/a...

Author: dkulp
Date: Tue Jan 10 22:46:18 2012
New Revision: 1229780

URL: http://svn.apache.org/viewvc?rev=1229780&view=rev
Log:
Move some utility methods into similar class in common

Removed:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/UrlUtilities.java
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/UrlUtils.java
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
    cxf/trunk/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
    cxf/trunk/rt/ws/mex/src/main/java/org/apache/cxf/ws/mex/MEXUtils.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/UrlUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/UrlUtils.java?rev=1229780&r1=1229779&r2=1229780&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/UrlUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/UrlUtils.java Tue Jan 10 22:46:18 2012
@@ -20,7 +20,11 @@
 package org.apache.cxf.common.util;
 
 import java.io.UnsupportedEncodingException;
+import java.net.URI;
 import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -77,4 +81,43 @@ public final class UrlUtils {
         return urlDecode(value);
     }
     
+    
+    /**
+     * Create a map from String to String that represents the contents of the query
+     * portion of a URL. For each x=y, x is the key and y is the value.
+     * @param s the query part of the URI.
+     * @return the map.
+     */
+    public static Map<String, String> parseQueryString(String s) {
+        Map<String, String> ht = new HashMap<String, String>();
+        StringTokenizer st = new StringTokenizer(s, "&");
+        while (st.hasMoreTokens()) {
+            String pair = st.nextToken();
+            int pos = pair.indexOf('=');
+            if (pos == -1) {
+                ht.put(pair.toLowerCase(), "");
+            } else {
+                ht.put(pair.substring(0, pos).toLowerCase(),
+                       pair.substring(pos + 1));
+            }
+        }
+        return ht;
+    }
+    
+    /**
+     * Return everything in the path up to the last slash in a URI.
+     * @param baseURI
+     * @return the trailing 
+     */
+    public static String getStem(String baseURI) {
+        URI uri = URI.create(baseURI);
+        baseURI = uri.getRawPath();
+        int idx = baseURI.lastIndexOf('/');
+        if (idx != -1) {
+            baseURI = baseURI.substring(0, idx);
+        }
+        return URI.create(baseURI).getPath();
+    }
+    
+    
 }

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java?rev=1229780&r1=1229779&r2=1229780&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Tue Jan 10 22:46:18 2012
@@ -34,6 +34,7 @@ import org.w3c.dom.Document;
 import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -42,7 +43,6 @@ import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.http.UrlUtilities;
 
 /**
  * 
@@ -95,7 +95,7 @@ public class WSDLGetInterceptor extends 
         //cannot have two wsdl's being written for the same endpoint at the same
         //time as the addresses may get mixed up
         synchronized (message.getExchange().getEndpoint()) {
-            Map<String, String> map = UrlUtilities.parseQueryString(query);
+            Map<String, String> map = UrlUtils.parseQueryString(query);
             if (isRecognizedQuery(map, baseUri, ctx, 
                                   message.getExchange().getEndpoint().getEndpointInfo())) {
                 

Modified: cxf/trunk/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java?rev=1229780&r1=1229779&r2=1229780&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java (original)
+++ cxf/trunk/rt/javascript/javascript-rt/src/main/java/org/apache/cxf/javascript/JavascriptQueryHandler.java Tue Jan 10 22:46:18 2012
@@ -33,6 +33,7 @@ import javax.annotation.Resource;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.UncheckedException;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerRegistry;
@@ -42,7 +43,6 @@ import org.apache.cxf.service.model.Endp
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.transport.DestinationWithEndpoint;
-import org.apache.cxf.transport.http.UrlUtilities;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.transports.http.StemMatchingQueryHandler;
 
@@ -71,7 +71,7 @@ public class JavascriptQueryHandler impl
     
     public String getResponseContentType(String fullQueryString, String ctx) {
         URI uri = URI.create(fullQueryString);
-        Map<String, String> map = UrlUtilities.parseQueryString(uri.getQuery());
+        Map<String, String> map = UrlUtils.parseQueryString(uri.getQuery());
         if (map.containsKey(CODE_QUERY_KEY)) {
             return "application/javascript;charset=UTF-8";
         }
@@ -84,9 +84,9 @@ public class JavascriptQueryHandler impl
             return false;
         }
         URI uri = URI.create(baseUri);
-        Map<String, String> map = UrlUtilities.parseQueryString(uri.getQuery());
+        Map<String, String> map = UrlUtils.parseQueryString(uri.getQuery());
         if (map.containsKey(CODE_QUERY_KEY)) {
-            return endpointInfo.getAddress().contains(UrlUtilities.getStem(uri.getSchemeSpecificPart()));
+            return endpointInfo.getAddress().contains(UrlUtils.getStem(uri.getSchemeSpecificPart()));
         }
         return false;
     }
@@ -127,7 +127,7 @@ public class JavascriptQueryHandler impl
     public void writeResponse(String fullQueryString, String ctx, EndpointInfo endpoint, OutputStream os) {
         URI uri = URI.create(fullQueryString);
         String query = uri.getQuery();
-        Map<String, String> map = UrlUtilities.parseQueryString(query);
+        Map<String, String> map = UrlUtils.parseQueryString(query);
         OutputStreamWriter writer = new OutputStreamWriter(os, UTF8);
         if (!map.containsKey(NO_UTILS_QUERY_KEY)) {
             writeUtilsToResponseStream(JavascriptQueryHandler.class, os);

Modified: cxf/trunk/rt/ws/mex/src/main/java/org/apache/cxf/ws/mex/MEXUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/mex/src/main/java/org/apache/cxf/ws/mex/MEXUtils.java?rev=1229780&r1=1229779&r2=1229780&view=diff
==============================================================================
--- cxf/trunk/rt/ws/mex/src/main/java/org/apache/cxf/ws/mex/MEXUtils.java (original)
+++ cxf/trunk/rt/ws/mex/src/main/java/org/apache/cxf/ws/mex/MEXUtils.java Tue Jan 10 22:46:18 2012
@@ -27,12 +27,12 @@ import java.util.Map;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.WSDLGetUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.http.UrlUtilities;
 
 /**
  * 
@@ -91,7 +91,7 @@ public final class MEXUtils {
             if (StringUtils.isEmpty(id) 
                 || id.equals(xsd.getKey())) {
                 String query = xsd.getValue().substring(xsd.getValue().indexOf('?') + 1);
-                Map<String, String> params = UrlUtilities.parseQueryString(query);
+                Map<String, String> params = UrlUtils.parseQueryString(query);
 
                 ret.add(utils.getDocument(message, base, params, ctxUri, info).getDocumentElement());
             }