Skip to content

Commit 00744fd

Browse files
committed
add SSLException into retry condition.
1 parent 7963ebf commit 00744fd

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/main/java/com/aliyun/oss/ClientErrorCode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public interface ClientErrorCode {
6161
* Thread interrupted while reading the input stream.
6262
*/
6363
static final String INPUTSTREAM_READING_ABORTED = "InputStreamReadingAborted";
64+
65+
/**
66+
* Ssl exception
67+
*/
68+
static final String SSL_EXCEPTION = "SslException";
6469
}

src/main/java/com/aliyun/oss/common/comm/DefaultServiceClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ public boolean shouldRetry(Exception ex, RequestMessage request, ResponseMessage
195195
|| errorCode.equals(ClientErrorCode.SOCKET_TIMEOUT)
196196
|| errorCode.equals(ClientErrorCode.CONNECTION_REFUSED)
197197
|| errorCode.equals(ClientErrorCode.UNKNOWN_HOST)
198-
|| errorCode.equals(ClientErrorCode.SOCKET_EXCEPTION)) {
198+
|| errorCode.equals(ClientErrorCode.SOCKET_EXCEPTION)
199+
|| errorCode.equals(ClientErrorCode.SSL_EXCEPTION)) {
199200
return true;
200201
}
201202

src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.SocketException;
2626
import java.net.SocketTimeoutException;
2727
import java.net.UnknownHostException;
28+
import javax.net.ssl.SSLException;
2829

2930
import org.apache.http.NoHttpResponseException;
3031
import org.apache.http.client.ClientProtocolException;
@@ -60,6 +61,8 @@ public static ClientException createNetworkException(IOException ex) {
6061
errorCode = ClientErrorCode.CONNECTION_REFUSED;
6162
} else if (ex instanceof NoHttpResponseException) {
6263
errorCode = ClientErrorCode.CONNECTION_TIMEOUT;
64+
} else if (ex instanceof SSLException) {
65+
errorCode = ClientErrorCode.SSL_EXCEPTION;
6366
} else if (ex instanceof ClientProtocolException) {
6467
Throwable cause = ex.getCause();
6568
if (cause instanceof NonRepeatableRequestException) {

src/test/java/com/aliyun/oss/common/utils/ExceptionFactoryTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.IOException;
2626
import java.net.SocketException;
2727
import java.net.SocketTimeoutException;
28+
import javax.net.ssl.SSLException;
2829

2930
import com.aliyun.oss.OSSException;
3031
import com.aliyun.oss.internal.model.OSSErrorResult;
@@ -36,6 +37,8 @@
3637
import com.aliyun.oss.ClientErrorCode;
3738
import com.aliyun.oss.ClientException;
3839

40+
import javax.net.ssl.SSLException;
41+
3942
public class ExceptionFactoryTest {
4043

4144
@Test
@@ -52,6 +55,10 @@ public void testCreateNetworkException() {
5255
ex = ExceptionFactory.createNetworkException(cte);
5356
assertEquals(ex.getErrorCode(), ClientErrorCode.CONNECTION_TIMEOUT);
5457

58+
SSLException slle = new SSLException("");
59+
ex = ExceptionFactory.createNetworkException(slle);
60+
assertEquals(ex.getErrorCode(), ClientErrorCode.SSL_EXCEPTION);
61+
5562
IOException ioe = new IOException();
5663
ex = ExceptionFactory.createNetworkException(ioe);
5764
assertEquals(ex.getErrorCode(), ClientErrorCode.UNKNOWN);

0 commit comments

Comments
 (0)