|
|
@ -37,6 +37,9 @@ import java.nio.charset.StandardCharsets; |
|
|
|
import java.security.KeyFactory; |
|
|
|
import java.security.KeyFactory; |
|
|
|
import java.security.interfaces.RSAPublicKey; |
|
|
|
import java.security.interfaces.RSAPublicKey; |
|
|
|
import java.security.spec.X509EncodedKeySpec; |
|
|
|
import java.security.spec.X509EncodedKeySpec; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* created by Harrison on 2020/05/27 |
|
|
|
* created by Harrison on 2020/05/27 |
|
|
@ -68,9 +71,9 @@ public class DownloadUtils { |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
@NotNull |
|
|
|
public static String download(String id, String fileName, com.fr.design.extra.Process<Double> process) throws Exception { |
|
|
|
public static String download(String id, String fileName, com.fr.design.extra.Process<Double> process) throws Exception { |
|
|
|
CloseableHttpResponse fileRes = getHttpResponse(getReusesUrl(), id); |
|
|
|
CloseableHttpResponse fileRes = postDownloadHttpResponse(getReusesUrl(), id); |
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { |
|
|
|
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) { |
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
|
|
|
String realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_SHARE); |
|
|
|
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 { |
|
|
|
public static String downloadPackage(String id, String fileName, CancelCheck cancelCheck) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpResponse fileRes = getHttpResponse(getPackageReusesUrl(), id); |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
|
|
params.put("designerVersion", ProductConstants.RELEASE_VERSION); |
|
|
|
|
|
|
|
CloseableHttpResponse fileRes = postDownloadHttpResponse(getPackageReusesUrl(), id, params); |
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { |
|
|
|
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 realPath = StableUtils.pathJoin(ProductConstants.getEnvHome(), ShareComponentConstants.PLUGIN_CACHE, ShareComponentConstants.DOWNLOAD_PACKAGE_SHARE); |
|
|
|
String filePath; |
|
|
|
String filePath; |
|
|
@ -145,9 +150,9 @@ public class DownloadUtils { |
|
|
|
|
|
|
|
|
|
|
|
public static FormTheme downloadThemeFile(String themePath) { |
|
|
|
public static FormTheme downloadThemeFile(String themePath) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
CloseableHttpResponse fileRes = getHttpResponse(themePath); |
|
|
|
CloseableHttpResponse fileRes = getDownloadHttpResponse(themePath); |
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { |
|
|
|
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) { |
|
|
|
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
|
|
|
HttpEntity entity = fileRes.getEntity(); |
|
|
|
HttpEntity entity = fileRes.getEntity(); |
|
|
@ -177,21 +182,33 @@ public class DownloadUtils { |
|
|
|
return null; |
|
|
|
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<String, String> params) throws Exception { |
|
|
|
//先登录一下。不然可能失败
|
|
|
|
//先登录一下。不然可能失败
|
|
|
|
CloseableHttpClient client = createClient(); |
|
|
|
CloseableHttpClient client = createClient(); |
|
|
|
FineLoggerFactory.getLogger().info("login fr-market"); |
|
|
|
FineLoggerFactory.getLogger().info("login fr-market"); |
|
|
|
FineLoggerFactory.getLogger().info("start download widget {}", id); |
|
|
|
FineLoggerFactory.getLogger().info("start download widget {}", id); |
|
|
|
HttpUriRequest file = RequestBuilder.post() |
|
|
|
RequestBuilder builder = RequestBuilder.post() |
|
|
|
.setHeader("User-Agent", "Mozilla/5.0") |
|
|
|
.setHeader("User-Agent", "Mozilla/5.0") |
|
|
|
.setUri(url).addParameter("id", encrypt(id)).addParameter("userId", |
|
|
|
.setUri(url) |
|
|
|
String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())) |
|
|
|
.addParameter("id", encrypt(id)) |
|
|
|
.build(); |
|
|
|
.addParameter("userId", String.valueOf(DesignerEnvManager.getEnvManager().getDesignerLoginUid())); |
|
|
|
return client.execute(file); |
|
|
|
|
|
|
|
|
|
|
|
if (params != null) { |
|
|
|
|
|
|
|
Set<String> 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(); |
|
|
|
CloseableHttpClient client = createClient(); |
|
|
|
HttpUriRequest file = RequestBuilder.get() |
|
|
|
HttpUriRequest file = RequestBuilder.get() |
|
|
|