Java代码
`// Set up authentication details with hardcoded values
SimpleAuthenticationDetailsProvider authProvider = SimpleAuthenticationDetailsProvider.builder()
.tenantId(tenantId)
.userId(accountId)
.fingerprint(accessKeyId)
.privateKeySupplier(new SimplePrivateKeySupplier(file.getLocation()))
.region(Region.valueOf(location.toUpperCase()))
.build();
// Create an Identity client
Identity identityClient = new IdentityClient(authProvider);
// Make a simple API call to list availability domains
ListAvailabilityDomainsResponse response =
identityClient.listAvailabilityDomains(
ListAvailabilityDomainsRequest.builder()
.compartmentId(tenantId)
.build());
if (response.getItems() != null && !response.getItems().isEmpty()) {
logger.debug("Credentials are valid.");
} else {
logger.debug("Credentials are invalid.");
}`
依赖关系
<!-- https://mvnrepository.com/artifact/com.oracle.oci.sdk/oci-java-sdk-core -->
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-core</artifactId>
<version>3.23.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.oci.sdk/oci-java-sdk-identity -->
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-identity</artifactId>
<version>3.23.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.oci.sdk/oci-java-sdk-common-httpclient-jersey -->
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common-httpclient-jersey</artifactId>
<version>3.23.2</version>
</dependency>
<!-- Jersey Core -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.1.1</version> <!-- Use the latest version -->
</dependency>
<!-- Jersey Jackson Support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.1.1</version> <!-- Use the same version as jersey-server -->
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
我得到了 我得到的错误是 身份服务中的 ListAvailabilityDomains 操作返回错误。(-1, null, false) 未知错误 时间戳: 2023-08-29T11:53:40.327Z 客户端版本:Oracle-JavaSDK/3.23.2 请求端点:https://identity.eu-frankfurt-1.oci.oraclecloud.com/20160918/availabilityDomains?compartmentId= 故障排除提示:有关解决此错误的更多信息,请参阅 https://docs.oracle.com/en-us/iaas/Content/API/References/apierrors.htm#apierrors_-1__-1_。 我什至尝试使用其他使用 listRegions() 的方法或使用 listInstances() 的方法进行身份验证,但它们也给出相同的错误
这个案例有什么解决办法吗?我遇到了同样的问题,尝试了几乎所有的解决方案,但没有成功