-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SYMPHONYP-939 implements review comments
- Loading branch information
1 parent
2d448ea
commit 80509b3
Showing
9 changed files
with
82 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...rter/src/main/java/org/finos/springbot/teams/handlers/retry/BasicMessageRetryHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.finos.springbot.teams.handlers.retry; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.concurrent.CompletionException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.finos.springbot.workflow.response.Response; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import com.microsoft.bot.connector.rest.ErrorResponseException; | ||
|
||
import okhttp3.ResponseBody; | ||
|
||
public abstract class BasicMessageRetryHandler implements MessageRetryHandler { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(BasicMessageRetryHandler.class); | ||
|
||
@Value("${teams.retry.count:3}") | ||
private long teamsRetryCount; | ||
|
||
public boolean handleException(Response t, int retryCount, Throwable e) { | ||
if (e instanceof CompletionException | ||
&& ((CompletionException) e).getCause() instanceof ErrorResponseException) { | ||
ErrorResponseException ere = (ErrorResponseException) ((CompletionException) e).getCause(); | ||
retrofit2.Response<ResponseBody> response = ere.response(); | ||
if (response.code() == HttpStatus.TOO_MANY_REQUESTS.value() && retryCount <= teamsRetryCount) { | ||
String retryAfter = response.headers().get("Retry-After"); | ||
LOG.info("MessageRetryHandler request retryAfter {}", retryAfter); | ||
|
||
int retryAfterInt = 1;//initiate to 1 sec | ||
if(StringUtils.isNumeric(retryAfter)) { | ||
retryAfterInt = Integer.parseInt(retryAfter); | ||
} | ||
LocalDateTime time = LocalDateTime.now().plusSeconds(retryAfterInt); | ||
add(new MessageRetry(t, retryCount, retryAfterInt, time)); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected abstract void add(MessageRetry messageRetry); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 5 additions & 41 deletions
46
...t-starter/src/main/java/org/finos/springbot/teams/handlers/retry/MessageRetryHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,13 @@ | ||
package org.finos.springbot.teams.handlers.retry; | ||
|
||
import java.util.concurrent.CompletionException; | ||
import java.util.Optional; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.finos.springbot.workflow.response.Response; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import com.microsoft.bot.connector.rest.ErrorResponseException; | ||
|
||
import okhttp3.ResponseBody; | ||
|
||
public abstract class MessageRetryHandler implements RetryHandler { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MessageRetryHandler.class); | ||
public interface MessageRetryHandler { | ||
|
||
@Value("${teams.retry.count:3}") | ||
private long teamsRetryCount; | ||
|
||
public boolean handleException(Response t, int retryCount, Throwable e) { | ||
if (e instanceof CompletionException | ||
&& ((CompletionException) e).getCause() instanceof ErrorResponseException) { | ||
ErrorResponseException ere = (ErrorResponseException) ((CompletionException) e).getCause(); | ||
retrofit2.Response<ResponseBody> response = ere.response(); | ||
if (response.code() == HttpStatus.TOO_MANY_REQUESTS.value() && retryCount <= teamsRetryCount) { | ||
String retryAfter = response.headers().get("Retry-After"); | ||
LOG.info("MessageRetryHandler request retryAfter {}", retryAfter); | ||
|
||
int retryAfterInt = 1;//initiate to 1 sec | ||
if(StringUtils.isNumeric(retryAfter)) { | ||
retryAfterInt = Integer.parseInt(retryAfter); | ||
} | ||
|
||
add(new MessageRetry(t, retryCount, retryAfterInt)); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
public boolean handleException(Response t, int retryCount, Throwable e); | ||
|
||
public Optional<MessageRetry> get(); | ||
|
||
protected abstract void add(MessageRetry messageRetry); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
...ing-boot-starter/src/main/java/org/finos/springbot/teams/handlers/retry/RetryHandler.java
This file was deleted.
Oops, something went wrong.