Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions EasyExcel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.netease.lowcode.extensions</groupId>
<artifactId>EasyExcel</artifactId>
<version>2.3.0</version>
<version>2.3.1</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -118,7 +118,7 @@
<version>1.4.3</version>
<configuration>
<jarWithDependencies>false</jarWithDependencies>
<rewriteVersion>false</rewriteVersion>
<!-- <rewriteVersion>true</rewriteVersion>-->
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ private static String getFileUrl(String url) {
int index = url.indexOf("/upload/");
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
int port = request.getLocalPort();

if (port == -1) {
return url;
}
if (index >= 0) {
url = "http://localhost:" + port + "/upload/" + url.substring(index + "/upload/".length());
}
Expand Down Expand Up @@ -211,6 +213,7 @@ public static List<List<String>> readHeaderRows(InputStream inputStream,
try {
EasyExcel.read(inputStream, new AnalysisEventListener<Object>() {
private int currentRow = -1;

@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
if (currentRow < headerRowCount) {
Expand All @@ -221,9 +224,11 @@ public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context)
throw new ExcelAnalysisException("表头读取完成");
}
}

@Override
public void invoke(Object data, AnalysisContext context) {
}

@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
Expand Down
2 changes: 1 addition & 1 deletion freemarker-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.netease.lowcode</groupId>
<artifactId>freemarker-tool</artifactId>
<!-- We currently do not support snapshots. Please use a testing version number like 0.x.x, e.g. 0.1.12 -->
<version>1.2.4</version>
<version>1.2.5</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Objects;

public class FileUtil {

private static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
private static final Logger logger = LoggerFactory.getLogger("LCAP_CUSTOMIZE_LOGGER");

public static InputStream getFileInputStream(String urlStr) throws IOException {
URL url = new URL(getTrueUrl(urlStr));
Expand All @@ -26,6 +30,7 @@ public static InputStream getFileInputStream(String urlStr) throws IOException {
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36");
return url.openStream();
}

// 新增方法:检测 URL 是否已经编码
private static boolean isUrlEncoded(String url) {
try {
Expand All @@ -35,6 +40,7 @@ private static boolean isUrlEncoded(String url) {
return false;
}
}

public static String getTrueUrl(String urlStr) throws UnsupportedEncodingException {
URI uri = null;
try {
Expand All @@ -56,19 +62,30 @@ public static String getTrueUrl(String urlStr) throws UnsupportedEncodingExcepti
String fileNameEncoded = java.net.URLEncoder.encode(fileName, "UTF-8");
urlStr = urlStr.replace(fileName, fileNameEncoded);
}
if (!urlStr.startsWith("http") && urlStr.startsWith("/upload")) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
int port = request.getLocalPort();
return "http://127.0.0.1:" + port + urlStr;
try {
if (!urlStr.startsWith("http") && urlStr.startsWith("/upload")) {
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
int port = request.getLocalPort();
return "http://127.0.0.1:" + port + urlStr;
}
} catch (Exception e) {
logger.error("urlStr转本地失败", e);
}
return urlStr;
}

public static UploadResponseDTO uploadStream(InputStream inputStream, String fileName) throws IOException {
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
int port = httpServletRequest.getLocalPort();

int port;
try {
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
port = httpServletRequest.getLocalPort();
} catch (Exception e) {
logger.error("获取本地port失败,默认获取8080", e);
//兜底方案
port = 8080;
}
String uploadUrl = "http://127.0.0.1:" + port + "/gateway/lowcode/api/v1/app/upload";

OkHttpClient client = new OkHttpClient();

byte[] fileBytes;
Expand Down Expand Up @@ -97,7 +114,7 @@ public static UploadResponseDTO uploadStream(InputStream inputStream, String fil
if (response.isSuccessful()) {
return JsonUtil.fromJson(response.body().string(), UploadResponseDTO.class);
}
logger.error(String.format("文件上传失败,%s",response));
throw new RuntimeException(String.format("文件上传失败,%s",response));
logger.error(String.format("文件上传失败,%s", response));
throw new RuntimeException(String.format("文件上传失败,%s", response));
}
}
2 changes: 1 addition & 1 deletion httpclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<artifactId>httpclient</artifactId>
<name>httpclient</name>
<description>httpclient</description>
<version>1.3.0</version>
<version>1.4.1</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,44 @@ public ExchangeResponseDto exchangeV4(@Required String url, @Required String htt
}
}

/**
* http/https调用(非form使用,异常时返回http错误码)
*
* @param url
* @param httpMethod
* @param header
* @param body
* @return
* @throws URISyntaxException
*/
@NaslLogic
@Retryable(value = {Exception.class}, maxAttempts = 3, backoff = @Backoff(delay = 1000L))
public ExchangeResponseDto exchangeCrtV4(@Required String url, @Required String httpMethod, @Required Map<String, String> header,
@Required String body, @Required Boolean isIgnoreCrt) throws TransferCommonException {
try {
if (isIgnoreCrt == null) {
isIgnoreCrt = false;
}
if (isIgnoreCrt) {
SSLUtil.turnOffCertificateValidation();
}
RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner();
requestParam.setBody(body);
//填充requestParam参数
requestParam.setUrl(url);
requestParam.setHttpMethod(httpMethod);
requestParam.setHeader(header);
ResponseEntity<String> exchange = httpClientService.exchangeInner(requestParam, restTemplate, String.class);
return convertToExchangeResponseDto(exchange);
} catch (HttpClientErrorException e) {
logger.error("", e);
throw new TransferCommonException(e.getStatusCode().value(), e.getResponseBodyAsString());
} catch (Exception e) {
logger.error("", e);
throw new TransferCommonException(e.getMessage(), e);
}
}

/**
* 下载文件并上传到nos(默认fileUrl是get请求,默认格式xlsx)
*
Expand Down Expand Up @@ -266,6 +304,12 @@ public String downloadFileUploadNosExtendHttpMethod(@Required String fileUrl, St
*/
@NaslLogic
public String uploadNosExchange(String fileUrl, String requestUrl, RequestParam requestParam) throws TransferCommonException {
if (requestParam.getIsIgnoreCrt() == null) {
requestParam.setIsIgnoreCrt(false);
}
if (requestParam.getIsIgnoreCrt()) {
SSLUtil.turnOffCertificateValidation();
}
URL url = null;
try {
url = new URL(requestUrl);
Expand Down Expand Up @@ -313,6 +357,12 @@ public String uploadNosExchangeCommonFileType(String fileUrl, String fileName, R
public String uploadNosExchangeCommon(UploadFileParam uploadFileParam, String fileName, RequestParam requestParam) throws TransferCommonException {
File file = null;
try {
if (requestParam.getIsIgnoreCrt() == null) {
requestParam.setIsIgnoreCrt(false);
}
if (requestParam.getIsIgnoreCrt()) {
SSLUtil.turnOffCertificateValidation();
}
RequestParamAllBodyTypeInner requestParamGetFile = new RequestParamAllBodyTypeInner();
requestParamGetFile.setUrl(uploadFileParam.getFileUrl());
//文件下载一般是get,默认get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ExtHttpFilterConfig {
private volatile String secret;

@Bean
public FilterRegistrationBean<Filter> expandTransferLogicAuthFilterRegistration() {
public FilterRegistrationBean<Filter> httpClientExpandTransferLogicAuthFilterRegistration() {
FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
ExtHttpLogicAuthFilter extHttpLogicAuthFilter = new ExtHttpLogicAuthFilter();
extHttpLogicAuthFilter.setExpandLogicAuthFlag(expandLogicAuthFlag);
Expand Down
Loading