mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.text.escape.EscapeUtil;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* HTML工具类
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,7 +27,7 @@ public abstract class HttpBase<T> {
|
||||
/**
|
||||
* 默认的请求编码、URL的encode、decode编码
|
||||
*/
|
||||
protected static final Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
|
||||
protected static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
/**
|
||||
* HTTP/1.0
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.http.ssl.DefaultSSLInfo;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@@ -267,8 +267,8 @@ public class HttpConnection {
|
||||
// Https请求
|
||||
final HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
|
||||
// 验证域
|
||||
httpsConn.setHostnameVerifier(ObjectUtil.defaultIfNull(hostnameVerifier, DefaultSSLInfo.TRUST_ANY_HOSTNAME_VERIFIER));
|
||||
httpsConn.setSSLSocketFactory(ObjectUtil.defaultIfNull(ssf, DefaultSSLInfo.DEFAULT_SSF));
|
||||
httpsConn.setHostnameVerifier(ObjUtil.defaultIfNull(hostnameVerifier, DefaultSSLInfo.TRUST_ANY_HOSTNAME_VERIFIER));
|
||||
httpsConn.setSSLSocketFactory(ObjUtil.defaultIfNull(ssf, DefaultSSLInfo.DEFAULT_SSF));
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* HTTP异常
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@@ -14,8 +14,8 @@ import cn.hutool.core.net.SSLUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.body.BytesBody;
|
||||
import cn.hutool.http.body.FormUrlEncodedBody;
|
||||
import cn.hutool.http.body.MultipartBody;
|
||||
@@ -482,7 +482,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, Object value) {
|
||||
if (StrUtil.isBlank(name) || ObjectUtil.isNull(value)) {
|
||||
if (StrUtil.isBlank(name) || ObjUtil.isNull(value)) {
|
||||
return this; // 忽略非法的form表单项内容;
|
||||
}
|
||||
|
||||
|
@@ -7,9 +7,9 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -439,10 +439,10 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
fileName = StrUtil.subSuf(path, path.lastIndexOf('/') + 1);
|
||||
if (StrUtil.isBlank(fileName)) {
|
||||
// 编码后的路径做为文件名
|
||||
fileName = URLUtil.encodeQuery(path, charset);
|
||||
fileName = URLEncoder.encodeQuery(path, charset);
|
||||
} else {
|
||||
// issue#I4K0FS@Gitee
|
||||
fileName = URLUtil.decode(fileName, charset);
|
||||
fileName = URLEncoder.encodeQuery(fileName, charset);
|
||||
}
|
||||
}
|
||||
return FileUtil.file(targetFileOrDir, fileName);
|
||||
|
@@ -7,13 +7,13 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
import cn.hutool.http.server.SimpleServer;
|
||||
|
||||
@@ -433,7 +433,7 @@ public class HttpUtil {
|
||||
* @return url参数
|
||||
*/
|
||||
public static String toParams(Map<String, ?> paramMap) {
|
||||
return toParams(paramMap, CharsetUtil.CHARSET_UTF_8);
|
||||
return toParams(paramMap, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,13 +560,13 @@ public class HttpUtil {
|
||||
|
||||
// 结尾处理
|
||||
if (null != name) {
|
||||
builder.append(URLUtil.encodeQuery(name, charset)).append('=');
|
||||
builder.append(URLEncoder.encodeQuery(name, charset)).append('=');
|
||||
}
|
||||
if (pos != i) {
|
||||
if (null == name && pos > 0) {
|
||||
builder.append('=');
|
||||
}
|
||||
builder.append(URLUtil.encodeQuery(paramPart.substring(pos, i), charset));
|
||||
builder.append(URLEncoder.encodeQuery(paramPart.substring(pos, i), charset));
|
||||
}
|
||||
|
||||
// 以&结尾则去除之
|
||||
@@ -746,7 +746,7 @@ public class HttpUtil {
|
||||
}
|
||||
|
||||
if (null == charset) {
|
||||
charset = CharsetUtil.CHARSET_UTF_8;
|
||||
charset = CharsetUtil.UTF_8;
|
||||
}
|
||||
String content = new String(contentBytes, charset);
|
||||
if (isGetCharsetFromContent) {
|
||||
@@ -757,9 +757,9 @@ public class HttpUtil {
|
||||
charsetInContent = Charset.forName(charsetInContentStr);
|
||||
} catch (Exception e) {
|
||||
if (StrUtil.containsIgnoreCase(charsetInContentStr, "utf-8") || StrUtil.containsIgnoreCase(charsetInContentStr, "utf8")) {
|
||||
charsetInContent = CharsetUtil.CHARSET_UTF_8;
|
||||
charsetInContent = CharsetUtil.UTF_8;
|
||||
} else if (StrUtil.containsIgnoreCase(charsetInContentStr, "gbk")) {
|
||||
charsetInContent = CharsetUtil.CHARSET_GBK;
|
||||
charsetInContent = CharsetUtil.GBK;
|
||||
}
|
||||
// ignore
|
||||
}
|
||||
@@ -781,7 +781,7 @@ public class HttpUtil {
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public static String getMimeType(String filePath, String defaultValue) {
|
||||
return ObjectUtil.defaultIfNull(getMimeType(filePath), defaultValue);
|
||||
return ObjUtil.defaultIfNull(getMimeType(filePath), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,7 +6,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.resource.MultiResource;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.io.resource.StringResource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.http.body;
|
||||
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.http.cookie;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.http.HttpConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 全局Cookie管理器,只针对Hutool请求有效
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 4.5.15
|
||||
*/
|
||||
@@ -26,19 +26,19 @@ public class GlobalCookieManager {
|
||||
static {
|
||||
cookieManager = new CookieManager(new ThreadLocalCookieStore(), CookiePolicy.ACCEPT_ALL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义{@link CookieManager}
|
||||
*
|
||||
*
|
||||
* @param customCookieManager 自定义的{@link CookieManager}
|
||||
*/
|
||||
public static void setCookieManager(CookieManager customCookieManager) {
|
||||
cookieManager = customCookieManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取全局{@link CookieManager}
|
||||
*
|
||||
*
|
||||
* @return {@link CookieManager}
|
||||
*/
|
||||
public static CookieManager getCookieManager() {
|
||||
@@ -58,7 +58,7 @@ public class GlobalCookieManager {
|
||||
|
||||
/**
|
||||
* 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie
|
||||
*
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void add(HttpConnection conn) {
|
||||
@@ -81,7 +81,7 @@ public class GlobalCookieManager {
|
||||
|
||||
/**
|
||||
* 存储响应的Cookie信息到本地
|
||||
*
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void store(HttpConnection conn) {
|
||||
|
@@ -15,7 +15,7 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
public class HttpServerBase implements Closeable {
|
||||
|
||||
final static Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
|
||||
final static Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
final HttpExchange httpExchange;
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import cn.hutool.core.net.multipart.MultipartFormData;
|
||||
import cn.hutool.core.net.multipart.UploadSetting;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.http.Method;
|
||||
@@ -145,7 +145,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
public String getHeader(String headerKey, Charset charset) {
|
||||
final String header = getHeader(headerKey);
|
||||
if (null != header) {
|
||||
return CharsetUtil.convert(header, CharsetUtil.CHARSET_ISO_8859_1, charset);
|
||||
return CharsetUtil.convert(header, CharsetUtil.ISO_8859_1, charset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ package cn.hutool.http.server;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
@@ -255,7 +255,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return 响应数据流
|
||||
*/
|
||||
public PrintWriter getWriter() {
|
||||
final Charset charset = ObjectUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
final Charset charset = ObjUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
return new PrintWriter(new OutputStreamWriter(getOut(), charset));
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(String data) {
|
||||
final Charset charset = ObjectUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
final Charset charset = ObjUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
return write(StrUtil.bytes(data, charset));
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
if(StrUtil.isBlank(fileName)){
|
||||
fileName = file.getName();
|
||||
}
|
||||
final String contentType = ObjectUtil.defaultIfNull(HttpUtil.getMimeType(fileName), "application/octet-stream");
|
||||
final String contentType = ObjUtil.defaultIfNull(HttpUtil.getMimeType(fileName), "application/octet-stream");
|
||||
BufferedInputStream in = null;
|
||||
try {
|
||||
in = FileUtil.getInputStream(file);
|
||||
@@ -425,11 +425,11 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @since 5.2.7
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in, int length, String contentType, String fileName) {
|
||||
final Charset charset = ObjectUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
final Charset charset = ObjUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
|
||||
if (false == contentType.startsWith("text/")) {
|
||||
// 非文本类型数据直接走下载
|
||||
setHeader(Header.CONTENT_DISPOSITION, StrUtil.format("attachment;filename={}", URLUtil.encode(fileName, charset)));
|
||||
setHeader(Header.CONTENT_DISPOSITION, StrUtil.format("attachment;filename={}", URLEncoder.encodeAll(fileName, charset)));
|
||||
}
|
||||
return write(in, length, contentType);
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.http.server;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.GlobalThreadPool;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.server.action.Action;
|
||||
import cn.hutool.http.server.action.RootAction;
|
||||
import cn.hutool.http.server.filter.HttpFilter;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http.ssl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http.useragent;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* User-Agent解析器
|
||||
|
@@ -3,8 +3,8 @@ package cn.hutool.http.webservice;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.http.HttpBase;
|
||||
import cn.hutool.http.HttpGlobalConfig;
|
||||
@@ -356,7 +356,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(String methodName) {
|
||||
return setMethod(methodName, ObjectUtil.defaultIfNull(this.namespaceURI, XMLConstants.NULL_NS_URI));
|
||||
return setMethod(methodName, ObjUtil.defaultIfNull(this.namespaceURI, XMLConstants.NULL_NS_URI));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package cn.hutool.http.webservice;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* SOAP异常
|
||||
*
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*/
|
||||
public class SoapRuntimeException extends RuntimeException {
|
||||
|
@@ -14,7 +14,7 @@ import cn.hutool.core.util.XmlUtil;
|
||||
|
||||
/**
|
||||
* SOAP相关工具类
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.5.7
|
||||
*/
|
||||
@@ -22,7 +22,7 @@ public class SoapUtil {
|
||||
|
||||
/**
|
||||
* 创建SOAP客户端,默认使用soap1.1版本协议
|
||||
*
|
||||
*
|
||||
* @param url WS的URL地址
|
||||
* @return {@link SoapClient}
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ public class SoapUtil {
|
||||
|
||||
/**
|
||||
* 创建SOAP客户端
|
||||
*
|
||||
*
|
||||
* @param url WS的URL地址
|
||||
* @param protocol 协议,见{@link SoapProtocol}
|
||||
* @return {@link SoapClient}
|
||||
@@ -43,7 +43,7 @@ public class SoapUtil {
|
||||
|
||||
/**
|
||||
* 创建SOAP客户端
|
||||
*
|
||||
*
|
||||
* @param url WS的URL地址
|
||||
* @param protocol 协议,见{@link SoapProtocol}
|
||||
* @param namespaceURI 方法上的命名空间URI
|
||||
@@ -62,7 +62,7 @@ public class SoapUtil {
|
||||
* @return SOAP XML字符串
|
||||
*/
|
||||
public static String toString(SOAPMessage message, boolean pretty) {
|
||||
return toString(message, pretty, CharsetUtil.CHARSET_UTF_8);
|
||||
return toString(message, pretty, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user