Skip to content

Commit

Permalink
Added ticket inform operation
Browse files Browse the repository at this point in the history
  • Loading branch information
zb-sr committed Jun 18, 2024
1 parent e478b9a commit 1779637
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class AuthResponse {
private String refreshToken;
@JsonProperty("scope")
private String scope;
@JsonProperty("error")
private String error;
@JsonProperty("error_description")
private String errorDescription;

public String getAccessToken() {
return accessToken;
Expand Down Expand Up @@ -53,4 +57,20 @@ public String getScope() {
public void setScope(String scope) {
this.scope = scope;
}

public String getError() {
return error;
}

public void setError(String error) {
this.error = error;
}

public String getErrorDescription() {
return errorDescription;
}

public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ private String fetchToken() {
storeToken(newToken, auth.getExpiresIn() != null ? auth.getExpiresIn() : 0);
return newToken;
}
final String authErrMsg = getAuthErrMsg(auth);
if (authErrMsg != null) {
throw new AuthTokenFailureException(authErrMsg);
}
sleep(config.getAuthRetryDelay().toMillis());
return null;
}
Expand Down Expand Up @@ -112,7 +116,23 @@ private String readToken() {
}

private boolean isTokenOK(final String token) {
return token != null && token.length() > 0;
return isNotNullOrEmpty(token);
}

private String getAuthErrMsg(final AuthResponse authResponse) {
if (isNullOrEmpty(authResponse.getError())
&& isNullOrEmpty(authResponse.getErrorDescription())) {
return null;
}
final StringBuilder result = new StringBuilder();
result.append("Auth error");
if (isNotNullOrEmpty(authResponse.getError())) {
result.append(": ").append(authResponse.getError());
}
if (isNotNullOrEmpty(authResponse.getErrorDescription())) {
result.append(": ").append(authResponse.getErrorDescription());
}
return result.toString();
}

private void storeToken(final String token, final int expiresIn) {
Expand All @@ -121,4 +141,12 @@ private void storeToken(final String token, final int expiresIn) {
accessToken = token;
}
}

private boolean isNotNullOrEmpty(final String input) {
return !isNullOrEmpty(input);
}

private boolean isNullOrEmpty(final String input) {
return input == null || input.trim().length() == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public CompletableFuture<TicketResponse> sendTicketAsync(final TicketRequest req
return engine.execute("ticket-placement", request, TicketResponse.class);
}

@Override
public CompletableFuture<TicketInformResponse> sendTicketInformAsync(final TicketInformRequest request) {
return engine.execute("ticket-placement-inform", request, TicketInformResponse.class);
}

@Override
public CompletableFuture<TicketAckResponse> sendTicketAckAsync(final TicketAckRequest request) {
return engine.execute("ticket-placement-ack", request, TicketAckResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ default TicketResponse sendTicket(TicketRequest request)
return this.sendTicketAsync(request).get();
}

/**
* Sends a ticket inform request synchronously and returns the corresponding response.
*
* @param request the ticket inform request to be sent
* @return the ticket inform response received
* @throws ExecutionException if the execution of the request encounters an exception wrapping the cause exception
* @throws InterruptedException if the execution of the request is interrupted
*/
default TicketInformResponse sendTicketInform(TicketInformRequest request)
throws ExecutionException, InterruptedException {
return this.sendTicketInformAsync(request).get();
}

/**
* Sends a ticket acknowledgment request synchronously and returns the corresponding response.
*
Expand Down Expand Up @@ -124,6 +137,14 @@ default ExtSettlementAckResponse sendExtSettlementAck(ExtSettlementAckRequest re
*/
CompletableFuture<TicketResponse> sendTicketAsync(TicketRequest request);

/**
* Sends a ticket inform request asynchronously and returns a CompletableFuture representing the response.
*
* @param request the ticket inform request to be sent
* @return a CompletableFuture representing the ticket inform response
*/
CompletableFuture<TicketInformResponse> sendTicketInformAsync(TicketInformRequest request);

/**
* Sends a ticket acknowledgment request asynchronously and returns a CompletableFuture representing the response.
*
Expand Down

0 comments on commit 1779637

Please sign in to comment.