优化网络请求和文件服务的URL处理
统一网络请求和文件服务中的URL处理方式,使用URI转URL的方法确保URL正确构建。优化了HttpClientUtil、HttpUtils和ImageUtils等类中URL的创建方式,通过URI处理避免潜在的格式错误。在MinioFileService中移除了未使用的Md5Utils依赖。
This commit is contained in:
parent
643e22dc24
commit
a9d0130c35
@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Arrays;
|
||||
@ -70,7 +71,8 @@ public class ImageUtils
|
||||
if (url.startsWith("http"))
|
||||
{
|
||||
// 网络地址
|
||||
URL urlObj = new URL(url);
|
||||
URI uriObj = new URI(url);
|
||||
URL urlObj = uriObj.toURL();
|
||||
URLConnection urlConnection = urlObj.openConnection();
|
||||
urlConnection.setConnectTimeout(30 * 1000);
|
||||
urlConnection.setReadTimeout(60 * 1000);
|
||||
|
@ -5,7 +5,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -251,7 +250,7 @@ public class HttpClientUtil {
|
||||
try {
|
||||
// 创建默认的httpClient实例.
|
||||
PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader
|
||||
.load(new URL(httpGet.getURI().toString()));
|
||||
.load(httpGet.getURI().toURL());
|
||||
DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
|
||||
httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();
|
||||
httpGet.setConfig(requestConfig);
|
||||
|
@ -7,6 +7,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -115,7 +116,8 @@ public class HttpUtils
|
||||
{
|
||||
String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
|
||||
log.info("sendGet - {}", urlNameString);
|
||||
URL realUrl = new URL(urlNameString);
|
||||
URI uri = new URI(urlNameString);
|
||||
URL realUrl = uri.toURL();
|
||||
URLConnection connection = realUrl.openConnection();
|
||||
connection.setRequestProperty("accept", "*/*");
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
@ -177,7 +179,8 @@ public class HttpUtils
|
||||
try
|
||||
{
|
||||
log.info("sendPost - {}", url);
|
||||
URL realUrl = new URL(url);
|
||||
URI uri = new URI(url);
|
||||
URL realUrl = uri.toURL();
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
@ -243,7 +246,8 @@ public class HttpUtils
|
||||
log.info("sendSSLPost - {}", urlNameString);
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
|
||||
URL console = new URL(urlNameString);
|
||||
URI uri = new URI(urlNameString);
|
||||
URL console = uri.toURL();
|
||||
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.ruoyi.common.utils.file.FileOperateUtils;
|
||||
import com.ruoyi.common.utils.sign.Md5Utils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
Loading…
Reference in New Issue
Block a user