From e51fb4fc9611d1ffc691a3c8ba11a530658d7270 Mon Sep 17 00:00:00 2001
From: "zhouxin5253@163.com" <9a@2gvp!hs3>
Date: Fri, 22 Jan 2021 20:36:17 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../client/TeambitionClient.java | 19 ++++++++++---------
.../store/TeambitionClientService.java | 5 +++--
.../store/TeambitionFileSystemStore.java | 3 ++-
.../zxbu/webdavteambition/util/JsonUtil.java | 13 ++++++-------
5 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/pom.xml b/pom.xml
index 89f750c..5db825a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
com.github.zxbu
webdav-teambition
- 0.0.2-SNAPSHOT
+ 1.0.0
webdav-teambition
Demo project for Spring Boot
diff --git a/src/main/java/com/github/zxbu/webdavteambition/client/TeambitionClient.java b/src/main/java/com/github/zxbu/webdavteambition/client/TeambitionClient.java
index dd8639a..e70c0c5 100644
--- a/src/main/java/com/github/zxbu/webdavteambition/client/TeambitionClient.java
+++ b/src/main/java/com/github/zxbu/webdavteambition/client/TeambitionClient.java
@@ -2,6 +2,7 @@ package com.github.zxbu.webdavteambition.client;
import com.github.zxbu.webdavteambition.config.TeambitionProperties;
import com.github.zxbu.webdavteambition.util.JsonUtil;
+import net.sf.webdav.exceptions.WebdavException;
import okhttp3.*;
import okio.BufferedSink;
import org.slf4j.Logger;
@@ -69,7 +70,7 @@ public class TeambitionClient {
response = okHttpClient.newCall(request).execute();
return response.body().byteStream();
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -81,10 +82,10 @@ public class TeambitionClient {
LOGGER.info("post {}, code {}", url, response.code());
if (!response.isSuccessful()) {
LOGGER.error("请求失败,url={}, code={}, body={}", url, response.code(), response.body().string());
- throw new RuntimeException("请求失败:" + url);
+ throw new WebdavException("请求失败:" + url);
}
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -96,11 +97,11 @@ public class TeambitionClient {
LOGGER.info("post {}, code {}", url, response.code());
if (!response.isSuccessful()) {
LOGGER.error("请求失败,url={}, code={}, body={}", url, response.code(), response.body().string());
- throw new RuntimeException("请求失败:" + url);
+ throw new WebdavException("请求失败:" + url);
}
return toString(response.body());
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -112,11 +113,11 @@ public class TeambitionClient {
LOGGER.info("put {}, code {}", url, response.code());
if (!response.isSuccessful()) {
LOGGER.error("请求失败,url={}, code={}, body={}", url, response.code(), response.body().string());
- throw new RuntimeException("请求失败:" + url);
+ throw new WebdavException("请求失败:" + url);
}
return toString(response.body());
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -129,13 +130,13 @@ public class TeambitionClient {
try (Response response = okHttpClient.newCall(request).execute()){
LOGGER.info("get {}, code {}", urlBuilder.build(), response.code());
if (!response.isSuccessful()) {
- throw new RuntimeException("请求失败:" + urlBuilder.build().toString());
+ throw new WebdavException("请求失败:" + urlBuilder.build().toString());
}
return toString(response.body());
}
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java
index ae9830e..6c3baed 100644
--- a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java
+++ b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java
@@ -9,6 +9,7 @@ import com.github.zxbu.webdavteambition.model.result.ListResult;
import com.github.zxbu.webdavteambition.model.result.TFile;
import com.github.zxbu.webdavteambition.model.result.UploadPreResult;
import com.github.zxbu.webdavteambition.util.JsonUtil;
+import net.sf.webdav.exceptions.WebdavException;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,7 +84,7 @@ public class TeambitionClientService {
});
return stringMap;
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -129,7 +130,7 @@ public class TeambitionClientService {
LOGGER.info("文件正在上传。文件名:{},当前进度:{}/{}", path, (i+1), uploadUrl.size());
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java
index 6a0d4e5..5d6049b 100644
--- a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java
+++ b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java
@@ -5,6 +5,7 @@ import com.github.zxbu.webdavteambition.model.result.TFile;
import net.sf.webdav.ITransaction;
import net.sf.webdav.IWebdavStore;
import net.sf.webdav.StoredObject;
+import net.sf.webdav.exceptions.WebdavException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
@@ -140,7 +141,7 @@ public class TeambitionFileSystemStore implements IWebdavStore {
teambitionClientService.move(sourcePath, destinationPathInfo.getParentPath());
} else {
if (!destinationPathInfo.getParentPath().equals(sourcePathInfo.getParentPath())) {
- throw new RuntimeException("不支持目录和名字同时修改");
+ throw new WebdavException("不支持目录和名字同时修改");
}
// 名字不同,说明是修改名字。不考虑目录和名字同时修改的情况
teambitionClientService.rename(sourcePath, destinationPathInfo.getName());
diff --git a/src/main/java/com/github/zxbu/webdavteambition/util/JsonUtil.java b/src/main/java/com/github/zxbu/webdavteambition/util/JsonUtil.java
index da16b0d..860d578 100644
--- a/src/main/java/com/github/zxbu/webdavteambition/util/JsonUtil.java
+++ b/src/main/java/com/github/zxbu/webdavteambition/util/JsonUtil.java
@@ -1,13 +1,12 @@
package com.github.zxbu.webdavteambition.util;
-import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import net.sf.webdav.exceptions.WebdavException;
import java.io.IOException;
import java.util.ArrayList;
@@ -20,7 +19,7 @@ public class JsonUtil {
try {
return objectMapper.writeValueAsString(o);
} catch (JsonProcessingException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -28,7 +27,7 @@ public class JsonUtil {
try {
return objectMapper.readValue(json, valueTypeRef);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -37,7 +36,7 @@ public class JsonUtil {
try {
return objectMapper.readValue(json, valueType);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -65,7 +64,7 @@ public class JsonUtil {
}
return objectMapper.treeToValue(jsonNode, Object.class);
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}
@@ -115,7 +114,7 @@ public class JsonUtil {
try {
return objectMapper.readTree(responseBody);
} catch (JsonProcessingException e) {
- throw new RuntimeException(e);
+ throw new WebdavException(e);
}
}