IBM Cloud Object Storage Java 客户端 - IllegalArgument 异常

IBM Cloud Object Storage Java Client - IllegalArgument exception

我正在关注此处提供的示例 https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#java

创建了以下代码:

SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";

String bucketName = "mybucket_name";
String api_key = "api_key_taken_fro_the_service_credential_json";
String service_instance_id = "service_id_taken_from_the_bucket_policies_page";
String endpoint_url = "http://s3.mel01.objectstorage.softlayer.net";
String location = "mel01";

System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_cos = createClient(api_key, service_instance_id, endpoint_url, location);
listObjects(bucketName, _cos);
listBuckets(_cos);

listObjectslistBuckets 是来自该引用页面的精确 c&p。

我收到 Invalid argument 异常,如下:

Listing objects in bucket mybucket_name
[INFO    ] FFDC1015I: An FFDC Incident has been created: "com.ibm.cloud.objectstorage.services.s3.model.AmazonS3Exception: Invalid Argument (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: 3bb36c4c-8de4-4f39-98f4-a1bfd3aa8972), S3 Extended Request ID: null com.ibm.ws.webcontainer.servlet.ServletWrapper.init 181" at ffdc_18.04.12_13.02.15.0.log
[ERROR   ] SRVE0271E: Uncaught init() exception created by servlet [gas.servlet.BlmxS3Servlet] in application [s3]: com.ibm.cloud.objectstorage.services.s3.model.AmazonS3Exception: Invalid Argument (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: 3bb36c4c-8de4-4f39-98f4-a1bfd3aa8972), S3 Extended Request ID: null
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1588)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1258)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutor.access0(AmazonHttpClient.java:667)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at com.ibm.cloud.objectstorage.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
    at com.ibm.cloud.objectstorage.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3635)
    at com.ibm.cloud.objectstorage.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3582)
    at com.ibm.cloud.objectstorage.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3576)
    at com.ibm.cloud.objectstorage.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:761)
    at gas.servlet.BlmxS3Servlet.listObjects(BlmxS3Servlet.java:94)
    at gas.servlet.BlmxS3Servlet.init(BlmxS3Servlet.java:63)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at [internal classes]

哪个参数可能无效?日志和 ffdc 都没有线索。

更新
存储桶名称正确,否则我得到:

[ERROR   ] SRVE0271E: Uncaught init() exception created by servlet [gas.servlet.BlmxS3Servlet] in application [s3]: com.ibm.cloud.objectstorage.services.s3.model.AmazonS3Exception: The specified bucket does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchBucket; Request ID: bf299e50-1aac-4af7-89df-188eb4b7c60f), S3 Extended Request ID: null

您的 endpoint_url 应该通过 https 而不是 http

配置过程中出现了几个问题:

1) 您需要创建具有 {"HMAC":true}

附加属性的凭据

2) 对于配置使用:

  • apikey - 来自凭据的 apikey 条目
  • service_instance_id - 这有点误导 - 因为它是你的对象服务名称,而不是 id - 在我的例子中它是字符串 Cloud Object Storage-abc
  • endpoint_url - 存储桶端点 - 在我的例子中 http://s3.mel01.objectstorage.softlayer.net - 确保它是 https 并且你将证书导入到你的信任库中。

那么应该可以了。 由于 "Access Denied",列出存储桶对我仍然不起作用,所以我必须检查服务 ID 的权限。