From 564f527587fab9d896bf1e4a8066fe47919d4937 Mon Sep 17 00:00:00 2001 From: Starryi Date: Tue, 28 Dec 2021 10:43:00 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-64738=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=BB=84=E4=BB=B6=E5=BA=93=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E8=A7=81=E7=BB=84=E4=BB=B6=E5=BA=94=E5=8E=BB=E9=87=8D=E4=B8=94?= =?UTF-8?q?=E4=BB=85=E6=98=BE=E7=A4=BA=E5=85=BC=E5=AE=B9=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=99=A8=E7=9A=84=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 获取组件包中子组件json数据接口添加当前设计器版本参数 2. 下载组件包的接口添加当前设计器版本参数 【改动思路】 同上 --- .../mainframe/share/util/DownloadUtils.java | 43 +++++++++++++------ .../mainframe/share/util/OnlineShopUtils.java | 5 ++- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index 020c03bff..a814dfa0a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java @@ -37,6 +37,9 @@ import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.interfaces.RSAPublicKey; import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** * created by Harrison on 2020/05/27 @@ -68,9 +71,9 @@ public class DownloadUtils { @NotNull public static String download(String id, String fileName, com.fr.design.extra.Process process) throws Exception { - CloseableHttpResponse fileRes = getHttpResponse(getReusesUrl(), id); + CloseableHttpResponse fileRes = postDownloadHttpResponse(getReusesUrl(), id); if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { - fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue()); + fileRes = getDownloadHttpResponse(fileRes.getHeaders("Location")[0].getValue()); } if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_SHARE); @@ -106,9 +109,11 @@ public class DownloadUtils { public static String downloadPackage(String id, String fileName, CancelCheck cancelCheck) throws Exception { - CloseableHttpResponse fileRes = getHttpResponse(getPackageReusesUrl(), id); + Map params = new HashMap<>(); + params.put("designerVersion", ProductConstants.RELEASE_VERSION); + CloseableHttpResponse fileRes = postDownloadHttpResponse(getPackageReusesUrl(), id, params); if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { - fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue()); + fileRes = getDownloadHttpResponse(fileRes.getHeaders("Location")[0].getValue()); } String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_PACKAGE_SHARE); String filePath; @@ -145,9 +150,9 @@ public class DownloadUtils { public static FormTheme downloadThemeFile(String themePath) { try { - CloseableHttpResponse fileRes = getHttpResponse(themePath); + CloseableHttpResponse fileRes = getDownloadHttpResponse(themePath); if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { - fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue()); + fileRes = getDownloadHttpResponse(fileRes.getHeaders("Location")[0].getValue()); } if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = fileRes.getEntity(); @@ -177,21 +182,33 @@ public class DownloadUtils { return null; } - private static CloseableHttpResponse getHttpResponse(String url, String id) throws Exception { + private static CloseableHttpResponse postDownloadHttpResponse(String url, String id) throws Exception { + return postDownloadHttpResponse(url, id, new HashMap<>()); + } + + private static CloseableHttpResponse postDownloadHttpResponse(String url, String id, Map params) throws Exception { //先登录一下。不然可能失败 CloseableHttpClient client = createClient(); FineLoggerFactory.getLogger().info("login fr-market"); FineLoggerFactory.getLogger().info("start download widget {}", id); - HttpUriRequest file = RequestBuilder.post() + RequestBuilder builder = RequestBuilder.post() .setHeader("User-Agent", "Mozilla/5.0") - .setUri(url).addParameter("id", encrypt(id)).addParameter("userId", - String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())) - .build(); - return client.execute(file); + .setUri(url) + .addParameter("id", encrypt(id)) + .addParameter("userId", String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())); + + if (params != null) { + Set keys = params.keySet(); + for (String key: keys) { + builder.addParameter(key, params.get(key)); + } + } + + return client.execute(builder.build()); } - private static CloseableHttpResponse getHttpResponse(String url) throws Exception { + private static CloseableHttpResponse getDownloadHttpResponse(String url) throws Exception { //先登录一下。不然可能失败 CloseableHttpClient client = createClient(); HttpUriRequest file = RequestBuilder.get() diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/OnlineShopUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/OnlineShopUtils.java index c42f06946..7341d7cbb 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/OnlineShopUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/OnlineShopUtils.java @@ -14,6 +14,7 @@ import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; +import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -251,7 +252,7 @@ public class OnlineShopUtils { } public static OnlineShareWidget[] getPackageWidgets(OnlineShareWidget widgetPackage) { - String plistUrl = getPackageChildrenPath() + widgetPackage.getId(); + String plistUrl = getPackageChildrenPath() + widgetPackage.getId() + "?designerVersion="+ ProductConstants.RELEASE_VERSION; OnlineShareWidget[] widgets = getOnlineShareWidgets(plistUrl); for (OnlineShareWidget widget : widgets) { widget.setParentPackage(widgetPackage); @@ -287,7 +288,7 @@ public class OnlineShopUtils { onlineShareWidgets.add(widget); } } - return onlineShareWidgets.toArray(new OnlineShareWidget[onlineShareWidgets.size()]); + return onlineShareWidgets.toArray(new OnlineShareWidget[0]); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); }