Skip to content

Jwenger/issue fixes #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions src/main/java/Avalara/SDK/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,18 @@ public ApiClient(Configuration config) throws Exception {
init();
initHttpClient();

// TODO: Add back when client creds flow is available through AI.
// Setup authentications (key: authentication name, value: authentication).
if (StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isEmpty(config.getBearerToken())) {
OpenIdHelper.populateConfigWithOpenIdDetails(config);
RetryingOAuth retryingOAuth = new RetryingOAuth(config.getTokenUrl(), config.getClientId(),
config.getClientSecret(), new ClientCredentialsGrant(), null);
authentications.put(
"OAuth",
retryingOAuth
);
initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
}
// if (StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isEmpty(config.getBearerToken())) {
// OpenIdHelper.populateConfigWithOpenIdDetails(config);
// RetryingOAuth retryingOAuth = new RetryingOAuth(config.getTokenUrl(), config.getClientId(),
// config.getClientSecret(), new ClientCredentialsGrant(), null);
// authentications.put(
// "OAuth",
// retryingOAuth
// );
// initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
// }

// Set Authentication type based on Configuration passed into the ApiClient
if (config.getUsername() != null && config.getPassword() != null) {
Expand Down Expand Up @@ -597,6 +598,12 @@ public ApiClient setWriteTimeout(int writeTimeout) {
}


/**
* Format the given parameter object into string.
*
* @param param Parameter
* @return String representation of the parameter
*/
/**
* Format the given parameter object into string.
*
Expand All @@ -606,22 +613,36 @@ public ApiClient setWriteTimeout(int writeTimeout) {
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
}
// 1) Primitive wrappers and Strings → plain text
if (param instanceof String) {
return (String) param;
}
if (param instanceof Number || param instanceof Boolean) {
return String.valueOf(param);
}
if (param instanceof OffsetDateTime odt) {
// Convert to LocalDateTime and format as ISO_LOCAL_DATE_TIME
return odt
.toLocalDateTime()
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
if (param instanceof Date || param instanceof LocalDate) {
String jsonStr = json.serialize(param);
// e.g. "\"2025-05-06T12:00:00Z\"" → "2025-05-06T12:00:00Z"
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
}
if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection) param) {
if (b.length() > 0) {
for (Object o : (Collection<?>) param) {
if (!b.isEmpty()) {
b.append(",");
}
b.append(String.valueOf(o));
b.append(parameterToString(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
return json.serialize(param);
}

/**
Expand Down Expand Up @@ -997,8 +1018,7 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
* @throws Avalara.SDK.ApiException If fail to execute the call
*/
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
try {
Response response = call.execute();
try (Response response = call.execute()) {
T data = handleResponse(response, returnType);
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
} catch (IOException e) {
Expand Down Expand Up @@ -1037,16 +1057,14 @@ public void onFailure(Call call, IOException e) {
@Override
public void onResponse(Call call, Response response) throws IOException {
T result;
try {
result = (T) handleResponse(response, returnType);
try (Response r = response) {
result = (T) handleResponse(r, returnType);
callback.onSuccess(result, r.code(), r.headers().toMultimap());
} catch (ApiException e) {
callback.onFailure(e, response.code(), response.headers().toMultimap());
return;
} catch (Exception e) {
callback.onFailure(new ApiException(e), response.code(), response.headers().toMultimap());
return;
}
callback.onSuccess(result, response.code(), response.headers().toMultimap());
}
});
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/Avalara/SDK/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,6 @@ public void setClientId(String clientId) {
ClientId = clientId;
}

/**
* Gets or sets the ClientSecret Used for OAuth2 Client Credentials flow.
*/
private String ClientSecret;

public String getClientSecret() {
return ClientSecret;
}

public void setClientSecret(String clientSecret) {
ClientSecret = clientSecret;
}

/**
* Gets the Base Path.
*/
Expand Down
Loading