Reputation: 21
I have followed all the steps to generate SDK and .jar files. . I have included the external jar into my project and stepping through the documentation "[Connecting to the Selling Partner API using a generated Java SDK https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#connecting-to-the-selling-partner-api-using-a-generated-java-sdk
Step 1:
AWSAuthenticationCredentials awsAuthenticationCredentials=AWSAuthenticationCredentials.builder()
.accessKeyId("myAccessKeyId")
.secretKey("mySecretId")
.region("us-east-1")
.build();
Step 2:
AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider=AWSAuthenticationCredentialsProvider.builder()
.roleArn("myroleARN")
.roleSessionName("myrolesessioname")
.build();
Step 3:
LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
.clientId("myClientId")
.clientSecret("myClientSecret")
.refreshToken("Aztr|...")
.endpoint("https://api.amazon.com/auth/o2/token")
.build();
Step 4:
SellersApi sellersApi = new SellersApi.Builder()
.awsAuthenticationCredentials(awsAuthenticationCredentials)
.lwaAuthorizationCredentials(lwaAuthorizationCredentials)
.awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
.endpoint("https://sellingpartnerapi-na.amazon.com")
.build();
Issue is at step 4 The class SellersAPI has no method Builder so SellersApi.Builder() is unreslolved.
Upvotes: 2
Views: 2275
Reputation: 10803
Add this builder to your SellersApi.java class:
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));
}
}
add awsSigV4Signer
and lwaAuthorizationSigner
to ApiClient.java as fields and append those two lines at the end of the buildRequest
method before return:
request = lwaAuthorizationSigner.sign(request);
request = awsSigV4Signer.sign(request);
Upvotes: 1
Reputation: 136
I'm not using SellersApi to get the connection with AWS, you can reference my other answer Amazon Selling Partner API request about how to test connection with AWS using Seller Partner API.
Also, here is the answer how to Generating a Java client library below.
Navigate to sellers.json in the selling-partner-api-models\models\sellers-api-model folder of your local copy of the repository.
Copy sellers.json into C:\SwaggerToCL.
Generate the client Library.
java -jar C:\SwaggerToCL\swagger-codegen-cli.jar generate -i C:\SwaggerToCL\Sellers.json -l java -o C:\SwaggerToCL\Sellers_JavaCL
Then the SellersApi in your package io.swagger.client.api; contains builder like this.
Anyway, you can just read the code and know the processing about how to connect with 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));
}
}
Upvotes: 1