我寫了一個應用程序來保存對象存儲中的文件。 我在連接到對象存儲,當Bluemix連接返回一個錯誤的問題({的AuthenticationException消息=未經授權,狀態= 401})對象存儲返回未授權的Java連接401
我使用的openstack4j實現,這是我的代碼:
String envServices = System.getenv("VCAP_SERVICES");
if (envServices != null) {
JSONParser parser = new JSONParser();
Object obj = parser.parse(envServices);
JSONObject jsonObject = (JSONObject) obj;
JSONArray vcapArray = (JSONArray) jsonObject.get("Object-Storage");
JSONObject vcap = (JSONObject) vcapArray.get(0);
JSONObject credentials = (JSONObject) vcap.get("credentials");
username = credentials.get("username").toString();
password = credentials.get("password").toString();
auth_url = credentials.get("auth_url").toString() + "/v3";
domain = credentials.get("domainId").toString();
project = credentials.get("projectId").toString();
} else {
username = "someuser";
password = "somepassword";
auth_url = "https://identity.open.softlayer.com";
domain = "sfsd";
project = "object_storage_xxxxxxx";
}
Identifier domainIdent = Identifier.byName(domain);
Identifier projectIdent = Identifier.byName(project);
OSClient os = OSFactory.builderV3().endpoint(auth_url).credentials(username, password,domainIdent).scopeToProject(projectIdent, domainIdent)
.authenticate();
objectStorage = os.objectStorage();
account = objectStorage.account().get();
任何幫助將不勝感激。 阿西