Skip to content

Commit

Permalink
Merge pull request #131 from hesy007/master
Browse files Browse the repository at this point in the history
Update RestfulMgrImpl.java
  • Loading branch information
knightliao committed Aug 31, 2016
2 parents 596306b + a0af2fc commit b6e3ced
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RestfulMgrImpl(RetryStrategy retryStrategy) {
*/
public <T> T getJsonData(Class<T> clazz, RemoteUrl remoteUrl, int retryTimes, int retrySleepSeconds)
throws Exception {

Exception ex = null;
for (URL url : remoteUrl.getUrls()) {

// 可重试的下载
Expand All @@ -63,7 +63,7 @@ public <T> T getJsonData(Class<T> clazz, RemoteUrl remoteUrl, int retryTimes, in
return t;

} catch (Exception e) {

ex = e;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
Expand All @@ -72,7 +72,7 @@ public <T> T getJsonData(Class<T> clazz, RemoteUrl remoteUrl, int retryTimes, in
}
}

throw new Exception("cannot get: " + remoteUrl);
throw new Exception("cannot get: " + remoteUrl, ex);
}

/**
Expand Down Expand Up @@ -129,8 +129,8 @@ public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String lo
//
// 判断是否下载失败
//

if (!localFile.exists()) {
if (localFile == null || !localFile.exists()) {
throw new Exception("target file cannot be found! " + fileName);
}

Expand All @@ -139,12 +139,10 @@ public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String lo
//

// 返回相对路径
if (localFileDir != null) {
String relativePathString = OsUtil.getRelativePath(localFile, new File(localFileDir));
if (relativePathString != null) {
if (new File(relativePathString).isFile()) {
return relativePathString;
}
String relativePathString = OsUtil.getRelativePath(localFile, new File(localFileDir));
if (relativePathString != null) {
if (new File(relativePathString).isFile()) {
return relativePathString;
}
}

Expand Down Expand Up @@ -218,7 +216,7 @@ private File transfer2SpecifyDir(File srcFile, String copy2TargetDirPath, String
*/
private Object retry4ConfDownload(RemoteUrl remoteUrl, File localTmpFile, int retryTimes, int sleepSeconds)
throws Exception {

Exception ex = null;
for (URL url : remoteUrl.getUrls()) {

// 可重试的下载
Expand All @@ -229,7 +227,7 @@ private Object retry4ConfDownload(RemoteUrl remoteUrl, File localTmpFile, int re
return retryStrategy.retry(unreliableImpl, retryTimes, sleepSeconds);

} catch (Exception e) {

ex = e;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
Expand All @@ -238,7 +236,7 @@ private Object retry4ConfDownload(RemoteUrl remoteUrl, File localTmpFile, int re
}
}

throw new Exception("download failed.");
throw new Exception("download failed.", ex);
}

}

0 comments on commit b6e3ced

Please sign in to comment.