|
22 | 22 |
|
23 | 23 | public class NativeHttpClient implements IHttpClient { |
24 | 24 | private static final Logger LOG = LoggerFactory.getLogger(NativeHttpClient.class); |
| 25 | + private static final String KEYWORDS_CONNECT_TIMED_OUT = "connect timed out"; |
| 26 | + private static final String KEYWORDS_READ_TIMED_OUT = "Read timed out"; |
25 | 27 |
|
26 | 28 | private int _maxRetryTimes = 0; |
27 | 29 |
|
@@ -53,11 +55,16 @@ public ResponseWrapper sendRequest(String url, String content, |
53 | 55 | try { |
54 | 56 | response = _sendRequest(url, content, method, authCode); |
55 | 57 | break; |
56 | | - } catch (SocketTimeoutException e) { // connect timed out |
57 | | - if (retryTimes >= _maxRetryTimes) { |
58 | | - throw new APIConnectionException(e); |
59 | | - } else { |
60 | | - LOG.debug("connect timed out - retry again - " + (retryTimes + 1)); |
| 58 | + } catch (SocketTimeoutException e) { |
| 59 | + if (KEYWORDS_READ_TIMED_OUT.equals(e.getMessage())) { |
| 60 | + // Read timed out. For push, maybe should not re-send. |
| 61 | + throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true); |
| 62 | + } else { // connect timed out |
| 63 | + if (retryTimes >= _maxRetryTimes) { |
| 64 | + throw new APIConnectionException(CONNECT_TIMED_OUT_MESSAGE, e); |
| 65 | + } else { |
| 66 | + LOG.debug("connect timed out - retry again - " + (retryTimes + 1)); |
| 67 | + } |
61 | 68 | } |
62 | 69 | } |
63 | 70 | } |
@@ -169,8 +176,10 @@ private ResponseWrapper _sendRequest(String url, String content, |
169 | 176 | } |
170 | 177 |
|
171 | 178 | } catch (SocketTimeoutException e) { |
172 | | - if (e.getMessage().contains("connect timed out")) { |
| 179 | + if (e.getMessage().contains(KEYWORDS_CONNECT_TIMED_OUT)) { |
173 | 180 | throw e; |
| 181 | + } else if (e.getMessage().contains(KEYWORDS_READ_TIMED_OUT)) { |
| 182 | + throw new SocketTimeoutException(KEYWORDS_READ_TIMED_OUT); |
174 | 183 | } |
175 | 184 | LOG.debug(IO_ERROR_MESSAGE, e); |
176 | 185 | throw new APIConnectionException(IO_ERROR_MESSAGE, e); |
|
0 commit comments