Ah, sorry, I speak too fast.

If using new URI(url.getProtocol(), url.getAuthority(), url.getPath(), 
url.getQuery(), null);  
and if the url is a jar file like
jar:file:/Users/ffang/.m2/repository/org/apache/cxf/cxf-tools-wsdlto-frontend-jaxws/2.7.1-SNAPSHOT/cxf-tools-wsdlto-frontend-jaxws-2.7.1-SNAPSHOT.jar!/META-INF/jax-ws-catalog.xml
then we get exception like
java.net.URISyntaxException: Relative path in absolute URI: 
jar:file:/Users/ffang/.m2/repository/org/apache/cxf/cxf-tools-wsdlto-frontend-jaxws/2.7.1-SNAPSHOT/cxf-tools-wsdlto-frontend-jaxws-2.7.1-SNAPSHOT.jar!/META-INF/jax-ws-catalog.xml
[WARNING]       at java.net.URI.checkPath(URI.java:1804)
[WARNING]       at java.net.URI.<init>(URI.java:752)

in this case the url.getProtocol()  return jar, and url.getPath() return 
file:/Users/ffang/.m2/repository/org/apache/cxf/cxf-tools-wsdlto-frontend-jaxws/2.7.1-SNAPSHOT/cxf-tools-wsdlto-frontend-jaxws-2.7.1-SNAPSHOT.jar!/META-INF/jax-ws-catalog.xml
and URI.checkPath() will throw java.net.URISyntaxException as the path not 
start with "/", more like a bug in URL/URI

private static void checkPath(String s, String scheme, String path)
        throws URISyntaxException
    {
        if (scheme != null) { ///here schema is jar
            if ((path != null)   ///here path is file:/.…. hence throw 
URISyntaxException
                && ((path.length() > 0) && (path.charAt(0) != '/')))
                throw new URISyntaxException(s,
                                             "Relative path in absolute URI");
        }
    }

And if we use URI.create() we can bypass this problem.

Freeman

-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat
Web: http://fusesource.com | http://www.redhat.com/
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042

On 2012-11-9, at 上午8:58, Freeman Fang wrote:

> Hi Dan,
> 
> Yep, using new URI(url.getProtocol(), url.getAuthority(), url.getPath(), 
> url.getQuery(), null); 
> works as it well call into some URI internal method to do the encode if 
> necessary, I will revise the code accordingly.
> 
> Thanks
> Freeman
> -------------
> Freeman(Yue) Fang
> 
> Red Hat, Inc. 
> FuseSource is now part of Red Hat
> Web: http://fusesource.com | http://www.redhat.com/
> Twitter: freemanfang
> Blog: http://freemanfang.blogspot.com
> http://blog.sina.com.cn/u/1473905042
> weibo: http://weibo.com/u/1473905042
> 
> On 2012-11-8, at 下午11:23, Daniel Kulp wrote:
> 
>> 
>> On Nov 8, 2012, at 8:16 AM, Freeman Fang <[email protected]> wrote:
>> 
>>> Thanks for the suggestion, but I don't think the
>>> if (!loadedCatalogs.contains(catalogURL.toURI())
>>> could work.
>>> 
>>> Take a close look at URL.toURI() method, it's
>>>   public URI toURI() throws URISyntaxException {
>>>       return new URI (toString());  ///line 1
>>>   }
>>> 
>>> Also take a look at URI.create() method, it's 
>>> public static URI create(String str) {
>>>       try {
>>>           return new URI(str);   ///line 2
>>>       } catch (URISyntaxException x) {
>>>           throw new IllegalArgumentException(x.getMessage(), x);
>>>       }
>>>   }
>>> 
>>> so line1 and line2 are exactly same method with same input argument, so 
>>> using catalogURL.toURI() actually same effect with  
>>> URI.create(catalogURL.toString()). So we need explicitly  manipulate 
>>> catalogURL.toString() anyway to replace/encode whitespace there.
>> 
>> Wow.   That really sucks.   I more or less would expect a "toURI" method to 
>> actually produce a usable URI if the URL is valid.     Oh well.     Good 
>> investigation.
>> 
>> You MIGHT be able to try something like:
>> 
>> new URI(url.getProtocol(), url.getAuthority(), url.getPath(), 
>> url.getQuery(), null);
>> 
>> to avoid the toString/parse combo, but that probably has similar issues.  :-(
>> 
>> 
>> Dan
>> 
>> 
>>> 
>>> Best Regards
>>> Freeman
>>> -------------
>>> Freeman(Yue) Fang
>>> 
>>> Red Hat, Inc. 
>>> FuseSource is now part of Red Hat
>>> Web: http://fusesource.com | http://www.redhat.com/
>>> Twitter: freemanfang
>>> Blog: http://freemanfang.blogspot.com
>>> http://blog.sina.com.cn/u/1473905042
>>> weibo: http://weibo.com/u/1473905042
>>> 
>>> On 2012-11-8, at 下午8:36, Daniel Kulp wrote:
>>> 
>>>> 
>>>> Freeman,
>>>> 
>>>> Since we have URL objects, instead of calling toString on them and doing:
>>>> 
>>>>> if 
>>>>> (!loadedCatalogs.contains(URI.create(replaceWhitespace(catalogURL.toString()))))
>>>>>  {
>>>> 
>>>> 
>>>> can we just do something like
>>>> 
>>>> if (!loadedCatalogs.contains(catalogURL.toURI())
>>>> 
>>>> 
>>>> or similar?   Would avoid some issues converting the URL to string, 
>>>> encoding it, etc…  If there are other characters in the URL that need 
>>>> encoding, that may handle that as well.
>>>> 
>>>> Dan
>>>> 
>>>> 
>>>> On Nov 8, 2012, at 3:48 AM, [email protected] wrote:
>>>> 
>>>>> Author: ffang
>>>>> Date: Thu Nov  8 08:48:30 2012
>>>>> New Revision: 1406958
>>>>> 
>>>>> URL: http://svn.apache.org/viewvc?rev=1406958&view=rev
>>>>> Log:
>>>>> [CXF-4620]Exception at compilation when a 'space' character is present in 
>>>>> maven local repository path
>>>>> 
>>>>> Modified:
>>>>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
>>>>> 
>>>>> Modified: 
>>>>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
>>>>> URL: 
>>>>> http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java?rev=1406958&r1=1406957&r2=1406958&view=diff
>>>>> ==============================================================================
>>>>> --- 
>>>>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
>>>>>  (original)
>>>>> +++ 
>>>>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
>>>>>  Thu Nov  8 08:48:30 2012
>>>>> @@ -144,15 +144,15 @@ public class OASISCatalogManager {
>>>>>      Enumeration<URL> catalogs = classLoader.getResources(name);
>>>>>      while (catalogs.hasMoreElements()) {
>>>>>          URL catalogURL = catalogs.nextElement();
>>>>> -            if 
>>>>> (!loadedCatalogs.contains(URI.create(catalogURL.toString()))) {
>>>>> +            if 
>>>>> (!loadedCatalogs.contains(URI.create(replaceWhitespace(catalogURL.toString()))))
>>>>>  {
>>>>>              ((Catalog)catalog).parseCatalog(catalogURL);
>>>>> -                loadedCatalogs.add(URI.create(catalogURL.toString()));
>>>>> +                
>>>>> loadedCatalogs.add(URI.create(replaceWhitespace(catalogURL.toString())));
>>>>>          }
>>>>>      }
>>>>>  }
>>>>> 
>>>>>  public final void loadCatalog(URL catalogURL) throws IOException {
>>>>> -        if (!loadedCatalogs.contains(URI.create(catalogURL.toString())) 
>>>>> && catalog != null) {
>>>>> +        if 
>>>>> (!loadedCatalogs.contains(URI.create(replaceWhitespace(catalogURL.toString())))
>>>>>  && catalog != null) {
>>>>>          if ("file".equals(catalogURL.getProtocol())) {
>>>>>              try {
>>>>>                  File file = new File(catalogURL.toURI());
>>>>> @@ -166,9 +166,16 @@ public class OASISCatalogManager {
>>>>> 
>>>>>          ((Catalog)catalog).parseCatalog(catalogURL);
>>>>> 
>>>>> -            loadedCatalogs.add(URI.create(catalogURL.toString()));
>>>>> +            
>>>>> loadedCatalogs.add(URI.create(replaceWhitespace(catalogURL.toString())));
>>>>>      }
>>>>>  }
>>>>> +    
>>>>> +    private String replaceWhitespace(String str) {
>>>>> +        if (str.contains(" ")) {
>>>>> +            str = str.replace(" ", "%20");
>>>>> +        }
>>>>> +        return str;
>>>>> +    }
>>>>> 
>>>>>  private static OASISCatalogManager getContextCatalog() {
>>>>>      try {
>>>>> 
>>>>> 
>>>> 
>>>> -- 
>>>> Daniel Kulp
>>>> [email protected] - http://dankulp.com/blog
>>>> Talend Community Coder - http://coders.talend.com
>>>> 
>>> 
>> 
>> -- 
>> Daniel Kulp
>> [email protected] - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>> 
> 

Reply via email to