taobao TOP接口的重复机制

TOP接口一共会重复三次
对HttpURLConnection进行了封装

public <T extends TaobaoResponse> T execute(TaobaoRequest<T> request, String session) throws ApiException {
		T rsp = null;
		ApiException exp = null;

		for (int i = 0; i <= maxRetryCount; i++) {
			if (i > 0) {
				if ((rsp != null && ((rsp.getSubCode() != null && rsp.getSubCode().startsWith("isp."))
						|| (retryErrorCodes != null && retryErrorCodes.contains(rsp.getSubCode())))) || exp != null) {
					sleepWithoutInterrupt(retryWaitTime);
					log.warn(buildRetryLog(request.getApiMethodName(), request.getTextParams(), i));
				} else {
					break;
				}
			}

			try {
				rsp = super.execute(request, session);
				if (rsp.isSuccess()) {
					return rsp;
				} else {
					if (i == maxRetryCount && throwIfOverMaxRetry) {
						throw RETRY_FAIL;
					}
				}
			} catch (ApiException e) {
				if (exp == null) {
					exp = e;
				}
			}
		}

		if (exp != null) {
			throw exp;
		} else {
			return rsp;
		}
	}

你可能感兴趣的:(taobao)