代码之家  ›  专栏  ›  技术社区  ›  Brian Hsu

Apache CommonVFS连接到https服务器

  •  2
  • Brian Hsu  · 技术社区  · 14 年前

    CommonVFS的网站说它支持HTTPS协议,但是我发现我不能访问那些以HTTPS://开头的URL,而我可以 browse it 从我的火狐浏览器。

    scala> import org.apache.commons.vfs.VFS                                                  
    import org.apache.commons.vfs.VFS
    
    scala> val fsManager = VFS.getManager();
    fsManager: org.apache.commons.vfs.FileSystemManager = org.apache.commons.vfs.impl.StandardFileSystemManager@16a0733
    
    scala> val file1 = fsManager.resolveFile ("http://bone.twbbs.org.tw/Images/desk.jpg")
    file1: org.apache.commons.vfs.FileObject = http://bone.twbbs.org.tw/Images/desk.jpg
    
    scala> val file2 = fsManager.resolveFile ("https://na.archives.gov.tw/archives/chinese/98/search/popup.jsp?res=/export/home/xdcm/do/ScaleDoFiles/jpg/00/00/01/21/07/A313480000K=0089=577=1=1=003=0002-i.jpg")
    org.apache.commons.vfs.FileSystemException: Could not connect to HTTP server on "na.archives.gov.tw".
        at org.apache.commons.vfs.provider.http.HttpClientFactory.createConnection(HttpClientFactory.java:105)
        at org.apache.commons.vfs.provider.http.HttpFileProvider.doCreateFileSystem(HttpFileProvider.java:81)
        at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:81)
        at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:62)
        at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:641)
        at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:602)
        at org.apache.commons.vfs.impl.DefaultFileS...
    

    scala> fsManager.asInstanceOf[org.apache.commons.vfs.impl.StandardFileSystemManager].addProvider("https", new org.apache.commons.vfs.provider.https.HttpsFileProvider)
    org.apache.commons.vfs.FileSystemException: Multiple providers registered for URL scheme "https".
        at org.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:174)
        at org.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:152)
        at .<init>(<console>:8)
        at .<clinit>(<console>)
        at RequestResult$.<init>(<console>:9)
        at RequestResult$.<clinit>(<console>)
        at RequestResult$scala_repl_result(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at scala.tools.nsc.Interpr...
    

    那么,如何使用commonVFS访问https服务器呢?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Brian Hsu    14 年前

    我跟着警察走 instruction here 将证书添加到我的密钥库,现在一切正常。