2017-07-31 74 views
1

我想從我的OpenStack Swift容器之一生成一個臨時URL。但是,當我訪問它的網址,它給我401 Unauthorized: Temp URL invalid無法生成在JOSS openstack到期時間的臨時GET url

這是我如何做它的示例版本。

package com.raja.openstack; 

import org.javaswift.joss.client.factory.AccountConfig; 
import org.javaswift.joss.client.factory.AccountFactory; 
import org.javaswift.joss.client.factory.AuthenticationMethod; 
import org.javaswift.joss.model.Account; 
import org.javaswift.joss.model.Container; 
import org.javaswift.joss.model.StoredObject; 

import java.io.File; 
import java.util.Map; 

/** 
* Created by raja on 04-05-2017. 
*/ 
public class OpenStackSwiftTest { 
    public static void main(String[] args) { 
     //create config 
     AccountConfig config = new AccountConfig(); 
     config.setAuthUrl("myhosting.url/auth/v1.0/"); 
     config.setAuthenticationMethod(AuthenticationMethod.BASIC); 
     config.setUsername("admin"); 
     config.setPassword("PasswordDuh"); 
     config.setHashPassword("blah"); //The API documentation insists this 

     //create account from config 
     Account account = new AccountFactory(config).createAccount(); 

     Map<String, Object> metadata1 = account.getMetadata(); 
     metadata1.forEach((s, o) -> { 
      System.out.println(s+":"+o); 
     }); 

     Container container = account.getContainer("mycontainer"); 


     //open a stored object handle 
     StoredObject storedObject = container.getObject("TEST.txt"); 

     //upload something 
     storedObject.uploadObject("Hello World!!".getBytes()); 

     //get the temporary URL. 
     String tempGetUrl = storedObject.getTempGetUrl(1000); 

     System.out.println(tempGetUrl); 

    } 
} 

上面的代碼打印類似如下

Quota-Bytes:107374182400 
Temp-Url-Key:blah 
myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt?temp_url_sig=5e38222a1b74fe1ae874a946ccb6f4cce043dcdb&temp_url_expires=1501517432 

當我嘗試訪問的URL,我得到401 Unauthorized: Temp URL invalid

然而,當我運行下面的命令,生成可以直接在瀏覽器上訪問URL,並下載內容。

swift tempurl GET 60 myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt blah -U admin -K PasswordDuh 

這裏是服務器配置的時候我做了stat

      StorageURL: myhosting.url/v1/AUTH_admin 
          Auth Token: AUTH_tkbd65506826b12317a7a3e03e0f547c78 
          Account: AUTH_admin 
          Containers: 10 
          Objects: 147553 
           Bytes: 26544582500 
Containers in policy "del-resilient": 1 
    Objects in policy "del-resilient": 571 
    Bytes in policy "del-resilient": 12312 
        Meta Quota-Bytes: 4182400 
        Meta Temp-Url-Key: blah 
       X-Openstack-Request-Id: tx69915eb0be0f43e89333e-00597f525c 
         Accept-Ranges: bytes 
          Connection: Keep-alive 
           Via: 1.1 ID-0314217254230750 uproxy-3 
         X-Timestamp: 1493105849.12206 
          X-Trans-Id: tx69915eb03456u3e89222e-00597f525c 
         Content-Type: text/plain; charset=utf-8 

什麼我在我的Java代碼缺失?以下是joss的依賴關係

<dependency> 
     <groupId>org.javaswift</groupId> 
     <artifactId>joss</artifactId> 
     <version>0.9.15</version> 
    </dependency> 

回答