You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ba...@apache.org on 2008/09/07 23:47:52 UTC

svn commit: r692958 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/context/utils/ContextUtils.java src/org/apache/axis2/jaxws/utility/JavaUtils.java test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java

Author: barrettj
Date: Sun Sep  7 14:47:51 2008
New Revision: 692958

URL: http://svn.apache.org/viewvc?rev=692958&view=rev
Log:
Handle conversion to URI from Strings that contain a space.
Add associated test.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java?rev=692958&r1=692957&r2=692958&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java Sun Sep  7 14:47:51 2008
@@ -29,6 +29,7 @@
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.utility.JavaUtils;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -71,13 +72,10 @@
             if (sd != null) {
                 String wsdlLocation = ((ServiceDescriptionWSDL)sd).getWSDLLocation();
                 if (wsdlLocation != null && !"".equals(wsdlLocation)) {
-                    URI wsdlLocationURI = null;
-                    try {
-                        wsdlLocationURI = new URI(wsdlLocation);
-                    }
-                    catch (URISyntaxException ex) {
+                    URI wsdlLocationURI = JavaUtils.createURI(wsdlLocation);
+                    if (wsdlLocationURI == null) {
                         log.warn(Messages.getMessage("addPropertiesErr",
-                        		wsdlLocation.toString(),description.getServiceQName().toString()), ex);
+                                 wsdlLocation.toString(),description.getServiceQName().toString()));
                     }
                     soapMessageContext
                             .put(javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION, wsdlLocationURI);

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java?rev=692958&r1=692957&r2=692958&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java Sun Sep  7 14:47:51 2008
@@ -24,6 +24,8 @@
 
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
@@ -224,4 +226,47 @@
         }
         return null;
     }
+        
+    /**
+     * Convert a String to a URI, handling special characters in the String such as
+     * spaces.
+     * 
+     * @param pathString The String to be converted to a URI
+     * @return a URI or null if the String can't be converted.
+     */
+    public static URI createURI(String pathString) {
+        URI pathURI = null;
+        if (pathString == null || "".equals(pathString)) {
+            if (log.isDebugEnabled()) {
+                log.debug("Path string argument is invalid [" + pathString + "]; returning null");
+            }
+            return null;
+        }
+
+        try {
+            pathURI = new URI(pathString);
+        }
+        catch (URISyntaxException ex1) {
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to create URI from [" + pathString + 
+                          "], trying alternative approach");
+            }
+            /*
+             * The URI creation requires special characters, such as spaces, be escaped or
+             * converted.  The 5 argument constuctor will do that for us.
+             */
+            try {
+                pathURI = new URI(null, null, pathString, null);
+            } catch (URISyntaxException ex2) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Unable to create URI using alternative approach; returning null.  Exception caught during inital attempt: " 
+                              + JavaUtils.stackToString(ex1));
+                    log.debug("Exception caught during alternet attemt " 
+                              + JavaUtils.stackToString(ex2));
+                }
+                log.error(ex2.toString(), ex2);
+            }
+        }
+        return pathURI;
+    }
 }

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java?rev=692958&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/JavaUtilsTests.java Sun Sep  7 14:47:51 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *      
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.utility;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the utility methods in the JavaUtils class
+ */
+public class JavaUtilsTests extends TestCase {
+    
+    /**
+     * Test that spaces in the string can be handled correctly when converting to a URI. 
+     */
+    public void testCreateURI_spaces() {
+        
+        String pathWithSpaces = "file:/F:/Program Files/MyAppServer/installedApps/MyEar.ear/MyWar.war/WEB-INF/wsdl/MyWSDL.wsdl";
+        
+        URI uri = JavaUtils.createURI(pathWithSpaces);
+        assertNotNull(uri);
+        
+    }
+    
+    /**
+     * Test that null and empty arguments are handled correctly when trying to convert to a URI.
+     */
+    public void testCreateURI_invalid() {
+        
+        URI uri = JavaUtils.createURI(null);
+        assertNull(uri);
+        
+        URI uri2 = JavaUtils.createURI("");
+        assertNull(uri2);
+        
+    }
+
+}