我没有使用 SellersApi 来获得与 AWS 的连接,您可以参考我的其他回答Amazon Selling Partner API request关于如何使用卖方合作伙伴 API 测试与 AWS 的连接。
此外,下面是如何生成 Java 客户端库的答案。
导航到存储库本地副本的 sells-partner-api-models\models\sellers-api-model 文件夹中的 Sellers.json。
将 Sellers.json 复制到 C:\SwaggerToCL。
生成客户端库。
java -jar C:\SwaggerToCL\swagger-codegen-cli.jar generate -i C:\SwaggerToCL\Sellers.json -l java -o C:\SwaggerToCL\Sellers_JavaCL
然后是你包中的 SellersApi io.swagger.client.api; 包含这样的构建器。
无论如何,您只需阅读代码并了解有关如何连接 AWS 的处理。
public static class Builder {
private AWSAuthenticationCredentials awsAuthenticationCredentials;
private LWAAuthorizationCredentials lwaAuthorizationCredentials;
private String endpoint;
private LWAAccessTokenCache lwaAccessTokenCache;
private Boolean disableAccessTokenCache = false;
private AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider;
public Builder awsAuthenticationCredentials(AWSAuthenticationCredentials awsAuthenticationCredentials) {
this.awsAuthenticationCredentials = awsAuthenticationCredentials;
return this;
}
public Builder lwaAuthorizationCredentials(LWAAuthorizationCredentials lwaAuthorizationCredentials) {
this.lwaAuthorizationCredentials = lwaAuthorizationCredentials;
return this;
}
public Builder endpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
public Builder lwaAccessTokenCache(LWAAccessTokenCache lwaAccessTokenCache) {
this.lwaAccessTokenCache = lwaAccessTokenCache;
return this;
}
public Builder disableAccessTokenCache() {
this.disableAccessTokenCache = true;
return this;
}
public Builder awsAuthenticationCredentialsProvider(AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider) {
this.awsAuthenticationCredentialsProvider = awsAuthenticationCredentialsProvider;
return this;
}
public SellersApi build() {
if (awsAuthenticationCredentials == null) {
throw new RuntimeException("AWSAuthenticationCredentials not set");
}
if (lwaAuthorizationCredentials == null) {
throw new RuntimeException("LWAAuthorizationCredentials not set");
}
if (StringUtil.isEmpty(endpoint)) {
throw new RuntimeException("Endpoint not set");
}
AWSSigV4Signer awsSigV4Signer;
if ( awsAuthenticationCredentialsProvider == null) {
awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials);
}
else {
awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials,awsAuthenticationCredentialsProvider);
}
LWAAuthorizationSigner lwaAuthorizationSigner = null;
if (disableAccessTokenCache) {
lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials);
}
else {
if (lwaAccessTokenCache == null) {
lwaAccessTokenCache = new LWAAccessTokenCacheImpl();
}
lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials,lwaAccessTokenCache);
}
return new SellersApi(new ApiClient()
.setAWSSigV4Signer(awsSigV4Signer)
.setLWAAuthorizationSigner(lwaAuthorizationSigner)
.setBasePath(endpoint));
}
}