-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2408 Allow retries to be enabled on default Apache HTTP client
- Loading branch information
krystiansola
committed
Oct 2, 2023
1 parent
4b6b53c
commit edafb4a
Showing
4 changed files
with
58 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
karate-core/src/main/java/com/intuit/karate/http/CustomHttpRequestRetryHandler.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,39 @@ | ||
package com.intuit.karate.http; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.NoHttpResponseException; | ||
import org.apache.http.client.HttpRequestRetryHandler; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
import com.intuit.karate.Logger; | ||
|
||
/** | ||
* Calls will retry the call when the client throws a NoHttpResponseException. | ||
* This is usually the case when there is steal connection. The retry cause that | ||
* the connection is renewed and the second call will succeed. | ||
*/ | ||
public class CustomHttpRequestRetryHandler implements HttpRequestRetryHandler | ||
{ | ||
private final Logger logger; | ||
|
||
public CustomHttpRequestRetryHandler(Logger logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) | ||
{ | ||
if (exception instanceof NoHttpResponseException && executionCount < 1) | ||
{ | ||
logger.error("Thrown an NoHttpResponseException retry..."); | ||
return true; | ||
} | ||
else | ||
{ | ||
logger.error("Thrown an exception {}", exception.getMessage()); | ||
return false; | ||
} | ||
} | ||
} |