|
@@ -6,6 +6,7 @@ import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fjhx.config.exception.EmailEngineException;
|
|
|
+import com.fjhx.config.exception.ServiceException;
|
|
|
import com.fjhx.vo.*;
|
|
|
import com.sun.istack.internal.NotNull;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -46,12 +47,11 @@ public class EmailEngineUtil {
|
|
|
body.read(bytes);
|
|
|
String result = new String(bytes);
|
|
|
|
|
|
- HttpStatus.Series series = response.getStatusCode().series();
|
|
|
- if (HttpStatus.Series.CLIENT_ERROR.equals(series)) {
|
|
|
- throw new RuntimeException(result);
|
|
|
+ if (HttpStatus.Series.SERVER_ERROR.equals(response.getStatusCode().series())) {
|
|
|
+ throw new EmailEngineException(result);
|
|
|
}
|
|
|
|
|
|
- throw new EmailEngineException(result);
|
|
|
+ throw new ServiceException(result);
|
|
|
}
|
|
|
|
|
|
});
|
|
@@ -93,7 +93,7 @@ public class EmailEngineUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查看文件夹的所有邮件
|
|
|
+ * 查看文件夹的邮件
|
|
|
*/
|
|
|
public static MessageVo getMessageList(String email, String path, int page, int size) {
|
|
|
String url = "/v1/account/" + email + "/messages?path=" + path + "&page=" + page + "&pageSize=" + size + "&documentStore=true";
|
|
@@ -111,21 +111,15 @@ public class EmailEngineUtil {
|
|
|
/**
|
|
|
* 下载附件
|
|
|
*/
|
|
|
- public static boolean downloadAttachment(String email, String attachmentId, String fileName) {
|
|
|
- try {
|
|
|
- File file = new File(attachmentPath + email);
|
|
|
- if (!file.exists()) {
|
|
|
- boolean mkdir = file.mkdir();
|
|
|
- Assert.isTrue(mkdir, "创建文件夹失败");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- FileOutputStream fileOutputStream = new FileOutputStream(attachmentPath + fileName);
|
|
|
- download("v1/account/" + email + "/attachment/" + attachmentId, fileOutputStream);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new EmailEngineException("下载附件失败");
|
|
|
+ public static void downloadAttachment(String email, String attachmentId, String fileName) throws FileNotFoundException {
|
|
|
+ File file = new File(attachmentPath + email);
|
|
|
+ if (!file.exists()) {
|
|
|
+ boolean mkdir = file.mkdirs();
|
|
|
+ Assert.isTrue(mkdir, "创建文件夹失败");
|
|
|
}
|
|
|
+
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(attachmentPath + fileName);
|
|
|
+ download("v1/account/" + email + "/attachment/" + attachmentId, fileOutputStream);
|
|
|
}
|
|
|
|
|
|
public static void submit(SubmitVo submitVo) {
|
|
@@ -210,18 +204,15 @@ public class EmailEngineUtil {
|
|
|
}
|
|
|
|
|
|
public static <T> T get(String url, Class<T> cls) {
|
|
|
- return RetryUtil.execute(() -> restTemplate.getForObject(urlPrefix + url, cls), 5, 5000L);
|
|
|
+ return restTemplate.getForObject(urlPrefix + url, cls);
|
|
|
}
|
|
|
|
|
|
public static <T> T post(String url, Object paramObj, Class<T> cls) {
|
|
|
- return RetryUtil.execute(() -> restTemplate.postForObject(urlPrefix + url, paramObj, cls), 5, 3000L);
|
|
|
+ return restTemplate.postForObject(urlPrefix + url, paramObj, cls);
|
|
|
}
|
|
|
|
|
|
public static void delete(String url, Map<String, Object> map) {
|
|
|
- RetryUtil.execute(() -> {
|
|
|
- restTemplate.delete(urlPrefix + url, map);
|
|
|
- return null;
|
|
|
- }, 5, 3000L);
|
|
|
+ restTemplate.delete(urlPrefix + url, map);
|
|
|
}
|
|
|
|
|
|
}
|