From d453a5be06633fee5e2303495297a4276a155614 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Thu, 5 Sep 2019 15:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=90=BA=E5=B8=A6?= =?UTF-8?q?=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solid/SolidCollectConstants.java | 18 +++++++ .../messagecollect/solid/SolidCollector.java | 47 +++++++++++++++---- 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java new file mode 100644 index 0000000000..452da9ecc5 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollectConstants.java @@ -0,0 +1,18 @@ +package com.fr.design.mainframe.messagecollect.solid; + +/** + * Created by alex sung on 2019/9/5. + */ +public class SolidCollectConstants { + private SolidCollectConstants(){} + + /** + * 客户端请求subject + */ + public static final String REQUEST_SUBJECT = "solid"; + + /** + * 客户端请求超时鉴权时间,默认1h失效 + */ + public static final long TIME_OUT = 60 * 60 * 1000; +} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java index eb5c05912c..eaaa532311 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/solid/SolidCollector.java @@ -2,14 +2,21 @@ package com.fr.design.mainframe.messagecollect.solid; import com.fr.general.CloudCenter; import com.fr.general.http.HttpToolbox; +import com.fr.json.JSON; +import com.fr.json.JSONFactory; import com.fr.log.FineLoggerFactory; +import com.fr.security.JwtUtils; import com.fr.stable.CommonUtils; import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; +import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.REQUEST_SUBJECT; +import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.TIME_OUT; + /** * 设计器固化信息回传类 * Created by alex sung on 2019/8/22. @@ -19,6 +26,7 @@ import java.util.Map; public class SolidCollector { private static final String CONTENT_URL = "/v10/collect/solid"; private static final String DELETE_URL = "/v10/collect/solid/delete"; + private static final String UNLOCK_URL = "/v10/collect/solid/unlock"; private static final String ATTR_CIPHER_TEXT = "cipherText"; private static final String ATTR_SIGNATURE = "signature"; private static final String SOLID_UPLOAD_URL = CloudCenter.getInstance().acquireUrlByKind("design.solid"); @@ -40,19 +48,32 @@ public class SolidCollector { * 回传文件给云中心,并删除服务端本地文件 */ public void sendToCloudCenterAndDeleteFile() { + if (WorkContext.getCurrent().isLocal()) { + return; + } try { String content = requestContent(); - if(StringUtils.isNotEmpty(content)){ - Map params = new HashMap<>(); - params.put(ATTR_CIPHER_TEXT, requestContent()); - params.put(ATTR_SIGNATURE, String.valueOf(CommonUtils.signature())); - HttpToolbox.post(SOLID_UPLOAD_URL, params); + if (StringUtils.isNotEmpty(content)) { + String cipherText = JSONFactory.createJSON(JSON.OBJECT).optString("data"); + if(StringUtils.isNotEmpty(cipherText)){ + Map params = new HashMap<>(); + params.put(ATTR_CIPHER_TEXT, cipherText); + params.put(ATTR_SIGNATURE, String.valueOf(CommonUtils.signature())); + HttpToolbox.post(SOLID_UPLOAD_URL, params); - String deleteUrl = WorkContext.getCurrent().getPath() + DELETE_URL; - HttpToolbox.post(deleteUrl, new HashMap()); + String deleteUrl = WorkContext.getCurrent().getPath() + DELETE_URL; + HttpToolbox.post(deleteUrl, getParams()); + } } } catch (Exception e) { FineLoggerFactory.getLogger().info(e.getMessage(), e); + } finally { + String unlockUrl = WorkContext.getCurrent().getPath() + UNLOCK_URL; + try { + HttpToolbox.post(unlockUrl, getParams()); + } catch (IOException e) { + FineLoggerFactory.getLogger().warn(e.getMessage(), e); + } } } @@ -60,7 +81,15 @@ public class SolidCollector { * 获取服务端固化文件内容 * @return 回传内容 */ - public String requestContent() throws Exception{ - return HttpToolbox.get(WorkContext.getCurrent().getPath() + CONTENT_URL); + public String requestContent() throws Exception { + Map params = new HashMap(); + params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT)); + return HttpToolbox.get(WorkContext.getCurrent().getPath() + CONTENT_URL, params); + } + + private Map getParams() { + Map params = new HashMap(); + params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT)); + return params; } }