diff --git a/clients/sellingpartner-api-aa-java/README.md b/clients/sellingpartner-api-aa-java/README.md
index 169dd2fd..41b47892 100644
--- a/clients/sellingpartner-api-aa-java/README.md
+++ b/clients/sellingpartner-api-aa-java/README.md
@@ -70,7 +70,7 @@ This package returns a custom LWAException when there is an error returned durin
```
## Version
-Selling Partner API Authentication/Authorization Library version 2.0.
+Selling Partner API Authentication/Authorization Library version 3.0.
## Resources
This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/).
diff --git a/clients/sellingpartner-api-aa-java/pom.xml b/clients/sellingpartner-api-aa-java/pom.xml
index 9b51bf46..3fbee269 100644
--- a/clients/sellingpartner-api-aa-java/pom.xml
+++ b/clients/sellingpartner-api-aa-java/pom.xml
@@ -6,22 +6,22 @@
com.amazon.sellingpartnerapi
sellingpartnerapi-aa-java
jar
- 2.0
+ 3.0
org.apache.maven.plugins
maven-compiler-plugin
- 3.1
+ 3.13.0
-
- 1.8
+
+ 17
org.apache.maven.plugins
maven-assembly-plugin
- 3.1.1
+ 3.7.1
build-assembly
@@ -47,39 +47,45 @@
com.amazonaws
aws-java-sdk-signer
- 1.11.610
+ 1.12.777
org.projectlombok
lombok
- 1.18.8
+ 1.18.34
provided
com.google.code.gson
gson
- 2.8.9
+ 2.11.0
-
+
- com.squareup.okhttp
+ com.squareup.okhttp3
okhttp
- 2.7.5
+ 4.12.0
+
+
+
+ com.squareup.okhttp3
+ logging-interceptor
+ 4.12.0
org.junit.jupiter
junit-jupiter-engine
- 5.0.0
+ 5.9.2
test
org.junit.jupiter
junit-jupiter-params
- 5.3.2
+ 5.9.2
test
@@ -87,14 +93,14 @@
org.junit.jupiter
junit-jupiter-migrationsupport
- 5.5.1
+ 5.9.2
test
org.mockito
mockito-core
- 3.0.0
+ 5.11.0
test
@@ -113,7 +119,7 @@
com.amazonaws
aws-java-sdk-sts
- 1.11.236
+ 1.12.777
@@ -121,5 +127,11 @@
guava
30.1-jre
+
+
+ com.github.spotbugs
+ spotbugs-annotations
+ 4.7.3
+
diff --git a/clients/sellingpartner-api-aa-java/resources/java/config.json b/clients/sellingpartner-api-aa-java/resources/java/config.json
index bda9b9a3..15680c68 100644
--- a/clients/sellingpartner-api-aa-java/resources/java/config.json
+++ b/clients/sellingpartner-api-aa-java/resources/java/config.json
@@ -1,3 +1,4 @@
{
- "artifactVersion": "2.0"
+ "artifactVersion": "3.0",
+ "library": "okhttp4-gson"
}
\ No newline at end of file
diff --git a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache
index 6d6c6b56..235371bb 100644
--- a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache
+++ b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache
@@ -2,10 +2,10 @@
package {{invokerPackage}};
-import com.squareup.okhttp.*;
-import com.squareup.okhttp.internal.http.HttpMethod;
-import com.squareup.okhttp.logging.HttpLoggingInterceptor;
-import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
+import okhttp3.*;
+import okhttp3.internal.http.HttpMethod;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
import okio.BufferedSink;
import okio.Okio;
{{#joda}}
@@ -29,11 +29,6 @@ import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
-import java.security.SecureRandom;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
import java.text.DateFormat;
{{#java8}}
import java.time.LocalDate;
@@ -167,45 +162,6 @@ public class ApiClient {
return this;
}
- /**
- * Get SSL CA cert.
- *
- * @return Input stream to the SSL CA cert
- */
- public InputStream getSslCaCert() {
- return sslCaCert;
- }
-
- /**
- * Configure the CA certificate to be trusted when making https requests.
- * Use null to reset to default.
- *
- * @param sslCaCert input stream for SSL CA cert
- * @return ApiClient
- */
- public ApiClient setSslCaCert(InputStream sslCaCert) {
- this.sslCaCert = sslCaCert;
- applySslSettings();
- return this;
- }
-
- public KeyManager[] getKeyManagers() {
- return keyManagers;
- }
-
- /**
- * Configure client keys to use for authorization in an SSL session.
- * Use null to reset to default.
- *
- * @param managers The KeyManagers to use
- * @return ApiClient
- */
- public ApiClient setKeyManagers(KeyManager[] managers) {
- this.keyManagers = managers;
- applySslSettings();
- return this;
- }
-
public DateFormat getDateFormat() {
return dateFormat;
}
@@ -425,20 +381,7 @@ public class ApiClient {
* @return Timeout in milliseconds
*/
public int getConnectTimeout() {
- return httpClient.getConnectTimeout();
- }
-
- /**
- * Sets the connect timeout (in milliseconds).
- * A value of 0 means no timeout, otherwise values must be between 1 and
- * {@link Integer#MAX_VALUE}.
- *
- * @param connectionTimeout connection timeout in milliseconds
- * @return Api client
- */
- public ApiClient setConnectTimeout(int connectionTimeout) {
- httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
- return this;
+ return httpClient.connectTimeoutMillis();
}
/**
@@ -447,20 +390,7 @@ public class ApiClient {
* @return Timeout in milliseconds
*/
public int getReadTimeout() {
- return httpClient.getReadTimeout();
- }
-
- /**
- * Sets the read timeout (in milliseconds).
- * A value of 0 means no timeout, otherwise values must be between 1 and
- * {@link Integer#MAX_VALUE}.
- *
- * @param readTimeout read timeout in milliseconds
- * @return Api client
- */
- public ApiClient setReadTimeout(int readTimeout) {
- httpClient.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS);
- return this;
+ return httpClient.readTimeoutMillis();
}
/**
@@ -469,20 +399,7 @@ public class ApiClient {
* @return Timeout in milliseconds
*/
public int getWriteTimeout() {
- return httpClient.getWriteTimeout();
- }
-
- /**
- * Sets the write timeout (in milliseconds).
- * A value of 0 means no timeout, otherwise values must be between 1 and
- * {@link Integer#MAX_VALUE}.
- *
- * @param writeTimeout connection timeout in milliseconds
- * @return Api client
- */
- public ApiClient setWriteTimeout(int writeTimeout) {
- httpClient.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS);
- return this;
+ return httpClient.writeTimeoutMillis();
}
/**
@@ -902,15 +819,15 @@ public class ApiClient {
public void executeAsync(Call call, final Type returnType, final ApiCallback callback) {
call.enqueue(new Callback() {
@Override
- public void onFailure(Request request, IOException e) {
+ public void onFailure(Call call, IOException e) {
callback.onFailure(new ApiException(e), 0, null);
}
@Override
- public void onResponse(Response response) throws IOException {
+ public void onResponse(Call call, Response response) {
T result;
try {
- result = (T) handleResponse(response, returnType);
+ result = handleResponse(response, returnType);
} catch (ApiException e) {
callback.onFailure(e, response.code(), response.headers().toMultimap());
return;
@@ -938,7 +855,7 @@ public class ApiClient {
if (response.body() != null) {
try {
response.body().close();
- } catch (IOException e) {
+ } catch (Exception e) {
throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap());
}
}
@@ -1131,7 +1048,7 @@ public class ApiClient {
* @return RequestBody
*/
public RequestBody buildRequestBodyFormEncoding(Map formParams) {
- FormEncodingBuilder formBuilder = new FormEncodingBuilder();
+ FormBody.Builder formBuilder = new FormBody.Builder();
for (Entry param : formParams.entrySet()) {
formBuilder.add(param.getKey(), parameterToString(param.getValue()));
}
@@ -1146,7 +1063,7 @@ public class ApiClient {
* @return RequestBody
*/
public RequestBody buildRequestBodyMultipart(Map formParams) {
- MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
+ MultipartBody.Builder mpBuilder = new MultipartBody.Builder();
for (Entry param : formParams.entrySet()) {
if (param.getValue() instanceof File) {
File file = (File) param.getValue();
@@ -1176,45 +1093,6 @@ public class ApiClient {
}
}
- /**
- * Apply SSL related settings to httpClient according to the current values of
- * sslCaCert.
- */
- private void applySslSettings() {
- try {
- TrustManager[] trustManagers = null;
- HostnameVerifier hostnameVerifier = null;
- if (sslCaCert != null) {
- char[] password = null; // Any password will work.
- CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
- Collection extends Certificate> certificates = certificateFactory.generateCertificates(sslCaCert);
- if (certificates.isEmpty()) {
- throw new IllegalArgumentException("expected non-empty set of trusted certificates");
- }
- KeyStore caKeyStore = newEmptyKeyStore(password);
- int index = 0;
- for (Certificate certificate : certificates) {
- String certificateAlias = "ca" + Integer.toString(index++);
- caKeyStore.setCertificateEntry(certificateAlias, certificate);
- }
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- trustManagerFactory.init(caKeyStore);
- trustManagers = trustManagerFactory.getTrustManagers();
- }
-
- if (keyManagers != null || trustManagers != null) {
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(keyManagers, trustManagers, new SecureRandom());
- httpClient.setSslSocketFactory(sslContext.getSocketFactory());
- } else {
- httpClient.setSslSocketFactory(null);
- }
- httpClient.setHostnameVerifier(hostnameVerifier);
- } catch (GeneralSecurityException e) {
- throw new RuntimeException(e);
- }
- }
-
private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
diff --git a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache
index 63cab300..d490ca8d 100644
--- a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache
+++ b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache
@@ -90,7 +90,7 @@ public class {{classname}} {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
- public com.squareup.okhttp.Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException, LWAException {
+ public okhttp3.Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException, LWAException {
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
// create path and map variables
@@ -123,10 +123,10 @@ public class {{classname}} {
{{localVariablePrefix}}localVarHeaderParams.put("Content-Type", {{localVariablePrefix}}localVarContentType);
if(progressListener != null) {
- apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
+ apiClient.getHttpClient().networkInterceptors().add(new okhttp3.Interceptor() {
@Override
- public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
- com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
+ public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
+ okhttp3.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
@@ -142,7 +142,7 @@ public class {{classname}} {
@Deprecated
{{/isDeprecated}}
@SuppressWarnings("rawtypes")
- private com.squareup.okhttp.Call {{operationId}}ValidateBeforeCall({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException, LWAException {
+ private okhttp3.Call {{operationId}}ValidateBeforeCall({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException, LWAException {
{{^performBeanValidation}}
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
@@ -151,7 +151,7 @@ public class {{classname}} {
}
{{/required}}{{/allParams}}
- com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
+ okhttp3.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
return {{localVariablePrefix}}call;
{{/performBeanValidation}}
@@ -166,7 +166,7 @@ public class {{classname}} {
parameterValues);
if (violations.size() == 0) {
- com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
+ okhttp3.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
return {{localVariablePrefix}}call;
} else {
@@ -225,7 +225,7 @@ public class {{classname}} {
@Deprecated
{{/isDeprecated}}
public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException,LWAException {
- com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null, null);
+ okhttp3.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null, null);
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType);{{/returnType}}{{^returnType}}return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}}
}
@@ -249,7 +249,7 @@ public class {{classname}} {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
- public com.squareup.okhttp.Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException, LWAException {
+ public okhttp3.Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException, LWAException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@@ -270,7 +270,7 @@ public class {{classname}} {
};
}
- com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
+ okhttp3.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType, {{localVariablePrefix}}callback);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}callback);{{/returnType}}
return {{localVariablePrefix}}call;
diff --git a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/build.gradle.mustache b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/build.gradle.mustache
new file mode 100644
index 00000000..3ab8f1ea
--- /dev/null
+++ b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/build.gradle.mustache
@@ -0,0 +1,61 @@
+/*
+* okhttp
+*/
+plugins {
+id 'java'
+id 'maven-publish'
+}
+
+repositories {
+mavenLocal()
+maven {
+url = uri('https://repo.maven.apache.org/maven2/')
+}
+}
+
+dependencies {
+implementation 'io.swagger:swagger-annotations:1.6.9'
+implementation 'com.squareup.okhttp3:okhttp:4.12.0'
+implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
+implementation 'com.google.code.gson:gson:2.10.1'
+implementation 'io.gsonfire:gson-fire:1.8.5'
+implementation 'javax.annotation:javax.annotation-api:1.3.2'
+implementation 'io.swagger.core.v3:swagger-annotations:2.2.16'
+{{#joda}}
+ implementation 'joda-time:joda-time:2.12.1'
+{{/joda}}
+{{#threetenbp}}
+ implementation 'org.threeten:threetenbp:1.6.5'
+{{/threetenbp}}
+testImplementation 'junit:junit:4.13.2'
+}
+
+group = '{{groupId}}'
+version = '{{artifactVersion}}'
+description = '{{artifactDescription}}'
+
+java.sourceCompatibility = 11
+java.targetCompatibility = 11
+
+tasks.register('testsJar', Jar) {
+archiveClassifier = 'tests'
+from(sourceSets.test.output)
+}
+
+java {
+withSourcesJar()
+withJavadocJar()
+}
+
+publishing {
+publications {
+maven(MavenPublication) {
+from(components.java)
+artifact(testsJar)
+}
+}
+}
+
+tasks.withType(JavaCompile) {
+options.encoding = 'UTF-8'
+}
\ No newline at end of file
diff --git a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSigner.java b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSigner.java
index b3d64093..30813f29 100644
--- a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSigner.java
+++ b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSigner.java
@@ -1,9 +1,9 @@
package com.amazon.SellingPartnerAPIAA;
-import com.squareup.okhttp.Request;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
+import okhttp3.Request;
/**
* LWA Authorization Signer
diff --git a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAClient.java b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAClient.java
index eb91ee1e..75273474 100644
--- a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAClient.java
+++ b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/LWAClient.java
@@ -3,14 +3,15 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.RequestBody;
-import com.squareup.okhttp.Response;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
import org.apache.commons.lang3.EnumUtils;
class LWAClient {
@@ -60,7 +61,10 @@ String getAccessTokenFromEndpoint(LWAAccessTokenRequestMeta lwaAccessTokenReques
String accessToken;
try {
Response response = okHttpClient.newCall(accessTokenRequest).execute();
- JsonObject responseJson = new JsonParser().parse(response.body().string()).getAsJsonObject();
+ ResponseBody body = response.body();
+ if (body == null) throw new LWAException(LWAExceptionErrorCode.other.toString(),
+ "Error getting LWA Token", "Response body missing");
+ JsonObject responseJson = JsonParser.parseString(body.string()).getAsJsonObject();
if (!response.isSuccessful()) {
// Check if response has element error and is a known LWA error code
if (responseJson.has("error") &&
diff --git a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/ScopeConstants.java b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/ScopeConstants.java
index 8d71dd11..6b2afd13 100644
--- a/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/ScopeConstants.java
+++ b/clients/sellingpartner-api-aa-java/src/com/amazon/SellingPartnerAPIAA/ScopeConstants.java
@@ -2,7 +2,7 @@
public final class ScopeConstants {
- private ScopeConstants(){
+ private ScopeConstants() {
}
public static final String SCOPE_NOTIFICATIONS_API = "sellingpartnerapi::notifications";
diff --git a/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSignerTest.java b/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSignerTest.java
index ee0e6f2b..c2c8d88f 100644
--- a/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSignerTest.java
+++ b/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAAuthorizationSignerTest.java
@@ -1,13 +1,12 @@
package com.amazon.SellingPartnerAPIAA;
-import com.squareup.okhttp.Call;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Protocol;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
-import com.squareup.okhttp.ResponseBody;
-
+import okhttp3.Call;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Protocol;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAClientTest.java b/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAClientTest.java
index 94d1a97a..b8c92163 100644
--- a/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAClientTest.java
+++ b/clients/sellingpartner-api-aa-java/tst/com/amazon/SellingPartnerAPIAA/LWAClientTest.java
@@ -2,13 +2,13 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import com.squareup.okhttp.Call;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Protocol;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
-import com.squareup.okhttp.ResponseBody;
+import okhttp3.Call;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Protocol;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
import okio.Buffer;
import org.junit.Before;
import org.junit.Test;
@@ -205,6 +205,19 @@ public void missingAccessTokenInResponseThrowsException(String sellerType, LWAAc
underTest.getAccessToken(testLwaAccessTokenRequestMeta);
});
}
+
+ @ParameterizedTest
+ @MethodSource("lwaClient")
+ public void missingResponseBodyThrowsLwaException(String sellerType, LWAAccessTokenRequestMeta testLwaAccessTokenRequestMeta) throws IOException {
+ when(mockOkHttpClient.newCall(any(Request.class)))
+ .thenReturn(mockCall);
+ when(mockCall.execute())
+ .thenReturn(buildResponse(200));
+
+ Assertions.assertThrows(LWAException.class, () -> {
+ underTest.getAccessToken(testLwaAccessTokenRequestMeta);
+ });
+ }
//Test for Access Token getting from cache
@Test
@@ -239,7 +252,7 @@ public void returnAccessTokenFromCacheWithExpiry() throws IOException, Interrupt
assertEquals("Azta|foo1", client.getAccessToken(lwaAccessTokenRequestMetaSeller));
}
- private static Response buildResponse(int code, String accessToken, String expiryInSeconds,String errorCode, String errorMessage) {
+ private static Response buildResponse(int code, String accessToken, String expiryInSeconds, String errorCode, String errorMessage) {
ResponseBody responseBody = ResponseBody.create(EXPECTED_MEDIA_TYPE,
String.format("{%s:%s,%s:%s,%s:%s,%s:%s}", "access_token", accessToken, "expires_in", expiryInSeconds, "error", errorCode, "error_description", errorMessage));
@@ -272,4 +285,14 @@ private static Response buildResponse(int code, String accessToken,String expiry
.message("OK")
.build();
}
+
+ private static Response buildResponse(int code) {
+ return new Response.Builder()
+ .request(new Request.Builder().url(TEST_ENDPOINT).build())
+ .code(code)
+ .body(null)
+ .protocol(Protocol.HTTP_1_1)
+ .message("OK")
+ .build();
+ }
}