Commit 986f5622 authored by kl's avatar kl Committed by kl

引入galimatias,解决不规范文件名导致文件下载异常

parent 11d0441e
...@@ -201,6 +201,12 @@ ...@@ -201,6 +201,12 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath> <systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath>
</dependency> </dependency>
<!-- url 规范化 -->
<dependency>
<groupId>io.mola.galimatias</groupId>
<artifactId>galimatias</artifactId>
<version>0.2.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>
......
...@@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants; ...@@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.model.FileType; import cn.keking.model.FileType;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import io.mola.galimatias.GalimatiasParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -81,7 +82,6 @@ public class DownloadUtils { ...@@ -81,7 +82,6 @@ public class DownloadUtils {
public static byte[] getBytesFromUrl(String urlStr) throws IOException { public static byte[] getBytesFromUrl(String urlStr) throws IOException {
InputStream is = getInputStreamFromUrl(urlStr); InputStream is = getInputStreamFromUrl(urlStr);
if (is == null) { if (is == null) {
// urlStr = URLUtil.normalize(urlStr, true, true);
is = getInputStreamFromUrl(urlStr); is = getInputStreamFromUrl(urlStr);
if (is == null) { if (is == null) {
logger.error("文件下载异常:url:{}", urlStr); logger.error("文件下载异常:url:{}", urlStr);
...@@ -98,13 +98,14 @@ public class DownloadUtils { ...@@ -98,13 +98,14 @@ public class DownloadUtils {
private static InputStream getInputStreamFromUrl(String urlStr) { private static InputStream getInputStreamFromUrl(String urlStr) {
try { try {
URL url = new URL(urlStr);
URL url = io.mola.galimatias.URL.parse(urlStr).toJavaURL();
URLConnection connection = url.openConnection(); URLConnection connection = url.openConnection();
if (connection instanceof HttpURLConnection) { if (connection instanceof HttpURLConnection) {
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
} }
return connection.getInputStream(); return connection.getInputStream();
} catch (IOException e) { } catch (IOException | GalimatiasParseException e) {
logger.warn("连接url异常:url:{}", urlStr); logger.warn("连接url异常:url:{}", urlStr);
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment