Java 使用BlobStore为对象生成临时URI
我正在尝试使用jClouds BlobStore特性为存储在OpenStack Swift容器中的对象实现一个临时GET URI的生成 然而,我得到了这些错误:Java 使用BlobStore为对象生成临时URI,java,openstack,openstack-swift,jclouds,Java,Openstack,Openstack Swift,Jclouds,我正在尝试使用jClouds BlobStore特性为存储在OpenStack Swift容器中的对象实现一个临时GET URI的生成 然而,我得到了这些错误: java.lang.IllegalStateException: Suppliers.memoizeWithExpiration(get().getTemporaryUrlKey() using {annotationParser={caller=SwiftApi.accountApiInRegion[RegionOne]}}, 600
java.lang.IllegalStateException: Suppliers.memoizeWithExpiration(get().getTemporaryUrlKey() using {annotationParser={caller=SwiftApi.accountApiInRegion[RegionOne]}}, 60000000000, NANOS) returned a null temporaryUrlKey!
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.hmacSHA1(TemporaryUrlSigner.java:63)
at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.sign(TemporaryUrlSigner.java:57)
at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.sign(RegionScopedTemporaryUrlBlobSigner.java:100)
at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.signGetBlob(RegionScopedTemporaryUrlBlobSigner.java:73)
下面是一个代码示例:
public class BlobStoreObjectSignerService implements ObjectSignerService {
@Autowired
private BlobRequestSigner blobRequestSigner;
@Value("${blobStore.private.container}")
String privateContainerName;
/**
* Generates signed request With GET Method to access allocated object.
*
* @param objectName name of the stored file
* @param principalName name of the principal (user) which is putted the file
* @param temporary defines if file should be available for a limited time
* @param timeToLive time in seconds file will be available for fetching
*/
public HttpRequest generateGetRequestForObject( String objectName,
String principalName,
boolean temporary,
long timeToLive ) {
if (temporary) {
return this.generateTemporaryGetRequestForObject(objectName, principalName, timeToLive);
} else {
return this.generatePermanentGetRequestForObject(objectName, principalName);
}
}
public HttpRequest generatePermanentGetRequestForObject( String objectName,
String principalName ) {
return this.generatePermanentGetRequestForObject( privateContainerName,
String.format( "/%s/%s", principalName, objectName ) );
}
public HttpRequest generateTemporaryGetRequestForObject( String objectName,
String principalName,
long timeToLive ) {
return this.generateTemporaryGetRequestForObject( privateContainerName,
String.format( "/%s/%s", principalName, objectName ),
timeToLive );
}
public HttpRequest generatePermanentGetRequestForObject(String containerName, String objectName) {
return this.blobRequestSigner.signGetBlob(containerName, objectName);
}
public HttpRequest generateTemporaryGetRequestForObject(String containerName, String objectName, long timeToLive) {
return this.blobRequestSigner.signGetBlob(containerName, objectName, timeToLive);
}
}
至于公共容器,我仍然可以通过获取头/元数据来获取对象链接,这有点像是横向的,但我仍然需要签名URI来发布存储在私有容器中的对象
使用BlobStore将文件放入容器中工作正常。OpenStack仪表板通常会显示所有推送的文件
我只在开发环境中使用Java 7和为Swift配置的DevStack。
jClouds版本是1.7.2。根据例外情况,您的帐户上似乎没有设置临时URL密钥。您可以通过
AccountApi
将密钥更新为新值,如下所示:
SwiftApi swiftApi = ContextBuilder.newBuilder(PROVIDER)
.credentials("{username}", "{apiKey}")
.buildApi(SwiftApi.class);
// Access the accountApi
AccountApi accountApi = swiftApi.getAccountApiForRegion("{regionId");
accountApi.updateTemporaryUrlKey("{newKey}");
// Access the key
String tempUrlKey;
if (accountApi.getTemporaryUrlKey().isPresent()) {
tempUrlKey = accountApi.get().getTemporaryUrlKey().get();
}
希望有帮助 成功了,谢谢!由于某些原因,钥匙似乎没有正确设置。