mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix code
This commit is contained in:
@@ -52,7 +52,7 @@ public enum ContentType {
|
||||
*
|
||||
* @param value ContentType值
|
||||
*/
|
||||
ContentType(String value) {
|
||||
ContentType(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public enum ContentType {
|
||||
* @param charset 编码
|
||||
* @return Content-Type字符串
|
||||
*/
|
||||
public String toString(Charset charset) {
|
||||
public String toString(final Charset charset) {
|
||||
return build(this.value, charset);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public enum ContentType {
|
||||
* @return 是否为默认Content-Type
|
||||
* @since 4.1.5
|
||||
*/
|
||||
public static boolean isDefault(String contentType) {
|
||||
public static boolean isDefault(final String contentType) {
|
||||
return null == contentType || isFormUrlEncode(contentType);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public enum ContentType {
|
||||
* @param contentType 内容类型
|
||||
* @return 是否为application/x-www-form-urlencoded
|
||||
*/
|
||||
public static boolean isFormUrlEncode(String contentType) {
|
||||
public static boolean isFormUrlEncode(final String contentType) {
|
||||
return StrUtil.startWithIgnoreCase(contentType, FORM_URLENCODED.toString());
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ public enum ContentType {
|
||||
* @param body 请求参数体
|
||||
* @return Content-Type类型,如果无法判断返回null
|
||||
*/
|
||||
public static ContentType get(String body) {
|
||||
public static ContentType get(final String body) {
|
||||
ContentType contentType = null;
|
||||
if (StrUtil.isNotBlank(body)) {
|
||||
char firstChar = body.charAt(0);
|
||||
final char firstChar = body.charAt(0);
|
||||
switch (firstChar) {
|
||||
case '{':
|
||||
case '[':
|
||||
@@ -143,7 +143,7 @@ public enum ContentType {
|
||||
* @return Content-Type字符串
|
||||
* @since 4.5.4
|
||||
*/
|
||||
public static String build(String contentType, Charset charset) {
|
||||
public static String build(final String contentType, final Charset charset) {
|
||||
return StrUtil.format("{};charset={}", contentType, charset.name());
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public enum ContentType {
|
||||
* @return Content-Type字符串
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public static String build(ContentType contentType, Charset charset) {
|
||||
public static String build(final ContentType contentType, final Charset charset) {
|
||||
return build(contentType.getValue(), charset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum GlobalHeaders {
|
||||
* @param isReset 是否重置所有头部信息(删除自定义保留默认)
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders putDefault(boolean isReset) {
|
||||
public GlobalHeaders putDefault(final boolean isReset) {
|
||||
// 解决HttpURLConnection中无法自定义Host等头信息的问题
|
||||
// https://stackoverflow.com/questions/9096987/how-to-overwrite-http-header-host-in-a-httpurlconnection/9098440
|
||||
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||
@@ -68,7 +68,7 @@ public enum GlobalHeaders {
|
||||
* @param name Header名
|
||||
* @return Header值
|
||||
*/
|
||||
public String header(String name) {
|
||||
public String header(final String name) {
|
||||
final List<String> values = headerList(name);
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return null;
|
||||
@@ -83,7 +83,7 @@ public enum GlobalHeaders {
|
||||
* @return Header值
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public List<String> headerList(String name) {
|
||||
public List<String> headerList(final String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return null;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public enum GlobalHeaders {
|
||||
* @param name Header名
|
||||
* @return Header值
|
||||
*/
|
||||
public String header(Header name) {
|
||||
public String header(final Header name) {
|
||||
if (null == name) {
|
||||
return null;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public enum GlobalHeaders {
|
||||
* @param isOverride 是否覆盖已有值
|
||||
* @return this
|
||||
*/
|
||||
synchronized public GlobalHeaders header(String name, String value, boolean isOverride) {
|
||||
synchronized public GlobalHeaders header(final String name, final String value, final boolean isOverride) {
|
||||
if (null != name && null != value) {
|
||||
final List<String> values = headers.get(name.trim());
|
||||
if (isOverride || CollUtil.isEmpty(values)) {
|
||||
@@ -136,7 +136,7 @@ public enum GlobalHeaders {
|
||||
* @param isOverride 是否覆盖已有值
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders header(Header name, String value, boolean isOverride) {
|
||||
public GlobalHeaders header(final Header name, final String value, final boolean isOverride) {
|
||||
return header(name.toString(), value, isOverride);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public enum GlobalHeaders {
|
||||
* @param value Header值
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders header(Header name, String value) {
|
||||
public GlobalHeaders header(final Header name, final String value) {
|
||||
return header(name.toString(), value, true);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public enum GlobalHeaders {
|
||||
* @param value Header值
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders header(String name, String value) {
|
||||
public GlobalHeaders header(final String name, final String value) {
|
||||
return header(name, value, true);
|
||||
}
|
||||
|
||||
@@ -171,15 +171,15 @@ public enum GlobalHeaders {
|
||||
* @param headers 请求头
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders header(Map<String, List<String>> headers) {
|
||||
public GlobalHeaders header(final Map<String, List<String>> headers) {
|
||||
if (MapUtil.isEmpty(headers)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String name;
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
name = entry.getKey();
|
||||
for (String value : entry.getValue()) {
|
||||
for (final String value : entry.getValue()) {
|
||||
this.header(name, StrUtil.nullToEmpty(value), false);
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public enum GlobalHeaders {
|
||||
* @param name Header名
|
||||
* @return this
|
||||
*/
|
||||
synchronized public GlobalHeaders removeHeader(String name) {
|
||||
synchronized public GlobalHeaders removeHeader(final String name) {
|
||||
if (name != null) {
|
||||
headers.remove(name.trim());
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public enum GlobalHeaders {
|
||||
* @param name Header名
|
||||
* @return this
|
||||
*/
|
||||
public GlobalHeaders removeHeader(Header name) {
|
||||
public GlobalHeaders removeHeader(final Header name) {
|
||||
return removeHeader(name.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public enum GlobalInterceptor {
|
||||
* @param interceptor 拦截器实现
|
||||
* @return this
|
||||
*/
|
||||
synchronized public GlobalInterceptor addRequestInterceptor(HttpInterceptor<HttpRequest> interceptor) {
|
||||
synchronized public GlobalInterceptor addRequestInterceptor(final HttpInterceptor<HttpRequest> interceptor) {
|
||||
this.requestInterceptors.addChain(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public enum GlobalInterceptor {
|
||||
* @param interceptor 拦截器实现
|
||||
* @return this
|
||||
*/
|
||||
synchronized public GlobalInterceptor addResponseInterceptor(HttpInterceptor<HttpResponse> interceptor) {
|
||||
synchronized public GlobalInterceptor addResponseInterceptor(final HttpInterceptor<HttpResponse> interceptor) {
|
||||
this.responseInterceptors.addChain(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public enum GlobalInterceptor {
|
||||
*/
|
||||
HttpInterceptor.Chain<HttpRequest> getCopiedRequestInterceptor() {
|
||||
final HttpInterceptor.Chain<HttpRequest> copied = new HttpInterceptor.Chain<>();
|
||||
for (HttpInterceptor<HttpRequest> interceptor : this.requestInterceptors) {
|
||||
for (final HttpInterceptor<HttpRequest> interceptor : this.requestInterceptors) {
|
||||
copied.addChain(interceptor);
|
||||
}
|
||||
return copied;
|
||||
@@ -86,7 +86,7 @@ public enum GlobalInterceptor {
|
||||
*/
|
||||
HttpInterceptor.Chain<HttpResponse> getCopiedResponseInterceptor() {
|
||||
final HttpInterceptor.Chain<HttpResponse> copied = new HttpInterceptor.Chain<>();
|
||||
for (HttpInterceptor<HttpResponse> interceptor : this.responseInterceptors) {
|
||||
for (final HttpInterceptor<HttpResponse> interceptor : this.responseInterceptors) {
|
||||
copied.addChain(interceptor);
|
||||
}
|
||||
return copied;
|
||||
|
||||
@@ -298,7 +298,7 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
private String checkTags(String s) {
|
||||
Matcher m = P_TAGS.matcher(s);
|
||||
final Matcher m = P_TAGS.matcher(s);
|
||||
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
while (m.find()) {
|
||||
@@ -311,7 +311,7 @@ public final class HTMLFilter {
|
||||
// these get tallied in processTag
|
||||
// (remember to reset before subsequent calls to filter method)
|
||||
final StringBuilder sBuilder = new StringBuilder(buf.toString());
|
||||
for (String key : vTagCounts.keySet()) {
|
||||
for (final String key : vTagCounts.keySet()) {
|
||||
for (int ii = 0; ii < vTagCounts.get(key); ii++) {
|
||||
sBuilder.append("</").append(key).append(">");
|
||||
}
|
||||
@@ -323,7 +323,7 @@ public final class HTMLFilter {
|
||||
|
||||
private String processRemoveBlanks(final String s) {
|
||||
String result = s;
|
||||
for (String tag : vRemoveBlanks) {
|
||||
for (final String tag : vRemoveBlanks) {
|
||||
if (!P_REMOVE_PAIR_BLANKS.containsKey(tag)) {
|
||||
P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">"));
|
||||
}
|
||||
@@ -338,7 +338,7 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) {
|
||||
Matcher m = regex_pattern.matcher(s);
|
||||
final Matcher m = regex_pattern.matcher(s);
|
||||
return m.replaceAll(replacement);
|
||||
}
|
||||
|
||||
@@ -484,10 +484,10 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
private String validateEntities(final String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
|
||||
// validate entities throughout the string
|
||||
Matcher m = P_VALID_ENTITIES.matcher(s);
|
||||
final Matcher m = P_VALID_ENTITIES.matcher(s);
|
||||
while (m.find()) {
|
||||
final String one = m.group(1); // ([^&;]*)
|
||||
final String two = m.group(2); // (?=(;|&|$))
|
||||
@@ -500,8 +500,8 @@ public final class HTMLFilter {
|
||||
|
||||
private String encodeQuotes(final String s) {
|
||||
if (encodeQuotes) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Matcher m = P_VALID_QUOTES.matcher(s);
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final Matcher m = P_VALID_QUOTES.matcher(s);
|
||||
while (m.find()) {
|
||||
final String one = m.group(1); // (>|^)
|
||||
final String two = m.group(2); // ([^<]+?)
|
||||
@@ -525,7 +525,7 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
private static boolean inArray(final String s, final String[] array) {
|
||||
for (String item : array) {
|
||||
for (final String item : array) {
|
||||
if (item != null && item.equals(s)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public enum Header {
|
||||
|
||||
private final String value;
|
||||
|
||||
Header(String value) {
|
||||
Header(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HtmlUtil {
|
||||
* @param text 被转义的文本
|
||||
* @return 转义后的文本
|
||||
*/
|
||||
public static String escape(String text) {
|
||||
public static String escape(final String text) {
|
||||
return encode(text);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class HtmlUtil {
|
||||
* @param htmlStr 包含转义符的HTML内容
|
||||
* @return 转换后的字符串
|
||||
*/
|
||||
public static String unescape(String htmlStr) {
|
||||
public static String unescape(final String htmlStr) {
|
||||
if (StrUtil.isBlank(htmlStr)) {
|
||||
return htmlStr;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class HtmlUtil {
|
||||
* @param content 文本
|
||||
* @return 清除标签后的文本
|
||||
*/
|
||||
public static String cleanHtmlTag(String content) {
|
||||
public static String cleanHtmlTag(final String content) {
|
||||
return content.replaceAll(RE_HTML_MARK, "");
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class HtmlUtil {
|
||||
* @param tagNames 要清除的标签
|
||||
* @return 去除标签后的文本
|
||||
*/
|
||||
public static String removeHtmlTag(String content, String... tagNames) {
|
||||
public static String removeHtmlTag(final String content, final String... tagNames) {
|
||||
return removeHtmlTag(content, true, tagNames);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class HtmlUtil {
|
||||
* @param tagNames 要清除的标签
|
||||
* @return 去除标签后的文本
|
||||
*/
|
||||
public static String unwrapHtmlTag(String content, String... tagNames) {
|
||||
public static String unwrapHtmlTag(final String content, final String... tagNames) {
|
||||
return removeHtmlTag(content, false, tagNames);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class HtmlUtil {
|
||||
* @param tagNames 要清除的标签
|
||||
* @return 去除标签后的文本
|
||||
*/
|
||||
public static String removeHtmlTag(String content, boolean withTagContent, String... tagNames) {
|
||||
public static String removeHtmlTag(String content, final boolean withTagContent, final String... tagNames) {
|
||||
String regex;
|
||||
for (String tagName : tagNames) {
|
||||
if (StrUtil.isBlank(tagName)) {
|
||||
@@ -145,9 +145,9 @@ public class HtmlUtil {
|
||||
* @param attrs 属性名(不区分大小写)
|
||||
* @return 处理后的文本
|
||||
*/
|
||||
public static String removeHtmlAttr(String content, String... attrs) {
|
||||
public static String removeHtmlAttr(String content, final String... attrs) {
|
||||
String regex;
|
||||
for (String attr : attrs) {
|
||||
for (final String attr : attrs) {
|
||||
// (?i) 表示忽略大小写
|
||||
// \s* 属性名前后的空白符去除
|
||||
// [^>]+? 属性值,至少有一个非>的字符,>表示标签结束
|
||||
@@ -166,9 +166,9 @@ public class HtmlUtil {
|
||||
* @param tagNames 指定标签
|
||||
* @return 处理后的文本
|
||||
*/
|
||||
public static String removeAllHtmlAttr(String content, String... tagNames) {
|
||||
public static String removeAllHtmlAttr(String content, final String... tagNames) {
|
||||
String regex;
|
||||
for (String tagName : tagNames) {
|
||||
for (final String tagName : tagNames) {
|
||||
regex = StrUtil.format("(?i)<{}[^>]*?>", tagName);
|
||||
content = content.replaceAll(regex, StrUtil.format("<{}>", tagName));
|
||||
}
|
||||
@@ -181,12 +181,12 @@ public class HtmlUtil {
|
||||
* @param text 被编码的文本
|
||||
* @return 编码后的字符
|
||||
*/
|
||||
private static String encode(String text) {
|
||||
int len;
|
||||
private static String encode(final String text) {
|
||||
final int len;
|
||||
if ((text == null) || ((len = text.length()) == 0)) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
StringBuilder buffer = new StringBuilder(len + (len >> 2));
|
||||
final StringBuilder buffer = new StringBuilder(len + (len >> 2));
|
||||
char c;
|
||||
for (int i = 0; i < len; i++) {
|
||||
c = text.charAt(i);
|
||||
@@ -205,7 +205,7 @@ public class HtmlUtil {
|
||||
* @param htmlContent HTML内容
|
||||
* @return 过滤后的内容
|
||||
*/
|
||||
public static String filter(String htmlContent) {
|
||||
public static String filter(final String htmlContent) {
|
||||
return new HTMLFilter().filter(htmlContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class HttpBase<T> {
|
||||
* @param name Header名
|
||||
* @return Header值
|
||||
*/
|
||||
public String header(String name) {
|
||||
public String header(final String name) {
|
||||
final List<String> values = headerList(name);
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return null;
|
||||
@@ -78,7 +78,7 @@ public abstract class HttpBase<T> {
|
||||
* @return Header值
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public List<String> headerList(String name) {
|
||||
public List<String> headerList(final String name) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return null;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public abstract class HttpBase<T> {
|
||||
* @param name Header名
|
||||
* @return Header值
|
||||
*/
|
||||
public String header(Header name) {
|
||||
public String header(final Header name) {
|
||||
if (null == name) {
|
||||
return null;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public abstract class HttpBase<T> {
|
||||
* @param isOverride 是否覆盖已有值
|
||||
* @return T 本身
|
||||
*/
|
||||
public T header(String name, String value, boolean isOverride) {
|
||||
public T header(final String name, final String value, final boolean isOverride) {
|
||||
if (null != name && null != value) {
|
||||
final List<String> values = headers.get(name.trim());
|
||||
if (isOverride || CollUtil.isEmpty(values)) {
|
||||
@@ -132,7 +132,7 @@ public abstract class HttpBase<T> {
|
||||
* @param isOverride 是否覆盖已有值
|
||||
* @return T 本身
|
||||
*/
|
||||
public T header(Header name, String value, boolean isOverride) {
|
||||
public T header(final Header name, final String value, final boolean isOverride) {
|
||||
return header(name.toString(), value, isOverride);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public abstract class HttpBase<T> {
|
||||
* @param value Header值
|
||||
* @return T 本身
|
||||
*/
|
||||
public T header(Header name, String value) {
|
||||
public T header(final Header name, final String value) {
|
||||
return header(name.toString(), value, true);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class HttpBase<T> {
|
||||
* @param value Header值
|
||||
* @return T 本身
|
||||
*/
|
||||
public T header(String name, String value) {
|
||||
public T header(final String name, final String value) {
|
||||
return header(name, value, true);
|
||||
}
|
||||
|
||||
@@ -168,12 +168,12 @@ public abstract class HttpBase<T> {
|
||||
* @return this
|
||||
* @since 4.6.3
|
||||
*/
|
||||
public T headerMap(Map<String, String> headers, boolean isOverride) {
|
||||
public T headerMap(final Map<String, String> headers, final boolean isOverride) {
|
||||
if (MapUtil.isEmpty(headers)) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
for (final Entry<String, String> entry : headers.entrySet()) {
|
||||
this.header(entry.getKey(), StrUtil.nullToEmpty(entry.getValue()), isOverride);
|
||||
}
|
||||
return (T) this;
|
||||
@@ -186,7 +186,7 @@ public abstract class HttpBase<T> {
|
||||
* @param headers 请求头
|
||||
* @return this
|
||||
*/
|
||||
public T header(Map<String, List<String>> headers) {
|
||||
public T header(final Map<String, List<String>> headers) {
|
||||
return header(headers, false);
|
||||
}
|
||||
|
||||
@@ -198,15 +198,15 @@ public abstract class HttpBase<T> {
|
||||
* @return this
|
||||
* @since 4.0.8
|
||||
*/
|
||||
public T header(Map<String, List<String>> headers, boolean isOverride) {
|
||||
public T header(final Map<String, List<String>> headers, final boolean isOverride) {
|
||||
if (MapUtil.isEmpty(headers)) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
String name;
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
name = entry.getKey();
|
||||
for (String value : entry.getValue()) {
|
||||
for (final String value : entry.getValue()) {
|
||||
this.header(name, StrUtil.nullToEmpty(value), isOverride);
|
||||
}
|
||||
}
|
||||
@@ -221,12 +221,12 @@ public abstract class HttpBase<T> {
|
||||
* @return this
|
||||
* @since 4.0.3
|
||||
*/
|
||||
public T addHeaders(Map<String, String> headers) {
|
||||
public T addHeaders(final Map<String, String> headers) {
|
||||
if (MapUtil.isEmpty(headers)) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
for (final Entry<String, String> entry : headers.entrySet()) {
|
||||
this.header(entry.getKey(), StrUtil.nullToEmpty(entry.getValue()), false);
|
||||
}
|
||||
return (T) this;
|
||||
@@ -238,7 +238,7 @@ public abstract class HttpBase<T> {
|
||||
* @param name Header名
|
||||
* @return this
|
||||
*/
|
||||
public T removeHeader(String name) {
|
||||
public T removeHeader(final String name) {
|
||||
if (name != null) {
|
||||
headers.remove(name.trim());
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public abstract class HttpBase<T> {
|
||||
* @param name Header名
|
||||
* @return this
|
||||
*/
|
||||
public T removeHeader(Header name) {
|
||||
public T removeHeader(final Header name) {
|
||||
return removeHeader(name.toString());
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ public abstract class HttpBase<T> {
|
||||
* @param httpVersion Http版本,{@link HttpBase#HTTP_1_0},{@link HttpBase#HTTP_1_1}
|
||||
* @return this
|
||||
*/
|
||||
public T httpVersion(String httpVersion) {
|
||||
public T httpVersion(final String httpVersion) {
|
||||
this.httpVersion = httpVersion;
|
||||
return (T) this;
|
||||
}
|
||||
@@ -312,7 +312,7 @@ public abstract class HttpBase<T> {
|
||||
* @return T 自己
|
||||
* @see CharsetUtil
|
||||
*/
|
||||
public T charset(String charset) {
|
||||
public T charset(final String charset) {
|
||||
if (StrUtil.isNotBlank(charset)) {
|
||||
charset(Charset.forName(charset));
|
||||
}
|
||||
@@ -326,7 +326,7 @@ public abstract class HttpBase<T> {
|
||||
* @return T 自己
|
||||
* @see CharsetUtil
|
||||
*/
|
||||
public T charset(Charset charset) {
|
||||
public T charset(final Charset charset) {
|
||||
if (null != charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
@@ -335,9 +335,9 @@ public abstract class HttpBase<T> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
final StringBuilder sb = StrUtil.builder();
|
||||
sb.append("Request Headers: ").append(StrUtil.CRLF);
|
||||
for (Entry<String, List<String>> entry : this.headers.entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : this.headers.entrySet()) {
|
||||
sb.append(" ").append(
|
||||
entry.getKey()).append(": ").append(CollUtil.join(entry.getValue(), ","))
|
||||
.append(StrUtil.CRLF);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class HttpConfig {
|
||||
* @see #setConnectionTimeout(int)
|
||||
* @see #setReadTimeout(int)
|
||||
*/
|
||||
public HttpConfig timeout(int milliseconds) {
|
||||
public HttpConfig timeout(final int milliseconds) {
|
||||
setConnectionTimeout(milliseconds);
|
||||
setReadTimeout(milliseconds);
|
||||
return this;
|
||||
@@ -116,7 +116,7 @@ public class HttpConfig {
|
||||
* @param milliseconds 超时毫秒数
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setConnectionTimeout(int milliseconds) {
|
||||
public HttpConfig setConnectionTimeout(final int milliseconds) {
|
||||
this.connectionTimeout = milliseconds;
|
||||
return this;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class HttpConfig {
|
||||
* @param milliseconds 超时毫秒数
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setReadTimeout(int milliseconds) {
|
||||
public HttpConfig setReadTimeout(final int milliseconds) {
|
||||
this.readTimeout = milliseconds;
|
||||
return this;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class HttpConfig {
|
||||
* @param maxRedirectCount 最大重定向次数
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setMaxRedirectCount(int maxRedirectCount) {
|
||||
public HttpConfig setMaxRedirectCount(final int maxRedirectCount) {
|
||||
this.maxRedirectCount = Math.max(maxRedirectCount, 0);
|
||||
return this;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class HttpConfig {
|
||||
* @param hostnameVerifier HostnameVerifier
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
public HttpConfig setHostnameVerifier(final HostnameVerifier hostnameVerifier) {
|
||||
// 验证域
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
return this;
|
||||
@@ -174,7 +174,7 @@ public class HttpConfig {
|
||||
* @param port 代理 端口
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setHttpProxy(String host, int port) {
|
||||
public HttpConfig setHttpProxy(final String host, final int port) {
|
||||
final Proxy proxy = new Proxy(Proxy.Type.HTTP,
|
||||
new InetSocketAddress(host, port));
|
||||
return setProxy(proxy);
|
||||
@@ -186,7 +186,7 @@ public class HttpConfig {
|
||||
* @param proxy 代理 {@link Proxy}
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setProxy(Proxy proxy) {
|
||||
public HttpConfig setProxy(final Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public class HttpConfig {
|
||||
* @param ssf SSLScketFactory
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setSSLSocketFactory(SSLSocketFactory ssf) {
|
||||
public HttpConfig setSSLSocketFactory(final SSLSocketFactory ssf) {
|
||||
this.ssf = ssf;
|
||||
return this;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class HttpConfig {
|
||||
* @see SSLUtil#createSSLContext(String)
|
||||
* @see #setSSLSocketFactory(SSLSocketFactory)
|
||||
*/
|
||||
public HttpConfig setSSLProtocol(String protocol) {
|
||||
public HttpConfig setSSLProtocol(final String protocol) {
|
||||
Assert.notBlank(protocol, "protocol must be not blank!");
|
||||
setSSLSocketFactory(SSLUtil.createSSLContext(protocol).getSocketFactory());
|
||||
return this;
|
||||
@@ -233,7 +233,7 @@ public class HttpConfig {
|
||||
* @param blockSize 块大小(bytes数),0或小于0表示不设置Chuncked模式
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setBlockSize(int blockSize) {
|
||||
public HttpConfig setBlockSize(final int blockSize) {
|
||||
this.blockSize = blockSize;
|
||||
return this;
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class HttpConfig {
|
||||
* @return this
|
||||
* @since 5.7.20
|
||||
*/
|
||||
public HttpConfig setIgnoreEOFError(boolean ignoreEOFError) {
|
||||
public HttpConfig setIgnoreEOFError(final boolean ignoreEOFError) {
|
||||
this.ignoreEOFError = ignoreEOFError;
|
||||
return this;
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class HttpConfig {
|
||||
* @param decodeUrl 是否忽略解码URL
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setDecodeUrl(boolean decodeUrl) {
|
||||
public HttpConfig setDecodeUrl(final boolean decodeUrl) {
|
||||
this.decodeUrl = decodeUrl;
|
||||
return this;
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class HttpConfig {
|
||||
* @param interceptor 拦截器实现
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig addRequestInterceptor(HttpInterceptor<HttpRequest> interceptor) {
|
||||
public HttpConfig addRequestInterceptor(final HttpInterceptor<HttpRequest> interceptor) {
|
||||
this.requestInterceptors.addChain(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class HttpConfig {
|
||||
* @param interceptor 拦截器实现
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig addResponseInterceptor(HttpInterceptor<HttpResponse> interceptor) {
|
||||
public HttpConfig addResponseInterceptor(final HttpInterceptor<HttpResponse> interceptor) {
|
||||
this.responseInterceptors.addChain(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ public class HttpConfig {
|
||||
* @param interceptorOnRedirect 重定向时是否使用拦截器
|
||||
* @return this
|
||||
*/
|
||||
public HttpConfig setInterceptorOnRedirect(boolean interceptorOnRedirect) {
|
||||
public HttpConfig setInterceptorOnRedirect(final boolean interceptorOnRedirect) {
|
||||
this.interceptorOnRedirect = interceptorOnRedirect;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class HttpConnection {
|
||||
* @param proxy 代理,无代理传{@code null}
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public static HttpConnection create(String urlStr, Proxy proxy) {
|
||||
public static HttpConnection create(final String urlStr, final Proxy proxy) {
|
||||
return create(URLUtil.toUrlForHttp(urlStr), proxy);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class HttpConnection {
|
||||
* @param proxy 代理,无代理传{@code null}
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public static HttpConnection create(URL url, Proxy proxy) {
|
||||
public static HttpConnection create(final URL url, final Proxy proxy) {
|
||||
return new HttpConnection(url, proxy);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class HttpConnection {
|
||||
* @param url URL
|
||||
* @param proxy 代理
|
||||
*/
|
||||
public HttpConnection(URL url, Proxy proxy) {
|
||||
public HttpConnection(final URL url, final Proxy proxy) {
|
||||
this.url = url;
|
||||
this.proxy = proxy;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class HttpConnection {
|
||||
public HttpConnection initConn() {
|
||||
try {
|
||||
this.conn = openHttp();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new HttpException(e);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class HttpConnection {
|
||||
* @param method 请求方法
|
||||
* @return 自己
|
||||
*/
|
||||
public HttpConnection setMethod(Method method) {
|
||||
public HttpConnection setMethod(final Method method) {
|
||||
if (Method.POST.equals(method) //
|
||||
|| Method.PUT.equals(method)//
|
||||
|| Method.PATCH.equals(method)//
|
||||
@@ -127,7 +127,7 @@ public class HttpConnection {
|
||||
// method
|
||||
try {
|
||||
this.conn.setRequestMethod(method.toString());
|
||||
} catch (ProtocolException e) {
|
||||
} catch (final ProtocolException e) {
|
||||
throw new HttpException(e);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class HttpConnection {
|
||||
* @param isOverride 是否覆盖旧值
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public HttpConnection header(String header, String value, boolean isOverride) {
|
||||
public HttpConnection header(final String header, final String value, final boolean isOverride) {
|
||||
if (null != this.conn) {
|
||||
if (isOverride) {
|
||||
this.conn.setRequestProperty(header, value);
|
||||
@@ -195,7 +195,7 @@ public class HttpConnection {
|
||||
* @param isOverride 是否覆盖旧值
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public HttpConnection header(Header header, String value, boolean isOverride) {
|
||||
public HttpConnection header(final Header header, final String value, final boolean isOverride) {
|
||||
return header(header.toString(), value, isOverride);
|
||||
}
|
||||
|
||||
@@ -207,12 +207,12 @@ public class HttpConnection {
|
||||
* @param isOverride 是否覆盖
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection header(Map<String, List<String>> headerMap, boolean isOverride) {
|
||||
public HttpConnection header(final Map<String, List<String>> headerMap, final boolean isOverride) {
|
||||
if (MapUtil.isNotEmpty(headerMap)) {
|
||||
String name;
|
||||
for (Entry<String, List<String>> entry : headerMap.entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : headerMap.entrySet()) {
|
||||
name = entry.getKey();
|
||||
for (String value : entry.getValue()) {
|
||||
for (final String value : entry.getValue()) {
|
||||
this.header(name, StrUtil.nullToEmpty(value), isOverride);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class HttpConnection {
|
||||
* @param name Header名
|
||||
* @return Http请求头值
|
||||
*/
|
||||
public String header(String name) {
|
||||
public String header(final String name) {
|
||||
return this.conn.getHeaderField(name);
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class HttpConnection {
|
||||
* @param name Header名
|
||||
* @return Http请求头值
|
||||
*/
|
||||
public String header(Header name) {
|
||||
public String header(final Header name) {
|
||||
return header(name.toString());
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class HttpConnection {
|
||||
* @return this
|
||||
* @throws HttpException KeyManagementException和NoSuchAlgorithmException异常包装
|
||||
*/
|
||||
public HttpConnection setHttpsInfo(HostnameVerifier hostnameVerifier, SSLSocketFactory ssf) throws HttpException {
|
||||
public HttpConnection setHttpsInfo(final HostnameVerifier hostnameVerifier, final SSLSocketFactory ssf) throws HttpException {
|
||||
final HttpURLConnection conn = this.conn;
|
||||
|
||||
if (conn instanceof HttpsURLConnection) {
|
||||
@@ -291,7 +291,7 @@ public class HttpConnection {
|
||||
* @param timeout 超时
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setConnectTimeout(int timeout) {
|
||||
public HttpConnection setConnectTimeout(final int timeout) {
|
||||
if (timeout > 0 && null != this.conn) {
|
||||
this.conn.setConnectTimeout(timeout);
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public class HttpConnection {
|
||||
* @param timeout 超时
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setReadTimeout(int timeout) {
|
||||
public HttpConnection setReadTimeout(final int timeout) {
|
||||
if (timeout > 0 && null != this.conn) {
|
||||
this.conn.setReadTimeout(timeout);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public class HttpConnection {
|
||||
* @param timeout 超时时间
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setConnectionAndReadTimeout(int timeout) {
|
||||
public HttpConnection setConnectionAndReadTimeout(final int timeout) {
|
||||
setConnectTimeout(timeout);
|
||||
setReadTimeout(timeout);
|
||||
|
||||
@@ -332,7 +332,7 @@ public class HttpConnection {
|
||||
* @param cookie Cookie
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setCookie(String cookie) {
|
||||
public HttpConnection setCookie(final String cookie) {
|
||||
if (cookie != null) {
|
||||
header(Header.COOKIE, cookie, true);
|
||||
}
|
||||
@@ -346,7 +346,7 @@ public class HttpConnection {
|
||||
* @param blockSize 块大小(bytes数),0或小于0表示不设置Chuncked模式
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setChunkedStreamingMode(int blockSize) {
|
||||
public HttpConnection setChunkedStreamingMode(final int blockSize) {
|
||||
if (blockSize > 0) {
|
||||
conn.setChunkedStreamingMode(blockSize);
|
||||
}
|
||||
@@ -359,7 +359,7 @@ public class HttpConnection {
|
||||
* @param isInstanceFollowRedirects 是否自定跳转
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setInstanceFollowRedirects(boolean isInstanceFollowRedirects) {
|
||||
public HttpConnection setInstanceFollowRedirects(final boolean isInstanceFollowRedirects) {
|
||||
conn.setInstanceFollowRedirects(isInstanceFollowRedirects);
|
||||
return this;
|
||||
}
|
||||
@@ -386,7 +386,7 @@ public class HttpConnection {
|
||||
public HttpConnection disconnectQuietly() {
|
||||
try {
|
||||
disconnect();
|
||||
} catch (Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ public class HttpConnection {
|
||||
if (StrUtil.isNotBlank(charsetName)) {
|
||||
try {
|
||||
charset = Charset.forName(charsetName);
|
||||
} catch (UnsupportedCharsetException e) {
|
||||
} catch (final UnsupportedCharsetException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -506,7 +506,7 @@ public class HttpConnection {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
final StringBuilder sb = StrUtil.builder();
|
||||
sb.append("Request URL: ").append(this.url).append(StrUtil.CRLF);
|
||||
sb.append("Request Method: ").append(this.getMethod()).append(StrUtil.CRLF);
|
||||
// sb.append("Request Headers: ").append(StrUtil.CRLF);
|
||||
|
||||
@@ -24,7 +24,7 @@ public class HttpDownloader {
|
||||
* @param streamPress 进度条 {@link StreamProgress}
|
||||
* @return 文本
|
||||
*/
|
||||
public static String downloadString(String url, Charset customCharset, StreamProgress streamPress) {
|
||||
public static String downloadString(final String url, final Charset customCharset, final StreamProgress streamPress) {
|
||||
final FastByteArrayOutputStream out = new FastByteArrayOutputStream();
|
||||
download(url, out, true, streamPress);
|
||||
return null == customCharset ? out.toString() : out.toString(customCharset);
|
||||
@@ -36,7 +36,7 @@ public class HttpDownloader {
|
||||
* @param url 请求的url
|
||||
* @return 文件数据
|
||||
*/
|
||||
public static byte[] downloadBytes(String url) {
|
||||
public static byte[] downloadBytes(final String url) {
|
||||
return requestDownload(url, -1).bodyBytes();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class HttpDownloader {
|
||||
* @param streamProgress 进度条
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long downloadFile(String url, File targetFileOrDir, int timeout, StreamProgress streamProgress) {
|
||||
public static long downloadFile(final String url, final File targetFileOrDir, final int timeout, final StreamProgress streamProgress) {
|
||||
return requestDownload(url, timeout).writeBody(targetFileOrDir, streamProgress);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class HttpDownloader {
|
||||
* @return 下载大小
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public long downloadFile(String url, File targetFileOrDir, String tempFileSuffix, int timeout, StreamProgress streamProgress) {
|
||||
public long downloadFile(final String url, final File targetFileOrDir, final String tempFileSuffix, final int timeout, final StreamProgress streamProgress) {
|
||||
return requestDownload(url, timeout).writeBody(targetFileOrDir, tempFileSuffix, streamProgress);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class HttpDownloader {
|
||||
* @param streamProgress 进度条
|
||||
* @return 文件
|
||||
*/
|
||||
public static File downloadForFile(String url, File targetFileOrDir, int timeout, StreamProgress streamProgress) {
|
||||
public static File downloadForFile(final String url, final File targetFileOrDir, final int timeout, final StreamProgress streamProgress) {
|
||||
return requestDownload(url, timeout).writeBodyForFile(targetFileOrDir, streamProgress);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class HttpDownloader {
|
||||
* @param streamProgress 进度条
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long download(String url, OutputStream out, boolean isCloseOut, StreamProgress streamProgress) {
|
||||
public static long download(final String url, final OutputStream out, final boolean isCloseOut, final StreamProgress streamProgress) {
|
||||
Assert.notNull(out, "[out] is null !");
|
||||
|
||||
return requestDownload(url, -1).writeBody(out, isCloseOut, streamProgress);
|
||||
@@ -106,7 +106,7 @@ public class HttpDownloader {
|
||||
* @return HttpResponse
|
||||
* @since 5.4.1
|
||||
*/
|
||||
private static HttpResponse requestDownload(String url, int timeout) {
|
||||
private static HttpResponse requestDownload(final String url, final int timeout) {
|
||||
Assert.notBlank(url, "[url] is blank !");
|
||||
|
||||
final HttpResponse response = HttpUtil.createGet(url, true)
|
||||
|
||||
@@ -10,27 +10,27 @@ import cn.hutool.core.text.StrUtil;
|
||||
public class HttpException extends RuntimeException {
|
||||
private static final long serialVersionUID = 8247610319171014183L;
|
||||
|
||||
public HttpException(Throwable e) {
|
||||
public HttpException(final Throwable e) {
|
||||
super(e.getMessage(), e);
|
||||
}
|
||||
|
||||
public HttpException(String message) {
|
||||
public HttpException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public HttpException(String messageTemplate, Object... params) {
|
||||
public HttpException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
}
|
||||
|
||||
public HttpException(String message, Throwable throwable) {
|
||||
public HttpException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
|
||||
public HttpException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
|
||||
public HttpException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public HttpException(Throwable throwable, String messageTemplate, Object... params) {
|
||||
public HttpException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
*
|
||||
* @param customTimeout 超时时长
|
||||
*/
|
||||
synchronized public static void setTimeout(int customTimeout) {
|
||||
synchronized public static void setTimeout(final int customTimeout) {
|
||||
timeout = customTimeout;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
* @param customBoundary 自定义Multipart边界
|
||||
* @since 5.7.17
|
||||
*/
|
||||
synchronized public static void setBoundary(String customBoundary) {
|
||||
synchronized public static void setBoundary(final String customBoundary) {
|
||||
boundary = customBoundary;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
* @param customMaxRedirectCount 全局默认的最大重定向次数
|
||||
* @since 5.7.19
|
||||
*/
|
||||
synchronized public static void setMaxRedirectCount(int customMaxRedirectCount) {
|
||||
synchronized public static void setMaxRedirectCount(final int customMaxRedirectCount) {
|
||||
maxRedirectCount = customMaxRedirectCount;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
* @param customIgnoreEOFError 是否忽略响应读取时可能的EOF异常。
|
||||
* @since 5.7.20
|
||||
*/
|
||||
synchronized public static void setIgnoreEOFError(boolean customIgnoreEOFError) {
|
||||
synchronized public static void setIgnoreEOFError(final boolean customIgnoreEOFError) {
|
||||
ignoreEOFError = customIgnoreEOFError;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
* @param customDecodeUrl 是否忽略解码URL
|
||||
* @since 5.7.22
|
||||
*/
|
||||
synchronized public static void setDecodeUrl(boolean customDecodeUrl) {
|
||||
synchronized public static void setDecodeUrl(final boolean customDecodeUrl) {
|
||||
decodeUrl = customDecodeUrl;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class HttpGlobalConfig implements Serializable {
|
||||
* @see GlobalCookieManager#setCookieManager(CookieManager)
|
||||
* @since 4.5.14
|
||||
*/
|
||||
synchronized public static void setCookieManager(CookieManager customCookieManager) {
|
||||
synchronized public static void setCookieManager(final CookieManager customCookieManager) {
|
||||
GlobalCookieManager.setCookieManager(customCookieManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class HttpInputStream extends InputStream {
|
||||
*
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public HttpInputStream(HttpResponse response) {
|
||||
public HttpInputStream(final HttpResponse response) {
|
||||
init(response);
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ public class HttpInputStream extends InputStream {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
public int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
return this.in.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
public long skip(final long n) throws IOException {
|
||||
return this.in.skip(n);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class HttpInputStream extends InputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mark(int readlimit) {
|
||||
public synchronized void mark(final int readlimit) {
|
||||
this.in.mark(readlimit);
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ public class HttpInputStream extends InputStream {
|
||||
*
|
||||
* @param response 响应对象
|
||||
*/
|
||||
private void init(HttpResponse response) {
|
||||
private void init(final HttpResponse response) {
|
||||
try {
|
||||
this.in = (response.status < HttpStatus.HTTP_BAD_REQUEST) ? response.httpConnection.getInputStream() : response.httpConnection.getErrorStream();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
if (false == (e instanceof FileNotFoundException)) {
|
||||
throw new HttpException(e);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class HttpInputStream extends InputStream {
|
||||
// Accept-Encoding: gzip
|
||||
try {
|
||||
this.in = new GZIPInputStream(this.in);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
// 在类似于Head等方法中无body返回,此时GZIPInputStream构造会出现错误,在此忽略此错误读取普通数据
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public interface HttpInterceptor<T extends HttpBase<T>> {
|
||||
private final List<HttpInterceptor<T>> interceptors = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public Chain<T> addChain(HttpInterceptor<T> element) {
|
||||
public Chain<T> addChain(final HttpInterceptor<T> element) {
|
||||
interceptors.add(element);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest post(String url) {
|
||||
public static HttpRequest post(final String url) {
|
||||
return of(url).method(Method.POST);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest get(String url) {
|
||||
public static HttpRequest get(final String url) {
|
||||
return of(url).method(Method.GET);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest head(String url) {
|
||||
public static HttpRequest head(final String url) {
|
||||
return of(url).method(Method.HEAD);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest options(String url) {
|
||||
public static HttpRequest options(final String url) {
|
||||
return of(url).method(Method.OPTIONS);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest put(String url) {
|
||||
public static HttpRequest put(final String url) {
|
||||
return of(url).method(Method.PUT);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static HttpRequest patch(String url) {
|
||||
public static HttpRequest patch(final String url) {
|
||||
return of(url).method(Method.PATCH);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest delete(String url) {
|
||||
public static HttpRequest delete(final String url) {
|
||||
return of(url).method(Method.DELETE);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param url URL
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public static HttpRequest trace(String url) {
|
||||
public static HttpRequest trace(final String url) {
|
||||
return of(url).method(Method.TRACE);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.7.18
|
||||
*/
|
||||
public static HttpRequest of(String url) {
|
||||
public static HttpRequest of(final String url) {
|
||||
return of(url, HttpGlobalConfig.isDecodeUrl() ? DEFAULT_CHARSET : null);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.7.18
|
||||
*/
|
||||
public static HttpRequest of(String url, Charset charset) {
|
||||
public static HttpRequest of(final String url, final Charset charset) {
|
||||
return of(UrlBuilder.ofHttp(url, charset));
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public static HttpRequest of(UrlBuilder url) {
|
||||
public static HttpRequest of(final UrlBuilder url) {
|
||||
return new HttpRequest(url);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see HttpGlobalConfig#setTimeout(int)
|
||||
* @since 4.6.2
|
||||
*/
|
||||
public static void setGlobalTimeout(int customTimeout) {
|
||||
public static void setGlobalTimeout(final int customTimeout) {
|
||||
HttpGlobalConfig.setTimeout(customTimeout);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see GlobalCookieManager#setCookieManager(CookieManager)
|
||||
* @since 4.5.14
|
||||
*/
|
||||
public static void setCookieManager(CookieManager customCookieManager) {
|
||||
public static void setCookieManager(final CookieManager customCookieManager) {
|
||||
GlobalCookieManager.setCookieManager(customCookieManager);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
*
|
||||
* @param url {@link UrlBuilder}
|
||||
*/
|
||||
public HttpRequest(UrlBuilder url) {
|
||||
public HttpRequest(final UrlBuilder url) {
|
||||
this.url = Assert.notNull(url, "URL must be not null!");
|
||||
// 给定默认URL编码
|
||||
final Charset charset = url.getCharset();
|
||||
@@ -274,7 +274,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.1.8
|
||||
*/
|
||||
public HttpRequest setUrl(String url) {
|
||||
public HttpRequest setUrl(final String url) {
|
||||
return setUrl(UrlBuilder.ofHttp(url, this.charset));
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.3.1
|
||||
*/
|
||||
public HttpRequest setUrl(UrlBuilder urlBuilder) {
|
||||
public HttpRequest setUrl(final UrlBuilder urlBuilder) {
|
||||
this.url = urlBuilder;
|
||||
return this;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.1.9
|
||||
*/
|
||||
public HttpRequest setUrlHandler(URLStreamHandler urlHandler) {
|
||||
public HttpRequest setUrlHandler(final URLStreamHandler urlHandler) {
|
||||
this.urlHandler = urlHandler;
|
||||
return this;
|
||||
}
|
||||
@@ -326,7 +326,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see #method(Method)
|
||||
* @since 4.1.8
|
||||
*/
|
||||
public HttpRequest setMethod(Method method) {
|
||||
public HttpRequest setMethod(final Method method) {
|
||||
return method(method);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param method HTTP方法
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest method(Method method) {
|
||||
public HttpRequest method(final Method method) {
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param contentType contentType
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest contentType(String contentType) {
|
||||
public HttpRequest contentType(final String contentType) {
|
||||
header(Header.CONTENT_TYPE, contentType);
|
||||
return this;
|
||||
}
|
||||
@@ -371,7 +371,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param isKeepAlive 是否长连接
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest keepAlive(boolean isKeepAlive) {
|
||||
public HttpRequest keepAlive(final boolean isKeepAlive) {
|
||||
header(Header.CONNECTION, isKeepAlive ? "Keep-Alive" : "Close");
|
||||
return this;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return 获取是否为长连接
|
||||
*/
|
||||
public boolean isKeepAlive() {
|
||||
String connection = header(Header.CONNECTION);
|
||||
final String connection = header(Header.CONNECTION);
|
||||
if (connection == null) {
|
||||
return false == HTTP_1_0.equalsIgnoreCase(httpVersion);
|
||||
}
|
||||
@@ -403,7 +403,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param value 长度
|
||||
* @return HttpRequest
|
||||
*/
|
||||
public HttpRequest contentLength(int value) {
|
||||
public HttpRequest contentLength(final int value) {
|
||||
header(Header.CONTENT_LENGTH, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public HttpRequest cookie(Collection<HttpCookie> cookies) {
|
||||
public HttpRequest cookie(final Collection<HttpCookie> cookies) {
|
||||
return cookie(CollUtil.isEmpty(cookies) ? null : cookies.toArray(new HttpCookie[0]));
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public HttpRequest cookie(HttpCookie... cookies) {
|
||||
public HttpRequest cookie(final HttpCookie... cookies) {
|
||||
if (ArrayUtil.isEmpty(cookies)) {
|
||||
return disableCookie();
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 3.0.7
|
||||
*/
|
||||
public HttpRequest cookie(String cookie) {
|
||||
public HttpRequest cookie(final String cookie) {
|
||||
this.cookie = cookie;
|
||||
return this;
|
||||
}
|
||||
@@ -481,7 +481,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, Object value) {
|
||||
public HttpRequest form(final String name, final Object value) {
|
||||
if (StrUtil.isBlank(name) || ObjUtil.isNull(value)) {
|
||||
return this; // 忽略非法的form表单项内容;
|
||||
}
|
||||
@@ -499,7 +499,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
}
|
||||
|
||||
// 普通值
|
||||
String strValue;
|
||||
final String strValue;
|
||||
if (value instanceof Iterable) {
|
||||
// 列表对象
|
||||
strValue = CollUtil.join((Iterable<?>) value, ",");
|
||||
@@ -526,7 +526,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param parameters 参数对,奇数为名,偶数为值
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, Object value, Object... parameters) {
|
||||
public HttpRequest form(final String name, final Object value, final Object... parameters) {
|
||||
form(name, value);
|
||||
|
||||
for (int i = 0; i < parameters.length; i += 2) {
|
||||
@@ -541,7 +541,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param formMap 表单内容
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(Map<String, Object> formMap) {
|
||||
public HttpRequest form(final Map<String, Object> formMap) {
|
||||
if (MapUtil.isNotEmpty(formMap)) {
|
||||
formMap.forEach(this::form);
|
||||
}
|
||||
@@ -555,7 +555,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.6.7
|
||||
*/
|
||||
public HttpRequest formStr(Map<String, String> formMapStr) {
|
||||
public HttpRequest formStr(final Map<String, String> formMapStr) {
|
||||
if (MapUtil.isNotEmpty(formMapStr)) {
|
||||
formMapStr.forEach(this::form);
|
||||
}
|
||||
@@ -570,7 +570,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param files 需要上传的文件,为空跳过
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, File... files) {
|
||||
public HttpRequest form(final String name, final File... files) {
|
||||
if (ArrayUtil.isEmpty(files)) {
|
||||
return this;
|
||||
}
|
||||
@@ -589,7 +589,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param file 需要上传的文件
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, File file) {
|
||||
public HttpRequest form(final String name, final File file) {
|
||||
return form(name, file, file.getName());
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param fileName 文件名,为空使用文件默认的文件名
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest form(String name, File file, String fileName) {
|
||||
public HttpRequest form(final String name, final File file, final String fileName) {
|
||||
if (null != file) {
|
||||
form(name, new FileResource(file, fileName));
|
||||
}
|
||||
@@ -619,7 +619,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public HttpRequest form(String name, byte[] fileBytes, String fileName) {
|
||||
public HttpRequest form(final String name, final byte[] fileBytes, final String fileName) {
|
||||
if (null != fileBytes) {
|
||||
form(name, new BytesResource(fileBytes, fileName));
|
||||
}
|
||||
@@ -635,7 +635,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.0.9
|
||||
*/
|
||||
public HttpRequest form(String name, Resource resource) {
|
||||
public HttpRequest form(final String name, final Resource resource) {
|
||||
if (null != resource) {
|
||||
if (false == isKeepAlive()) {
|
||||
keepAlive(true);
|
||||
@@ -687,7 +687,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param body 请求体
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest body(String body) {
|
||||
public HttpRequest body(final String body) {
|
||||
return this.body(body, null);
|
||||
}
|
||||
|
||||
@@ -704,8 +704,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param contentType 请求体类型,{@code null}表示自动判断类型
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest body(String body, String contentType) {
|
||||
byte[] bytes = StrUtil.bytes(body, this.charset);
|
||||
public HttpRequest body(final String body, String contentType) {
|
||||
final byte[] bytes = StrUtil.bytes(body, this.charset);
|
||||
body(bytes);
|
||||
this.form = null; // 当使用body时,停止form的使用
|
||||
|
||||
@@ -739,7 +739,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param bodyBytes 主体
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest body(byte[] bodyBytes) {
|
||||
public HttpRequest body(final byte[] bodyBytes) {
|
||||
if (null != bodyBytes) {
|
||||
this.bodyBytes = bodyBytes;
|
||||
}
|
||||
@@ -754,7 +754,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param config 配置
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest setConfig(HttpConfig config) {
|
||||
public HttpRequest setConfig(final HttpConfig config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
@@ -773,7 +773,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see #setConnectionTimeout(int)
|
||||
* @see #setReadTimeout(int)
|
||||
*/
|
||||
public HttpRequest timeout(int milliseconds) {
|
||||
public HttpRequest timeout(final int milliseconds) {
|
||||
config.timeout(milliseconds);
|
||||
return this;
|
||||
}
|
||||
@@ -785,7 +785,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public HttpRequest setConnectionTimeout(int milliseconds) {
|
||||
public HttpRequest setConnectionTimeout(final int milliseconds) {
|
||||
config.setConnectionTimeout(milliseconds);
|
||||
return this;
|
||||
}
|
||||
@@ -797,7 +797,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public HttpRequest setReadTimeout(int milliseconds) {
|
||||
public HttpRequest setReadTimeout(final int milliseconds) {
|
||||
config.setReadTimeout(milliseconds);
|
||||
return this;
|
||||
}
|
||||
@@ -819,7 +819,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param isFollowRedirects 是否打开重定向
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest setFollowRedirects(boolean isFollowRedirects) {
|
||||
public HttpRequest setFollowRedirects(final boolean isFollowRedirects) {
|
||||
return setMaxRedirectCount(isFollowRedirects ? 2 : 0);
|
||||
}
|
||||
|
||||
@@ -831,7 +831,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public HttpRequest setMaxRedirectCount(int maxRedirectCount) {
|
||||
public HttpRequest setMaxRedirectCount(final int maxRedirectCount) {
|
||||
config.setMaxRedirectCount(maxRedirectCount);
|
||||
return this;
|
||||
}
|
||||
@@ -843,7 +843,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param hostnameVerifier HostnameVerifier
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest setHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
public HttpRequest setHostnameVerifier(final HostnameVerifier hostnameVerifier) {
|
||||
config.setHostnameVerifier(hostnameVerifier);
|
||||
return this;
|
||||
}
|
||||
@@ -856,7 +856,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.4.5
|
||||
*/
|
||||
public HttpRequest setHttpProxy(String host, int port) {
|
||||
public HttpRequest setHttpProxy(final String host, final int port) {
|
||||
config.setHttpProxy(host, port);
|
||||
return this;
|
||||
}
|
||||
@@ -867,7 +867,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param proxy 代理 {@link Proxy}
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest setProxy(Proxy proxy) {
|
||||
public HttpRequest setProxy(final Proxy proxy) {
|
||||
config.setProxy(proxy);
|
||||
return this;
|
||||
}
|
||||
@@ -880,7 +880,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param ssf SSLScketFactory
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest setSSLSocketFactory(SSLSocketFactory ssf) {
|
||||
public HttpRequest setSSLSocketFactory(final SSLSocketFactory ssf) {
|
||||
config.setSSLSocketFactory(ssf);
|
||||
return this;
|
||||
}
|
||||
@@ -901,7 +901,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see SSLUtil#createSSLContext(String)
|
||||
* @see #setSSLSocketFactory(SSLSocketFactory)
|
||||
*/
|
||||
public HttpRequest setSSLProtocol(String protocol) {
|
||||
public HttpRequest setSSLProtocol(final String protocol) {
|
||||
config.setSSLProtocol(protocol);
|
||||
return this;
|
||||
}
|
||||
@@ -914,7 +914,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.5.0
|
||||
*/
|
||||
public HttpRequest setRest(boolean isRest) {
|
||||
public HttpRequest setRest(final boolean isRest) {
|
||||
this.isRest = isRest;
|
||||
return this;
|
||||
}
|
||||
@@ -927,7 +927,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public HttpRequest setChunkedStreamingMode(int blockSize) {
|
||||
public HttpRequest setChunkedStreamingMode(final int blockSize) {
|
||||
config.setBlockSize(blockSize);
|
||||
return this;
|
||||
}
|
||||
@@ -940,7 +940,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @see #addRequestInterceptor(HttpInterceptor)
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public HttpRequest addInterceptor(HttpInterceptor<HttpRequest> interceptor) {
|
||||
public HttpRequest addInterceptor(final HttpInterceptor<HttpRequest> interceptor) {
|
||||
return addRequestInterceptor(interceptor);
|
||||
}
|
||||
|
||||
@@ -951,7 +951,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public HttpRequest addRequestInterceptor(HttpInterceptor<HttpRequest> interceptor) {
|
||||
public HttpRequest addRequestInterceptor(final HttpInterceptor<HttpRequest> interceptor) {
|
||||
config.addRequestInterceptor(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -963,7 +963,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public HttpRequest addResponseInterceptor(HttpInterceptor<HttpResponse> interceptor) {
|
||||
public HttpRequest addResponseInterceptor(final HttpInterceptor<HttpResponse> interceptor) {
|
||||
config.addResponseInterceptor(interceptor);
|
||||
return this;
|
||||
}
|
||||
@@ -997,7 +997,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param isAsync 是否异步
|
||||
* @return this
|
||||
*/
|
||||
public HttpResponse execute(boolean isAsync) {
|
||||
public HttpResponse execute(final boolean isAsync) {
|
||||
return doExecute(isAsync, config.requestInterceptors, config.responseInterceptors);
|
||||
}
|
||||
|
||||
@@ -1008,8 +1008,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param consumer 响应内容处理函数
|
||||
* @since 5.7.8
|
||||
*/
|
||||
public void then(Consumer<HttpResponse> consumer) {
|
||||
try (HttpResponse response = execute(true)) {
|
||||
public void then(final Consumer<HttpResponse> consumer) {
|
||||
try (final HttpResponse response = execute(true)) {
|
||||
consumer.accept(response);
|
||||
}
|
||||
}
|
||||
@@ -1024,7 +1024,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param password 密码
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest basicAuth(String username, String password) {
|
||||
public HttpRequest basicAuth(final String username, final String password) {
|
||||
return auth(HttpUtil.buildBasicAuth(username, password, charset));
|
||||
}
|
||||
|
||||
@@ -1039,7 +1039,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return this
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public HttpRequest basicProxyAuth(String username, String password) {
|
||||
public HttpRequest basicProxyAuth(final String username, final String password) {
|
||||
return proxyAuth(HttpUtil.buildBasicAuth(username, password, charset));
|
||||
}
|
||||
|
||||
@@ -1050,7 +1050,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public HttpRequest bearerAuth(String token) {
|
||||
public HttpRequest bearerAuth(final String token) {
|
||||
return auth("Bearer " + token);
|
||||
}
|
||||
|
||||
@@ -1061,7 +1061,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public HttpRequest auth(String content) {
|
||||
public HttpRequest auth(final String content) {
|
||||
header(Header.AUTHORIZATION, content, true);
|
||||
return this;
|
||||
}
|
||||
@@ -1073,14 +1073,14 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @return HttpRequest
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public HttpRequest proxyAuth(String content) {
|
||||
public HttpRequest proxyAuth(final String content) {
|
||||
header(Header.PROXY_AUTHORIZATION, content, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
final StringBuilder sb = StrUtil.builder();
|
||||
sb.append("Request Url: ").append(this.url.setCharset(this.charset)).append(StrUtil.CRLF);
|
||||
sb.append(super.toString());
|
||||
return sb.toString();
|
||||
@@ -1096,10 +1096,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param responseInterceptors 响应拦截器列表
|
||||
* @return this
|
||||
*/
|
||||
private HttpResponse doExecute(boolean isAsync, HttpInterceptor.Chain<HttpRequest> requestInterceptors,
|
||||
HttpInterceptor.Chain<HttpResponse> responseInterceptors) {
|
||||
private HttpResponse doExecute(final boolean isAsync, final HttpInterceptor.Chain<HttpRequest> requestInterceptors,
|
||||
final HttpInterceptor.Chain<HttpResponse> responseInterceptors) {
|
||||
if (null != requestInterceptors) {
|
||||
for (HttpInterceptor<HttpRequest> interceptor : requestInterceptors) {
|
||||
for (final HttpInterceptor<HttpRequest> interceptor : requestInterceptors) {
|
||||
interceptor.process(this);
|
||||
}
|
||||
}
|
||||
@@ -1121,7 +1121,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
|
||||
// 拦截响应
|
||||
if (null != responseInterceptors) {
|
||||
for (HttpInterceptor<HttpResponse> interceptor : responseInterceptors) {
|
||||
for (final HttpInterceptor<HttpResponse> interceptor : responseInterceptors) {
|
||||
interceptor.process(httpResponse);
|
||||
}
|
||||
}
|
||||
@@ -1195,13 +1195,13 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param isAsync 是否异步
|
||||
* @return {@link HttpResponse},无转发返回 {@code null}
|
||||
*/
|
||||
private HttpResponse sendRedirectIfPossible(boolean isAsync) {
|
||||
private HttpResponse sendRedirectIfPossible(final boolean isAsync) {
|
||||
// 手动实现重定向
|
||||
if (config.maxRedirectCount > 0) {
|
||||
int responseCode;
|
||||
final int responseCode;
|
||||
try {
|
||||
responseCode = httpConnection.responseCode();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
// 错误时静默关闭连接
|
||||
this.httpConnection.disconnectQuietly();
|
||||
throw new HttpException(e);
|
||||
@@ -1241,7 +1241,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
} else {
|
||||
this.httpConnection.connect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
// 异常时关闭连接
|
||||
this.httpConnection.disconnectQuietly();
|
||||
throw new IORuntimeException(e);
|
||||
@@ -1261,7 +1261,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
}
|
||||
|
||||
// Write的时候会优先使用body中的内容,write时自动关闭OutputStream
|
||||
RequestBody body;
|
||||
final RequestBody body;
|
||||
if (ArrayUtil.isNotEmpty(this.bodyBytes)) {
|
||||
body = BytesBody.create(this.bodyBytes);
|
||||
} else {
|
||||
@@ -1325,7 +1325,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @param value 属性值
|
||||
* @return this
|
||||
*/
|
||||
private HttpRequest putToForm(String name, Object value) {
|
||||
private HttpRequest putToForm(final String name, final Object value) {
|
||||
if (null == name || null == value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class HttpResource implements Resource, Serializable {
|
||||
* @param resource 资源,非空
|
||||
* @param contentType Content-Type类型,{@code null}表示不设置
|
||||
*/
|
||||
public HttpResource(Resource resource, String contentType) {
|
||||
public HttpResource(final Resource resource, final String contentType) {
|
||||
this.resource = Assert.notNull(resource, "Resource must be not null !");
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @param isIgnoreBody 是否忽略读取响应体
|
||||
* @since 3.1.2
|
||||
*/
|
||||
protected HttpResponse(HttpConnection httpConnection, HttpConfig config, Charset charset, boolean isAsync, boolean isIgnoreBody) {
|
||||
protected HttpResponse(final HttpConnection httpConnection, final HttpConfig config, final Charset charset, final boolean isAsync, final boolean isIgnoreBody) {
|
||||
this.httpConnection = httpConnection;
|
||||
this.config = config;
|
||||
this.charset = charset;
|
||||
@@ -201,10 +201,10 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return {@link HttpCookie}
|
||||
* @since 4.1.4
|
||||
*/
|
||||
public HttpCookie getCookie(String name) {
|
||||
List<HttpCookie> cookie = getCookies();
|
||||
public HttpCookie getCookie(final String name) {
|
||||
final List<HttpCookie> cookie = getCookies();
|
||||
if (null != cookie) {
|
||||
for (HttpCookie httpCookie : cookie) {
|
||||
for (final HttpCookie httpCookie : cookie) {
|
||||
if (httpCookie.getName().equals(name)) {
|
||||
return httpCookie;
|
||||
}
|
||||
@@ -220,8 +220,8 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return Cookie值
|
||||
* @since 4.1.4
|
||||
*/
|
||||
public String getCookieValue(String name) {
|
||||
HttpCookie cookie = getCookie(name);
|
||||
public String getCookieValue(final String name) {
|
||||
final HttpCookie cookie = getCookie(name);
|
||||
return (null == cookie) ? null : cookie.getValue();
|
||||
}
|
||||
// ---------------------------------------------------------------- Http Response Header end
|
||||
@@ -275,7 +275,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出bytes数
|
||||
* @since 3.3.2
|
||||
*/
|
||||
public long writeBody(OutputStream out, boolean isCloseOut, StreamProgress streamProgress) {
|
||||
public long writeBody(final OutputStream out, final boolean isCloseOut, final StreamProgress streamProgress) {
|
||||
Assert.notNull(out, "[out] must be not null!");
|
||||
final long contentLength = contentLength();
|
||||
try {
|
||||
@@ -298,7 +298,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出bytes数
|
||||
* @since 3.3.2
|
||||
*/
|
||||
public long writeBody(File targetFileOrDir, StreamProgress streamProgress) {
|
||||
public long writeBody(final File targetFileOrDir, final StreamProgress streamProgress) {
|
||||
Assert.notNull(targetFileOrDir, "[targetFileOrDir] must be not null!");
|
||||
|
||||
final File outFile = completeFileNameFromHeader(targetFileOrDir);
|
||||
@@ -318,7 +318,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出bytes数
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public long writeBody(File targetFileOrDir, String tempFileSuffix, StreamProgress streamProgress) {
|
||||
public long writeBody(final File targetFileOrDir, String tempFileSuffix, final StreamProgress streamProgress) {
|
||||
Assert.notNull(targetFileOrDir, "[targetFileOrDir] must be not null!");
|
||||
|
||||
File outFile = completeFileNameFromHeader(targetFileOrDir);
|
||||
@@ -337,12 +337,12 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
// 临时文件
|
||||
outFile = new File(outFile.getParentFile(), tempFileName);
|
||||
|
||||
long length;
|
||||
final long length;
|
||||
try {
|
||||
length = writeBody(outFile, streamProgress);
|
||||
// 重命名下载好的临时文件
|
||||
FileUtil.rename(outFile, fileName, true);
|
||||
} catch (Throwable e) {
|
||||
} catch (final Throwable e) {
|
||||
// 异常则删除临时文件
|
||||
FileUtil.del(outFile);
|
||||
throw new HttpException(e);
|
||||
@@ -360,7 +360,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出的文件
|
||||
* @since 5.6.4
|
||||
*/
|
||||
public File writeBodyForFile(File targetFileOrDir, StreamProgress streamProgress) {
|
||||
public File writeBodyForFile(final File targetFileOrDir, final StreamProgress streamProgress) {
|
||||
Assert.notNull(targetFileOrDir, "[targetFileOrDir] must be not null!");
|
||||
|
||||
final File outFile = completeFileNameFromHeader(targetFileOrDir);
|
||||
@@ -378,7 +378,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出bytes数
|
||||
* @since 3.3.2
|
||||
*/
|
||||
public long writeBody(File targetFileOrDir) {
|
||||
public long writeBody(final File targetFileOrDir) {
|
||||
return writeBody(targetFileOrDir, null);
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return 写出bytes数
|
||||
* @since 3.3.2
|
||||
*/
|
||||
public long writeBody(String targetFileOrDir) {
|
||||
public long writeBody(final String targetFileOrDir) {
|
||||
return writeBody(FileUtil.file(targetFileOrDir));
|
||||
}
|
||||
// ---------------------------------------------------------------- Body end
|
||||
@@ -406,9 +406,9 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
final StringBuilder sb = StrUtil.builder();
|
||||
sb.append("Response Headers: ").append(StrUtil.CRLF);
|
||||
for (Entry<String, List<String>> entry : this.headers.entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : this.headers.entrySet()) {
|
||||
sb.append(" ").append(entry).append(StrUtil.CRLF);
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @return File 保存的文件
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public File completeFileNameFromHeader(File targetFileOrDir) {
|
||||
public File completeFileNameFromHeader(final File targetFileOrDir) {
|
||||
if (false == targetFileOrDir.isDirectory()) {
|
||||
// 非目录直接返回
|
||||
return targetFileOrDir;
|
||||
@@ -466,7 +466,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
private HttpResponse initWithDisconnect() throws HttpException {
|
||||
try {
|
||||
init();
|
||||
} catch (HttpException e) {
|
||||
} catch (final HttpException e) {
|
||||
this.httpConnection.disconnectQuietly();
|
||||
throw e;
|
||||
}
|
||||
@@ -490,7 +490,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
// 获取响应状态码
|
||||
try {
|
||||
this.status = httpConnection.responseCode();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
if (false == (e instanceof FileNotFoundException)) {
|
||||
throw new HttpException(e);
|
||||
}
|
||||
@@ -501,7 +501,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
// 读取响应头信息
|
||||
try {
|
||||
this.headers = httpConnection.headers();
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// ignore
|
||||
// StaticLog.warn(e, e.getMessage());
|
||||
}
|
||||
@@ -540,7 +540,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
// 非同步状态转为同步状态
|
||||
try {
|
||||
this.readBody(this.in);
|
||||
} catch (IORuntimeException e) {
|
||||
} catch (final IORuntimeException e) {
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (e.getCause() instanceof FileNotFoundException) {
|
||||
// 服务器无返回内容,忽略之
|
||||
@@ -562,7 +562,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @param in 输入流
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void readBody(InputStream in) throws IORuntimeException {
|
||||
private void readBody(final InputStream in) throws IORuntimeException {
|
||||
if (ignoreBody) {
|
||||
return;
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
* @param isIgnoreEOFError 是否忽略响应读取时可能的EOF异常
|
||||
* @return 拷贝长度
|
||||
*/
|
||||
private static long copyBody(InputStream in, OutputStream out, long contentLength, StreamProgress streamProgress, boolean isIgnoreEOFError) {
|
||||
private static long copyBody(final InputStream in, final OutputStream out, final long contentLength, final StreamProgress streamProgress, final boolean isIgnoreEOFError) {
|
||||
if (null == out) {
|
||||
throw new NullPointerException("[out] is null!");
|
||||
}
|
||||
@@ -593,7 +593,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
|
||||
long copyLength = -1;
|
||||
try {
|
||||
copyLength = IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE, contentLength, streamProgress);
|
||||
} catch (IORuntimeException e) {
|
||||
} catch (final IORuntimeException e) {
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (isIgnoreEOFError
|
||||
&& (e.getCause() instanceof EOFException || StrUtil.containsIgnoreCase(e.getMessage(), "Premature EOF"))) {
|
||||
|
||||
@@ -210,7 +210,7 @@ public class HttpStatus {
|
||||
* @return 是否为重定向状态码
|
||||
* @since 5.6.3
|
||||
*/
|
||||
public static boolean isRedirected(int responseCode){
|
||||
public static boolean isRedirected(final int responseCode){
|
||||
return responseCode == HTTP_MOVED_PERM
|
||||
|| responseCode == HTTP_MOVED_TEMP
|
||||
|| responseCode == HTTP_SEE_OTHER
|
||||
|
||||
@@ -51,7 +51,7 @@ public class HttpUtil {
|
||||
* @param url URL
|
||||
* @return 是否https
|
||||
*/
|
||||
public static boolean isHttps(String url) {
|
||||
public static boolean isHttps(final String url) {
|
||||
return url.toLowerCase().startsWith("https:");
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class HttpUtil {
|
||||
* @return 是否http
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static boolean isHttp(String url) {
|
||||
public static boolean isHttp(final String url) {
|
||||
return url.toLowerCase().startsWith("http:");
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class HttpUtil {
|
||||
* @return {@link HttpRequest}
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static HttpRequest createRequest(Method method, String url) {
|
||||
public static HttpRequest createRequest(final Method method, final String url) {
|
||||
return HttpRequest.of(url).method(method);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class HttpUtil {
|
||||
* @return {@link HttpRequest}
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static HttpRequest createGet(String url) {
|
||||
public static HttpRequest createGet(final String url) {
|
||||
return createGet(url, false);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class HttpUtil {
|
||||
* @return {@link HttpRequest}
|
||||
* @since 5.6.4
|
||||
*/
|
||||
public static HttpRequest createGet(String url, boolean isFollowRedirects) {
|
||||
public static HttpRequest createGet(final String url, final boolean isFollowRedirects) {
|
||||
return HttpRequest.get(url).setFollowRedirects(isFollowRedirects);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class HttpUtil {
|
||||
* @return {@link HttpRequest}
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static HttpRequest createPost(String url) {
|
||||
public static HttpRequest createPost(final String url) {
|
||||
return HttpRequest.post(url);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class HttpUtil {
|
||||
* @param customCharset 自定义请求字符集,如果字符集获取不到,使用此字符集
|
||||
* @return 返回内容,如果只检查状态码,正常只返回 "",不正常返回 null
|
||||
*/
|
||||
public static String get(String urlString, Charset customCharset) {
|
||||
public static String get(final String urlString, final Charset customCharset) {
|
||||
return HttpRequest.get(urlString).charset(customCharset).execute().body();
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class HttpUtil {
|
||||
* @param urlString 网址
|
||||
* @return 返回内容,如果只检查状态码,正常只返回 "",不正常返回 null
|
||||
*/
|
||||
public static String get(String urlString) {
|
||||
public static String get(final String urlString) {
|
||||
return get(urlString, HttpGlobalConfig.getTimeout());
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class HttpUtil {
|
||||
* @return 返回内容,如果只检查状态码,正常只返回 "",不正常返回 null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static String get(String urlString, int timeout) {
|
||||
public static String get(final String urlString, final int timeout) {
|
||||
return HttpRequest.get(urlString).timeout(timeout).execute().body();
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class HttpUtil {
|
||||
* @param paramMap post表单数据
|
||||
* @return 返回数据
|
||||
*/
|
||||
public static String get(String urlString, Map<String, Object> paramMap) {
|
||||
public static String get(final String urlString, final Map<String, Object> paramMap) {
|
||||
return HttpRequest.get(urlString).form(paramMap).execute().body();
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class HttpUtil {
|
||||
* @return 返回数据
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static String get(String urlString, Map<String, Object> paramMap, int timeout) {
|
||||
public static String get(final String urlString, final Map<String, Object> paramMap, final int timeout) {
|
||||
return HttpRequest.get(urlString).form(paramMap).timeout(timeout).execute().body();
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public class HttpUtil {
|
||||
* @param paramMap post表单数据
|
||||
* @return 返回数据
|
||||
*/
|
||||
public static String post(String urlString, Map<String, Object> paramMap) {
|
||||
public static String post(final String urlString, final Map<String, Object> paramMap) {
|
||||
return post(urlString, paramMap, HttpGlobalConfig.getTimeout());
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class HttpUtil {
|
||||
* @return 返回数据
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static String post(String urlString, Map<String, Object> paramMap, int timeout) {
|
||||
public static String post(final String urlString, final Map<String, Object> paramMap, final int timeout) {
|
||||
return HttpRequest.post(urlString).form(paramMap).timeout(timeout).execute().body();
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class HttpUtil {
|
||||
* @param body post表单数据
|
||||
* @return 返回数据
|
||||
*/
|
||||
public static String post(String urlString, String body) {
|
||||
public static String post(final String urlString, final String body) {
|
||||
return post(urlString, body, HttpGlobalConfig.getTimeout());
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public class HttpUtil {
|
||||
* @return 返回数据
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static String post(String urlString, String body, int timeout) {
|
||||
public static String post(final String urlString, final String body, final int timeout) {
|
||||
return HttpRequest.post(urlString).timeout(timeout).body(body).execute().body();
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public class HttpUtil {
|
||||
* @param customCharsetName 自定义的字符集
|
||||
* @return 文本
|
||||
*/
|
||||
public static String downloadString(String url, String customCharsetName) {
|
||||
public static String downloadString(final String url, final String customCharsetName) {
|
||||
return downloadString(url, CharsetUtil.charset(customCharsetName), null);
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public class HttpUtil {
|
||||
* @param customCharset 自定义的字符集,可以使用{@link CharsetUtil#charset} 方法转换
|
||||
* @return 文本
|
||||
*/
|
||||
public static String downloadString(String url, Charset customCharset) {
|
||||
public static String downloadString(final String url, final Charset customCharset) {
|
||||
return downloadString(url, customCharset, null);
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public class HttpUtil {
|
||||
* @param streamPress 进度条 {@link StreamProgress}
|
||||
* @return 文本
|
||||
*/
|
||||
public static String downloadString(String url, Charset customCharset, StreamProgress streamPress) {
|
||||
public static String downloadString(final String url, final Charset customCharset, final StreamProgress streamPress) {
|
||||
return HttpDownloader.downloadString(url, customCharset, streamPress);
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ public class HttpUtil {
|
||||
* @param dest 目标文件或目录,当为目录时,取URL中的文件名,取不到使用编码后的URL做为文件名
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long downloadFile(String url, String dest) {
|
||||
public static long downloadFile(final String url, final String dest) {
|
||||
return downloadFile(url, FileUtil.file(dest));
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ public class HttpUtil {
|
||||
* @param destFile 目标文件或目录,当为目录时,取URL中的文件名,取不到使用编码后的URL做为文件名
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long downloadFile(String url, File destFile) {
|
||||
public static long downloadFile(final String url, final File destFile) {
|
||||
return downloadFile(url, destFile, null);
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class HttpUtil {
|
||||
* @return 文件大小
|
||||
* @since 4.0.4
|
||||
*/
|
||||
public static long downloadFile(String url, File destFile, int timeout) {
|
||||
public static long downloadFile(final String url, final File destFile, final int timeout) {
|
||||
return downloadFile(url, destFile, timeout, null);
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ public class HttpUtil {
|
||||
* @param streamProgress 进度条
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long downloadFile(String url, File destFile, StreamProgress streamProgress) {
|
||||
public static long downloadFile(final String url, final File destFile, final StreamProgress streamProgress) {
|
||||
return downloadFile(url, destFile, -1, streamProgress);
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ public class HttpUtil {
|
||||
* @return 文件大小
|
||||
* @since 4.0.4
|
||||
*/
|
||||
public static long downloadFile(String url, File destFile, int timeout, StreamProgress streamProgress) {
|
||||
public static long downloadFile(final String url, final File destFile, final int timeout, final StreamProgress streamProgress) {
|
||||
return HttpDownloader.downloadFile(url, destFile, timeout, streamProgress);
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ public class HttpUtil {
|
||||
* @return 下载的文件对象
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static File downloadFileFromUrl(String url, String dest) {
|
||||
public static File downloadFileFromUrl(final String url, final String dest) {
|
||||
return downloadFileFromUrl(url, FileUtil.file(dest));
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ public class HttpUtil {
|
||||
* @return 下载的文件对象
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static File downloadFileFromUrl(String url, File destFile) {
|
||||
public static File downloadFileFromUrl(final String url, final File destFile) {
|
||||
return downloadFileFromUrl(url, destFile, null);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public class HttpUtil {
|
||||
* @return 下载的文件对象
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static File downloadFileFromUrl(String url, File destFile, int timeout) {
|
||||
public static File downloadFileFromUrl(final String url, final File destFile, final int timeout) {
|
||||
return downloadFileFromUrl(url, destFile, timeout, null);
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ public class HttpUtil {
|
||||
* @return 下载的文件对象
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static File downloadFileFromUrl(String url, File destFile, StreamProgress streamProgress) {
|
||||
public static File downloadFileFromUrl(final String url, final File destFile, final StreamProgress streamProgress) {
|
||||
return downloadFileFromUrl(url, destFile, -1, streamProgress);
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public class HttpUtil {
|
||||
* @return 下载的文件对象
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static File downloadFileFromUrl(String url, File destFile, int timeout, StreamProgress streamProgress) {
|
||||
public static File downloadFileFromUrl(final String url, final File destFile, final int timeout, final StreamProgress streamProgress) {
|
||||
return HttpDownloader.downloadForFile(url, destFile, timeout, streamProgress);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public class HttpUtil {
|
||||
* @param isCloseOut 是否关闭输出流
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long download(String url, OutputStream out, boolean isCloseOut) {
|
||||
public static long download(final String url, final OutputStream out, final boolean isCloseOut) {
|
||||
return download(url, out, isCloseOut, null);
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ public class HttpUtil {
|
||||
* @param streamProgress 进度条
|
||||
* @return 文件大小
|
||||
*/
|
||||
public static long download(String url, OutputStream out, boolean isCloseOut, StreamProgress streamProgress) {
|
||||
public static long download(final String url, final OutputStream out, final boolean isCloseOut, final StreamProgress streamProgress) {
|
||||
return HttpDownloader.download(url, out, isCloseOut, streamProgress);
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ public class HttpUtil {
|
||||
* @return 文件数据
|
||||
* @since 5.3.6
|
||||
*/
|
||||
public static byte[] downloadBytes(String url) {
|
||||
public static byte[] downloadBytes(final String url) {
|
||||
return HttpDownloader.downloadBytes(url);
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ public class HttpUtil {
|
||||
* @param paramMap 表单数据
|
||||
* @return url参数
|
||||
*/
|
||||
public static String toParams(Map<String, ?> paramMap) {
|
||||
public static String toParams(final Map<String, ?> paramMap) {
|
||||
return toParams(paramMap, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ public class HttpUtil {
|
||||
* @return url参数
|
||||
* @see #toParams(Map, Charset, boolean)
|
||||
*/
|
||||
public static String toParams(Map<String, ?> paramMap, Charset charset) {
|
||||
public static String toParams(final Map<String, ?> paramMap, final Charset charset) {
|
||||
return toParams(paramMap, charset, false);
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ public class HttpUtil {
|
||||
* @return url参数
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public static String toParams(Map<String, ?> paramMap, Charset charset, boolean isFormUrlEncoded) {
|
||||
public static String toParams(final Map<String, ?> paramMap, final Charset charset, final boolean isFormUrlEncoded) {
|
||||
return UrlQuery.of(paramMap, isFormUrlEncoded).build(charset);
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ public class HttpUtil {
|
||||
* @return 编码后的url和参数
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String encodeParams(String urlWithParams, Charset charset) {
|
||||
public static String encodeParams(final String urlWithParams, final Charset charset) {
|
||||
if (StrUtil.isBlank(urlWithParams)) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
@@ -524,7 +524,7 @@ public class HttpUtil {
|
||||
* @return 标准化的参数字符串
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static String normalizeParams(String paramPart, Charset charset) {
|
||||
public static String normalizeParams(final String paramPart, final Charset charset) {
|
||||
if(StrUtil.isEmpty(paramPart)){
|
||||
return paramPart;
|
||||
}
|
||||
@@ -570,7 +570,7 @@ public class HttpUtil {
|
||||
}
|
||||
|
||||
// 以&结尾则去除之
|
||||
int lastIndex = builder.length() - 1;
|
||||
final int lastIndex = builder.length() - 1;
|
||||
if ('&' == builder.charAt(lastIndex)) {
|
||||
builder.delTo(lastIndex);
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public class HttpUtil {
|
||||
* @return 参数Map
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static Map<String, String> decodeParamMap(String paramsStr, Charset charset) {
|
||||
public static Map<String, String> decodeParamMap(final String paramsStr, final Charset charset) {
|
||||
final Map<CharSequence, CharSequence> queryMap = UrlQuery.of(paramsStr, charset).getQueryMap();
|
||||
if (MapUtil.isEmpty(queryMap)) {
|
||||
return MapUtil.empty();
|
||||
@@ -600,7 +600,7 @@ public class HttpUtil {
|
||||
* @param charset 字符集
|
||||
* @return 参数Map
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, String charset) {
|
||||
public static Map<String, List<String>> decodeParams(final String paramsStr, final String charset) {
|
||||
return decodeParams(paramsStr, CharsetUtil.charset(charset));
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ public class HttpUtil {
|
||||
* @return 参数Map
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, Charset charset) {
|
||||
public static Map<String, List<String>> decodeParams(final String paramsStr, final Charset charset) {
|
||||
final Map<CharSequence, CharSequence> queryMap = UrlQuery.of(paramsStr, charset).getQueryMap();
|
||||
if (MapUtil.isEmpty(queryMap)) {
|
||||
return MapUtil.empty();
|
||||
@@ -637,7 +637,7 @@ public class HttpUtil {
|
||||
* @param isEncodeParams 是否对键和值做转义处理
|
||||
* @return 合成后的URL
|
||||
*/
|
||||
public static String urlWithForm(String url, Map<String, Object> form, Charset charset, boolean isEncodeParams) {
|
||||
public static String urlWithForm(String url, final Map<String, Object> form, final Charset charset, final boolean isEncodeParams) {
|
||||
if (isEncodeParams && StrUtil.contains(url, '?')) {
|
||||
// 在需要编码的情况下,如果url中已经有部分参数,则编码之
|
||||
url = encodeParams(url, charset);
|
||||
@@ -656,7 +656,7 @@ public class HttpUtil {
|
||||
* @param isEncode 是否对键和值做转义处理
|
||||
* @return 拼接后的字符串
|
||||
*/
|
||||
public static String urlWithForm(String url, String queryString, Charset charset, boolean isEncode) {
|
||||
public static String urlWithForm(final String url, final String queryString, final Charset charset, final boolean isEncode) {
|
||||
if (StrUtil.isBlank(queryString)) {
|
||||
// 无额外参数
|
||||
if (StrUtil.contains(url, '?')) {
|
||||
@@ -668,7 +668,7 @@ public class HttpUtil {
|
||||
|
||||
// 始终有参数
|
||||
final StrBuilder urlBuilder = StrBuilder.create(url.length() + queryString.length() + 16);
|
||||
int qmIndex = url.indexOf('?');
|
||||
final int qmIndex = url.indexOf('?');
|
||||
if (qmIndex > 0) {
|
||||
// 原URL带参数,则对这部分参数单独编码(如果选项为进行编码)
|
||||
urlBuilder.append(isEncode ? encodeParams(url, charset) : url);
|
||||
@@ -695,7 +695,7 @@ public class HttpUtil {
|
||||
* @param conn HTTP连接对象
|
||||
* @return 字符集
|
||||
*/
|
||||
public static String getCharset(HttpURLConnection conn) {
|
||||
public static String getCharset(final HttpURLConnection conn) {
|
||||
if (conn == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -710,7 +710,7 @@ public class HttpUtil {
|
||||
* @return 字符集
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static String getCharset(String contentType) {
|
||||
public static String getCharset(final String contentType) {
|
||||
if (StrUtil.isBlank(contentType)) {
|
||||
return null;
|
||||
}
|
||||
@@ -726,7 +726,7 @@ public class HttpUtil {
|
||||
* @param isGetCharsetFromContent 是否从返回内容中获得编码信息
|
||||
* @return 内容
|
||||
*/
|
||||
public static String getString(InputStream in, Charset charset, boolean isGetCharsetFromContent) {
|
||||
public static String getString(final InputStream in, final Charset charset, final boolean isGetCharsetFromContent) {
|
||||
final byte[] contentBytes = IoUtil.readBytes(in);
|
||||
return getString(contentBytes, charset, isGetCharsetFromContent);
|
||||
}
|
||||
@@ -740,7 +740,7 @@ public class HttpUtil {
|
||||
* @param isGetCharsetFromContent 是否从返回内容中获得编码信息
|
||||
* @return 内容
|
||||
*/
|
||||
public static String getString(byte[] contentBytes, Charset charset, boolean isGetCharsetFromContent) {
|
||||
public static String getString(final byte[] contentBytes, Charset charset, final boolean isGetCharsetFromContent) {
|
||||
if (null == contentBytes) {
|
||||
return null;
|
||||
}
|
||||
@@ -755,7 +755,7 @@ public class HttpUtil {
|
||||
Charset charsetInContent = null;
|
||||
try {
|
||||
charsetInContent = Charset.forName(charsetInContentStr);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
if (StrUtil.containsIgnoreCase(charsetInContentStr, "utf-8") || StrUtil.containsIgnoreCase(charsetInContentStr, "utf8")) {
|
||||
charsetInContent = CharsetUtil.UTF_8;
|
||||
} else if (StrUtil.containsIgnoreCase(charsetInContentStr, "gbk")) {
|
||||
@@ -780,7 +780,7 @@ public class HttpUtil {
|
||||
* @see FileUtil#getMimeType(String)
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public static String getMimeType(String filePath, String defaultValue) {
|
||||
public static String getMimeType(final String filePath, final String defaultValue) {
|
||||
return ObjUtil.defaultIfNull(getMimeType(filePath), defaultValue);
|
||||
}
|
||||
|
||||
@@ -791,7 +791,7 @@ public class HttpUtil {
|
||||
* @return MimeType
|
||||
* @see FileUtil#getMimeType(String)
|
||||
*/
|
||||
public static String getMimeType(String filePath) {
|
||||
public static String getMimeType(final String filePath) {
|
||||
return FileUtil.getMimeType(filePath);
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ public class HttpUtil {
|
||||
* @see ContentType#get(String)
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static String getContentTypeByRequestBody(String body) {
|
||||
public static String getContentTypeByRequestBody(final String body) {
|
||||
final ContentType contentType = ContentType.get(body);
|
||||
return (null == contentType) ? null : contentType.toString();
|
||||
}
|
||||
@@ -820,7 +820,7 @@ public class HttpUtil {
|
||||
* @return {@link SimpleServer}
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static SimpleServer createServer(int port) {
|
||||
public static SimpleServer createServer(final int port) {
|
||||
return new SimpleServer(port);
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ public class HttpUtil {
|
||||
* @return 密码验证信息
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public static String buildBasicAuth(String username, String password, Charset charset) {
|
||||
public static String buildBasicAuth(final String username, final String password, final Charset charset) {
|
||||
final String data = username.concat(":").concat(password);
|
||||
return "Basic " + Base64.encode(data, charset);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
* @param out HTTP写出流
|
||||
* @param charset 编码
|
||||
*/
|
||||
public MultipartOutputStream(OutputStream out, Charset charset) {
|
||||
public MultipartOutputStream(final OutputStream out, final Charset charset) {
|
||||
this(out, charset, HttpGlobalConfig.getBoundary());
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
* @param boundary 边界符
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public MultipartOutputStream(OutputStream out, Charset charset, String boundary) {
|
||||
public MultipartOutputStream(final OutputStream out, final Charset charset, final String boundary) {
|
||||
this.out = out;
|
||||
this.charset = charset;
|
||||
this.boundary = boundary;
|
||||
@@ -80,10 +80,10 @@ public class MultipartOutputStream extends OutputStream {
|
||||
* @return this
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public MultipartOutputStream write(String formFieldName, Object value) throws IORuntimeException {
|
||||
public MultipartOutputStream write(final String formFieldName, final Object value) throws IORuntimeException {
|
||||
// 多资源
|
||||
if (value instanceof MultiResource) {
|
||||
for (Resource subResource : (MultiResource) value) {
|
||||
for (final Resource subResource : (MultiResource) value) {
|
||||
write(formFieldName, subResource);
|
||||
}
|
||||
return this;
|
||||
@@ -104,7 +104,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
public void write(final int b) throws IOException {
|
||||
this.out.write(b);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
* @param resource 资源
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void appendResource(String formFieldName, Resource resource) throws IORuntimeException {
|
||||
private void appendResource(final String formFieldName, final Resource resource) throws IORuntimeException {
|
||||
final String fileName = resource.getName();
|
||||
|
||||
// Content-Disposition
|
||||
@@ -179,7 +179,7 @@ public class MultipartOutputStream extends OutputStream {
|
||||
*
|
||||
* @param objs 写出的对象(转换为字符串)
|
||||
*/
|
||||
private void write(Object... objs) {
|
||||
private void write(final Object... objs) {
|
||||
IoUtil.write(this, this.charset, false, objs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class BytesBody implements RequestBody {
|
||||
* @param content body内容,编码后
|
||||
* @return BytesBody
|
||||
*/
|
||||
public static BytesBody create(byte[] content){
|
||||
public static BytesBody create(final byte[] content){
|
||||
return new BytesBody(content);
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ public class BytesBody implements RequestBody {
|
||||
*
|
||||
* @param content Body内容,编码后
|
||||
*/
|
||||
public BytesBody(byte[] content) {
|
||||
public BytesBody(final byte[] content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) {
|
||||
public void write(final OutputStream out) {
|
||||
IoUtil.write(out, false, content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class FormUrlEncodedBody extends BytesBody {
|
||||
* @param charset 编码
|
||||
* @return FormUrlEncodedBody
|
||||
*/
|
||||
public static FormUrlEncodedBody create(Map<String, Object> form, Charset charset) {
|
||||
public static FormUrlEncodedBody create(final Map<String, Object> form, final Charset charset) {
|
||||
return new FormUrlEncodedBody(form, charset);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FormUrlEncodedBody extends BytesBody {
|
||||
* @param form 表单
|
||||
* @param charset 编码
|
||||
*/
|
||||
public FormUrlEncodedBody(Map<String, Object> form, Charset charset) {
|
||||
public FormUrlEncodedBody(final Map<String, Object> form, final Charset charset) {
|
||||
super(StrUtil.bytes(UrlQuery.of(form, true).build(charset), charset));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MultipartBody implements RequestBody {
|
||||
* @param charset 编码
|
||||
* @return MultipartBody
|
||||
*/
|
||||
public static MultipartBody create(Map<String, Object> form, Charset charset) {
|
||||
public static MultipartBody create(final Map<String, Object> form, final Charset charset) {
|
||||
return new MultipartBody(form, charset);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class MultipartBody implements RequestBody {
|
||||
* @param form 表单
|
||||
* @param charset 编码
|
||||
*/
|
||||
public MultipartBody(Map<String, Object> form, Charset charset) {
|
||||
public MultipartBody(final Map<String, Object> form, final Charset charset) {
|
||||
this.form = form;
|
||||
this.charset = charset;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class MultipartBody implements RequestBody {
|
||||
* @param out out流
|
||||
*/
|
||||
@Override
|
||||
public void write(OutputStream out) {
|
||||
public void write(final OutputStream out) {
|
||||
final MultipartOutputStream stream = new MultipartOutputStream(out, this.charset, this.boundary);
|
||||
if (MapUtil.isNotEmpty(this.form)) {
|
||||
this.form.forEach(stream::write);
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface RequestBody {
|
||||
* @param out {@link OutputStream}
|
||||
* @since 5.7.17
|
||||
*/
|
||||
default void writeClose(OutputStream out) {
|
||||
default void writeClose(final OutputStream out) {
|
||||
try {
|
||||
write(out);
|
||||
} finally {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class GlobalCookieManager {
|
||||
*
|
||||
* @param customCookieManager 自定义的{@link CookieManager}
|
||||
*/
|
||||
public static void setCookieManager(CookieManager customCookieManager) {
|
||||
public static void setCookieManager(final CookieManager customCookieManager) {
|
||||
cookieManager = customCookieManager;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GlobalCookieManager {
|
||||
* @return Cookie信息列表
|
||||
* @since 4.6.9
|
||||
*/
|
||||
public static List<HttpCookie> getCookies(HttpConnection conn){
|
||||
public static List<HttpCookie> getCookies(final HttpConnection conn){
|
||||
return cookieManager.getCookieStore().get(getURI(conn));
|
||||
}
|
||||
|
||||
@@ -61,16 +61,16 @@ public class GlobalCookieManager {
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void add(HttpConnection conn) {
|
||||
public static void add(final HttpConnection conn) {
|
||||
if(null == cookieManager) {
|
||||
// 全局Cookie管理器关闭
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, List<String>> cookieHeader;
|
||||
final Map<String, List<String>> cookieHeader;
|
||||
try {
|
||||
cookieHeader = cookieManager.get(getURI(conn), new HashMap<>(0));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class GlobalCookieManager {
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void store(HttpConnection conn) {
|
||||
public static void store(final HttpConnection conn) {
|
||||
if(null == cookieManager) {
|
||||
// 全局Cookie管理器关闭
|
||||
return;
|
||||
@@ -92,7 +92,7 @@ public class GlobalCookieManager {
|
||||
|
||||
try {
|
||||
cookieManager.put(getURI(conn), conn.headers());
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class GlobalCookieManager {
|
||||
* @param conn HttpConnection
|
||||
* @return URI
|
||||
*/
|
||||
private static URI getURI(HttpConnection conn){
|
||||
private static URI getURI(final HttpConnection conn){
|
||||
return URLUtil.toURI(conn.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 线程隔离的Cookie存储。多线程环境下Cookie隔离使用,防止Cookie覆盖<br>
|
||||
*
|
||||
*
|
||||
* 见:https://stackoverflow.com/questions/16305486/cookiemanager-for-multiple-threads
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.1.18
|
||||
*/
|
||||
@@ -26,7 +26,7 @@ public class ThreadLocalCookieStore implements CookieStore {
|
||||
|
||||
/**
|
||||
* 获取本线程下的CookieStore
|
||||
*
|
||||
*
|
||||
* @return CookieStore
|
||||
*/
|
||||
public CookieStore getCookieStore() {
|
||||
@@ -35,7 +35,7 @@ public class ThreadLocalCookieStore implements CookieStore {
|
||||
|
||||
/**
|
||||
* 移除当前线程的Cookie
|
||||
*
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public ThreadLocalCookieStore removeCurrent() {
|
||||
@@ -44,12 +44,12 @@ public class ThreadLocalCookieStore implements CookieStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(URI uri, HttpCookie cookie) {
|
||||
public void add(final URI uri, final HttpCookie cookie) {
|
||||
getCookieStore().add(uri, cookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HttpCookie> get(URI uri) {
|
||||
public List<HttpCookie> get(final URI uri) {
|
||||
return getCookieStore().get(uri);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ThreadLocalCookieStore implements CookieStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(URI uri, HttpCookie cookie) {
|
||||
public boolean remove(final URI uri, final HttpCookie cookie) {
|
||||
return getCookieStore().remove(uri, cookie);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class HttpServerBase implements Closeable {
|
||||
*
|
||||
* @param httpExchange {@link HttpExchange}
|
||||
*/
|
||||
public HttpServerBase(HttpExchange httpExchange) {
|
||||
public HttpServerBase(final HttpExchange httpExchange) {
|
||||
this.httpExchange = httpExchange;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
*
|
||||
* @param httpExchange {@link HttpExchange}
|
||||
*/
|
||||
public HttpServerRequest(HttpExchange httpExchange) {
|
||||
public HttpServerRequest(final HttpExchange httpExchange) {
|
||||
super(httpExchange);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param headerKey 头信息的KEY
|
||||
* @return header值
|
||||
*/
|
||||
public String getHeader(Header headerKey) {
|
||||
public String getHeader(final Header headerKey) {
|
||||
return getHeader(headerKey.toString());
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param headerKey 头信息的KEY
|
||||
* @return header值
|
||||
*/
|
||||
public String getHeader(String headerKey) {
|
||||
public String getHeader(final String headerKey) {
|
||||
return getHeaders().getFirst(headerKey);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param charset 字符集
|
||||
* @return header值
|
||||
*/
|
||||
public String getHeader(String headerKey, Charset charset) {
|
||||
public String getHeader(final String headerKey, final Charset charset) {
|
||||
final String header = getHeader(headerKey);
|
||||
if (null != header) {
|
||||
return CharsetUtil.convert(header, CharsetUtil.ISO_8859_1, charset);
|
||||
@@ -235,7 +235,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param cookieName Cookie名
|
||||
* @return HttpCookie对象
|
||||
*/
|
||||
public HttpCookie getCookie(String cookieName) {
|
||||
public HttpCookie getCookie(final String cookieName) {
|
||||
return getCookieMap().get(cookieName);
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param charset 编码
|
||||
* @return 请求
|
||||
*/
|
||||
public String getBody(Charset charset) {
|
||||
public String getBody(final Charset charset) {
|
||||
return StrUtil.str(getBodyBytes(), charset);
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public String getParam(String name){
|
||||
public String getParam(final String name){
|
||||
return getParams().get(name, 0);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @return 参数值
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public List<String> getParams(String name){
|
||||
public List<String> getParams(final String name){
|
||||
return getParams().get(name);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @param otherHeaderNames 其他自定义头文件,通常在Http服务器(例如Nginx)中配置
|
||||
* @return IP地址
|
||||
*/
|
||||
public String getClientIP(String... otherHeaderNames) {
|
||||
public String getClientIP(final String... otherHeaderNames) {
|
||||
String[] headers = {"X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"};
|
||||
if (ArrayUtil.isNotEmpty(otherHeaderNames)) {
|
||||
headers = ArrayUtil.addAll(headers, otherHeaderNames);
|
||||
@@ -391,9 +391,9 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @return IP地址
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public String getClientIPByHeader(String... headerNames) {
|
||||
public String getClientIPByHeader(final String... headerNames) {
|
||||
String ip;
|
||||
for (String header : headerNames) {
|
||||
for (final String header : headerNames) {
|
||||
ip = getHeader(header);
|
||||
if (false == NetUtil.isUnknown(ip)) {
|
||||
return NetUtil.getMultistageReverseProxyIp(ip);
|
||||
@@ -428,11 +428,11 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.3.0
|
||||
*/
|
||||
public MultipartFormData parseMultipart(UploadSetting uploadSetting) throws IORuntimeException {
|
||||
public MultipartFormData parseMultipart(final UploadSetting uploadSetting) throws IORuntimeException {
|
||||
final MultipartFormData formData = new MultipartFormData(uploadSetting);
|
||||
try {
|
||||
formData.parseRequestStream(getBodyStream(), getCharset());
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
*
|
||||
* @param httpExchange {@link HttpExchange}
|
||||
*/
|
||||
public HttpServerResponse(HttpExchange httpExchange) {
|
||||
public HttpServerResponse(final HttpExchange httpExchange) {
|
||||
super(httpExchange);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param httpStatusCode HTTP状态码,见HttpStatus
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse send(int httpStatusCode) {
|
||||
public HttpServerResponse send(final int httpStatusCode) {
|
||||
return send(httpStatusCode, 0);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public HttpServerResponse sendOk(int bodyLength) {
|
||||
public HttpServerResponse sendOk(final int bodyLength) {
|
||||
return send(HttpStatus.HTTP_OK, bodyLength);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param content 错误页页面内容,默认text/html类型
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse send404(String content) {
|
||||
public HttpServerResponse send404(final String content) {
|
||||
return sendError(HttpStatus.HTTP_NOT_FOUND, content);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param content 错误页页面内容,默认text/html类型
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse sendError(int errorCode, String content) {
|
||||
public HttpServerResponse sendError(final int errorCode, final String content) {
|
||||
send(errorCode);
|
||||
setContentType(ContentType.TEXT_HTML.toString());
|
||||
return write(content);
|
||||
@@ -105,14 +105,14 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param bodyLength 响应体长度,默认0表示不定长度,会输出Transfer-encoding: chunked
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse send(int httpStatusCode, long bodyLength) {
|
||||
public HttpServerResponse send(final int httpStatusCode, final long bodyLength) {
|
||||
if (this.isSendCode) {
|
||||
throw new IORuntimeException("Http status code has been send!");
|
||||
}
|
||||
|
||||
try {
|
||||
this.httpExchange.sendResponseHeaders(httpStatusCode, bodyLength);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse addHeader(String header, String value) {
|
||||
public HttpServerResponse addHeader(final String header, final String value) {
|
||||
getHeaders().add(header, value);
|
||||
return this;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setHeader(Header header, String value) {
|
||||
public HttpServerResponse setHeader(final Header header, final String value) {
|
||||
return setHeader(header.getValue(), value);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setHeader(String header, String value) {
|
||||
public HttpServerResponse setHeader(final String header, final String value) {
|
||||
getHeaders().set(header, value);
|
||||
return this;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param value 值列表
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setHeader(String header, List<String> value) {
|
||||
public HttpServerResponse setHeader(final String header, final List<String> value) {
|
||||
getHeaders().put(header, value);
|
||||
return this;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param headers 响应头map
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setHeaders(Map<String, List<String>> headers) {
|
||||
public HttpServerResponse setHeaders(final Map<String, List<String>> headers) {
|
||||
getHeaders().putAll(headers);
|
||||
return this;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param contentLength Content-Length头内容
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setContentLength(long contentLength) {
|
||||
public HttpServerResponse setContentLength(final long contentLength) {
|
||||
return setHeader(Header.CONTENT_LENGTH, String.valueOf(contentLength));
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param charset 编码
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setCharset(Charset charset) {
|
||||
public HttpServerResponse setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param value 属性值
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse setAttr(String name, Object value) {
|
||||
public HttpServerResponse setAttr(final String name, final Object value) {
|
||||
this.httpExchange.setAttribute(name, value);
|
||||
return this;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param contentType Content-Type类型
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(String data, String contentType) {
|
||||
public HttpServerResponse write(final String data, final String contentType) {
|
||||
setContentType(contentType);
|
||||
return write(data);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param data 数据
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(String data) {
|
||||
public HttpServerResponse write(final String data) {
|
||||
final Charset charset = ObjUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
return write(StrUtil.bytes(data, charset));
|
||||
}
|
||||
@@ -289,7 +289,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param contentType 返回的类型
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(byte[] data, String contentType) {
|
||||
public HttpServerResponse write(final byte[] data, final String contentType) {
|
||||
setContentType(contentType);
|
||||
return write(data);
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param data 数据
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(byte[] data) {
|
||||
public HttpServerResponse write(final byte[] data) {
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||
return write(in, in.available());
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in, String contentType) {
|
||||
public HttpServerResponse write(final InputStream in, final String contentType) {
|
||||
return write(in, 0, contentType);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.2.7
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in, int length, String contentType) {
|
||||
public HttpServerResponse write(final InputStream in, final int length, final String contentType) {
|
||||
setContentType(contentType);
|
||||
return write(in, length);
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param in 数据流
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in) {
|
||||
public HttpServerResponse write(final InputStream in) {
|
||||
return write(in, 0);
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param length 指定响应内容长度,默认0表示不定长度,会输出Transfer-encoding: chunked
|
||||
* @return this
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in, int length) {
|
||||
public HttpServerResponse write(final InputStream in, final int length) {
|
||||
if (false == isSendCode) {
|
||||
sendOk(Math.max(0, length));
|
||||
}
|
||||
@@ -370,7 +370,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public HttpServerResponse write(File file) {
|
||||
public HttpServerResponse write(final File file) {
|
||||
return write(file, null);
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public HttpServerResponse write(File file, String fileName) {
|
||||
public HttpServerResponse write(final File file, String fileName) {
|
||||
final long fileSize = file.length();
|
||||
if(fileSize > Integer.MAX_VALUE){
|
||||
throw new IllegalArgumentException("File size is too bigger than " + Integer.MAX_VALUE);
|
||||
@@ -410,7 +410,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @param fileName 文件名
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public void write(InputStream in, String contentType, String fileName) {
|
||||
public void write(final InputStream in, final String contentType, final String fileName) {
|
||||
write(in, 0, contentType, fileName);
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ public class HttpServerResponse extends HttpServerBase {
|
||||
* @return this
|
||||
* @since 5.2.7
|
||||
*/
|
||||
public HttpServerResponse write(InputStream in, int length, String contentType, String fileName) {
|
||||
public HttpServerResponse write(final InputStream in, final int length, final String contentType, final String fileName) {
|
||||
final Charset charset = ObjUtil.defaultIfNull(this.charset, DEFAULT_CHARSET);
|
||||
|
||||
if (false == contentType.startsWith("text/")) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SimpleServer {
|
||||
*
|
||||
* @param port 监听端口
|
||||
*/
|
||||
public SimpleServer(int port) {
|
||||
public SimpleServer(final int port) {
|
||||
this(new InetSocketAddress(port));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SimpleServer {
|
||||
* @param hostname 监听地址
|
||||
* @param port 监听端口
|
||||
*/
|
||||
public SimpleServer(String hostname, int port) {
|
||||
public SimpleServer(final String hostname, final int port) {
|
||||
this(new InetSocketAddress(hostname, port));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SimpleServer {
|
||||
*
|
||||
* @param address 监听地址
|
||||
*/
|
||||
public SimpleServer(InetSocketAddress address) {
|
||||
public SimpleServer(final InetSocketAddress address) {
|
||||
this(address, null);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class SimpleServer {
|
||||
* @param address 监听地址
|
||||
* @param configurator https配置信息,用于使用自定义SSL(TLS)证书等
|
||||
*/
|
||||
public SimpleServer(InetSocketAddress address, HttpsConfigurator configurator) {
|
||||
public SimpleServer(final InetSocketAddress address, final HttpsConfigurator configurator) {
|
||||
try {
|
||||
if(null != configurator){
|
||||
final HttpsServer server = HttpsServer.create(address, 0);
|
||||
@@ -78,7 +78,7 @@ public class SimpleServer {
|
||||
} else{
|
||||
this.server = HttpServer.create(address, 0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
setExecutor(GlobalThreadPool.getExecutor());
|
||||
@@ -101,7 +101,7 @@ public class SimpleServer {
|
||||
* @return this
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public SimpleServer addFilter(Filter filter) {
|
||||
public SimpleServer addFilter(final Filter filter) {
|
||||
this.filters.add(filter);
|
||||
return this;
|
||||
}
|
||||
@@ -122,10 +122,10 @@ public class SimpleServer {
|
||||
* @return this
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public SimpleServer addFilter(HttpFilter filter) {
|
||||
public SimpleServer addFilter(final HttpFilter filter) {
|
||||
return addFilter(new SimpleFilter() {
|
||||
@Override
|
||||
public void doFilter(HttpExchange httpExchange, Chain chain) throws IOException {
|
||||
public void doFilter(final HttpExchange httpExchange, final Chain chain) throws IOException {
|
||||
filter.doFilter(new HttpServerRequest(httpExchange), new HttpServerResponse(httpExchange), chain);
|
||||
}
|
||||
});
|
||||
@@ -139,7 +139,7 @@ public class SimpleServer {
|
||||
* @return this
|
||||
* @see #createContext(String, HttpHandler)
|
||||
*/
|
||||
public SimpleServer addHandler(String path, HttpHandler handler) {
|
||||
public SimpleServer addHandler(final String path, final HttpHandler handler) {
|
||||
createContext(path, handler);
|
||||
return this;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class SimpleServer {
|
||||
* @return {@link HttpContext}
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public HttpContext createContext(String path, HttpHandler handler) {
|
||||
public HttpContext createContext(String path, final HttpHandler handler) {
|
||||
// 非/开头的路径会报错
|
||||
path = StrUtil.addPrefixIfNot(path, StrUtil.SLASH);
|
||||
final HttpContext context = this.server.createContext(path, handler);
|
||||
@@ -167,7 +167,7 @@ public class SimpleServer {
|
||||
* @param root 路径
|
||||
* @return this
|
||||
*/
|
||||
public SimpleServer setRoot(String root) {
|
||||
public SimpleServer setRoot(final String root) {
|
||||
return setRoot(new File(root));
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class SimpleServer {
|
||||
* @param root 路径
|
||||
* @return this
|
||||
*/
|
||||
public SimpleServer setRoot(File root) {
|
||||
public SimpleServer setRoot(final File root) {
|
||||
return addAction("/", new RootAction(root));
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class SimpleServer {
|
||||
* @param action 处理器
|
||||
* @return this
|
||||
*/
|
||||
public SimpleServer addAction(String path, Action action) {
|
||||
public SimpleServer addAction(final String path, final Action action) {
|
||||
return addHandler(path, new ActionHandler(action));
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class SimpleServer {
|
||||
* @param executor {@link Executor}
|
||||
* @return this
|
||||
*/
|
||||
public SimpleServer setExecutor(Executor executor) {
|
||||
public SimpleServer setExecutor(final Executor executor) {
|
||||
this.server.setExecutor(executor);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RootAction implements Action {
|
||||
*
|
||||
* @param rootDir 网页根目录
|
||||
*/
|
||||
public RootAction(String rootDir) {
|
||||
public RootAction(final String rootDir) {
|
||||
this(new File(rootDir));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class RootAction implements Action {
|
||||
*
|
||||
* @param rootDir 网页根目录
|
||||
*/
|
||||
public RootAction(File rootDir) {
|
||||
public RootAction(final File rootDir) {
|
||||
this(rootDir, DEFAULT_INDEX_FILE_NAME);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RootAction implements Action {
|
||||
* @param rootDir 网页根目录
|
||||
* @param indexFileNames 主页文件名列表
|
||||
*/
|
||||
public RootAction(String rootDir, String... indexFileNames) {
|
||||
public RootAction(final String rootDir, final String... indexFileNames) {
|
||||
this(new File(rootDir), indexFileNames);
|
||||
}
|
||||
|
||||
@@ -56,19 +56,19 @@ public class RootAction implements Action {
|
||||
* @param indexFileNames 主页文件名列表
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public RootAction(File rootDir, String... indexFileNames) {
|
||||
public RootAction(final File rootDir, final String... indexFileNames) {
|
||||
this.rootDir = rootDir;
|
||||
this.indexFileNames = CollUtil.toList(indexFileNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(HttpServerRequest request, HttpServerResponse response) {
|
||||
public void doAction(final HttpServerRequest request, final HttpServerResponse response) {
|
||||
final String path = request.getPath();
|
||||
|
||||
File file = FileUtil.file(rootDir, path);
|
||||
if (file.exists()) {
|
||||
if (file.isDirectory()) {
|
||||
for (String indexFileName : indexFileNames) {
|
||||
for (final String indexFileName : indexFileNames) {
|
||||
//默认读取主页
|
||||
file = FileUtil.file(file, indexFileName);
|
||||
if (file.exists() && file.isFile()) {
|
||||
|
||||
@@ -23,12 +23,12 @@ public class ActionHandler implements HttpHandler {
|
||||
*
|
||||
* @param action Action
|
||||
*/
|
||||
public ActionHandler(Action action) {
|
||||
public ActionHandler(final Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange httpExchange) throws IOException {
|
||||
public void handle(final HttpExchange httpExchange) throws IOException {
|
||||
action.doAction(
|
||||
new HttpServerRequest(httpExchange),
|
||||
new HttpServerResponse(httpExchange)
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CustomProtocolsSSLFactory extends SSLSocketFactory {
|
||||
* @param protocols 支持协议列表
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public CustomProtocolsSSLFactory(String... protocols) throws IORuntimeException {
|
||||
public CustomProtocolsSSLFactory(final String... protocols) throws IORuntimeException {
|
||||
this.protocols = protocols;
|
||||
this.base = SSLUtil.createSSLContext(null).getSocketFactory();
|
||||
}
|
||||
@@ -49,35 +49,35 @@ public class CustomProtocolsSSLFactory extends SSLSocketFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SSLSocket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
||||
public SSLSocket createSocket(final Socket s, final String host, final int port, final boolean autoClose) throws IOException {
|
||||
final SSLSocket socket = (SSLSocket) base.createSocket(s, host, port, autoClose);
|
||||
resetProtocols(socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException {
|
||||
public Socket createSocket(final String host, final int port) throws IOException {
|
||||
final SSLSocket socket = (SSLSocket) base.createSocket(host, port);
|
||||
resetProtocols(socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
|
||||
public Socket createSocket(final String host, final int port, final InetAddress localHost, final int localPort) throws IOException {
|
||||
final SSLSocket socket = (SSLSocket) base.createSocket(host, port, localHost, localPort);
|
||||
resetProtocols(socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress host, int port) throws IOException {
|
||||
public Socket createSocket(final InetAddress host, final int port) throws IOException {
|
||||
final SSLSocket socket = (SSLSocket) base.createSocket(host, port);
|
||||
resetProtocols(socket);
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
public Socket createSocket(final InetAddress address, final int port, final InetAddress localAddress, final int localPort) throws IOException {
|
||||
final SSLSocket socket = (SSLSocket) base.createSocket(address, port, localAddress, localPort);
|
||||
resetProtocols(socket);
|
||||
return socket;
|
||||
@@ -88,7 +88,7 @@ public class CustomProtocolsSSLFactory extends SSLSocketFactory {
|
||||
*
|
||||
* @param socket SSLSocket
|
||||
*/
|
||||
private void resetProtocols(SSLSocket socket) {
|
||||
private void resetProtocols(final SSLSocket socket) {
|
||||
if (ArrayUtil.isNotEmpty(this.protocols)) {
|
||||
socket.setEnabledProtocols(this.protocols);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import javax.net.ssl.SSLSession;
|
||||
|
||||
/**
|
||||
* https 域名校验
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class TrustAnyHostnameVerifier implements HostnameVerifier {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
public boolean verify(final String hostname, final SSLSession session) {
|
||||
return true;// 直接返回true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class Browser extends UserAgentInfo {
|
||||
* @param versionRegex 匹配版本的正则
|
||||
* @since 5.7.4
|
||||
*/
|
||||
synchronized public static void addCustomBrowser(String name, String regex, String versionRegex) {
|
||||
synchronized public static void addCustomBrowser(final String name, final String regex, final String versionRegex) {
|
||||
browers.add(new Browser(name, regex, versionRegex));
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class Browser extends UserAgentInfo {
|
||||
* @param regex 关键字或表达式
|
||||
* @param versionRegex 匹配版本的正则
|
||||
*/
|
||||
public Browser(String name, String regex, String versionRegex) {
|
||||
public Browser(final String name, final String regex, String versionRegex) {
|
||||
super(name, regex);
|
||||
if (Other_Version.equals(versionRegex)) {
|
||||
versionRegex = name + versionRegex;
|
||||
@@ -113,7 +113,7 @@ public class Browser extends UserAgentInfo {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 版本
|
||||
*/
|
||||
public String getVersion(String userAgentString) {
|
||||
public String getVersion(final String userAgentString) {
|
||||
if(isUnknown()){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Engine extends UserAgentInfo {
|
||||
* @param name 引擎名称
|
||||
* @param regex 关键字或表达式
|
||||
*/
|
||||
public Engine(String name, String regex) {
|
||||
public Engine(final String name, final String regex) {
|
||||
super(name, regex);
|
||||
this.versionPattern = Pattern.compile(name + "[/\\- ]([\\d\\w.\\-]+)", Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class Engine extends UserAgentInfo {
|
||||
* @return 版本
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public String getVersion(String userAgentString) {
|
||||
public String getVersion(final String userAgentString) {
|
||||
if(isUnknown()){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class OS extends UserAgentInfo {
|
||||
* @param versionRegex 匹配版本的正则
|
||||
* @since 5.7.4
|
||||
*/
|
||||
synchronized public static void addCustomOs(String name, String regex, String versionRegex) {
|
||||
synchronized public static void addCustomOs(final String name, final String regex, final String versionRegex) {
|
||||
oses.add(new OS(name, regex, versionRegex));
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class OS extends UserAgentInfo {
|
||||
* @param name 系统名称
|
||||
* @param regex 关键字或表达式
|
||||
*/
|
||||
public OS(String name, String regex) {
|
||||
public OS(final String name, final String regex) {
|
||||
this(name, regex, null);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class OS extends UserAgentInfo {
|
||||
* @param versionRegex 版本正则表达式
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public OS(String name, String regex, String versionRegex) {
|
||||
public OS(final String name, final String regex, final String versionRegex) {
|
||||
super(name, regex);
|
||||
if (null != versionRegex) {
|
||||
this.versionPattern = Pattern.compile(versionRegex, Pattern.CASE_INSENSITIVE);
|
||||
@@ -97,7 +97,7 @@ public class OS extends UserAgentInfo {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 版本
|
||||
*/
|
||||
public String getVersion(String userAgentString) {
|
||||
public String getVersion(final String userAgentString) {
|
||||
if(isUnknown() || null == this.versionPattern){
|
||||
// 无版本信息
|
||||
return null;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class Platform extends UserAgentInfo {
|
||||
* @param name 平台名称
|
||||
* @param regex 关键字或表达式
|
||||
*/
|
||||
public Platform(String name, String regex) {
|
||||
public Platform(final String name, final String regex) {
|
||||
super(name, regex);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param mobile 是否为移动平台
|
||||
*/
|
||||
public void setMobile(boolean mobile) {
|
||||
public void setMobile(final boolean mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param browser 浏览器类型
|
||||
*/
|
||||
public void setBrowser(Browser browser) {
|
||||
public void setBrowser(final Browser browser) {
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param platform 平台类型
|
||||
*/
|
||||
public void setPlatform(Platform platform) {
|
||||
public void setPlatform(final Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param os 系统类型
|
||||
*/
|
||||
public void setOs(OS os) {
|
||||
public void setOs(final OS os) {
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class UserAgent implements Serializable {
|
||||
* @param osVersion 系统版本
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public void setOsVersion(String osVersion) {
|
||||
public void setOsVersion(final String osVersion) {
|
||||
this.osVersion = osVersion;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param engine 引擎类型
|
||||
*/
|
||||
public void setEngine(Engine engine) {
|
||||
public void setEngine(final Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param version 浏览器版本
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
public void setVersion(final String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class UserAgent implements Serializable {
|
||||
*
|
||||
* @param engineVersion 引擎版本
|
||||
*/
|
||||
public void setEngineVersion(String engineVersion) {
|
||||
public void setEngineVersion(final String engineVersion) {
|
||||
this.engineVersion = engineVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UserAgentInfo implements Serializable {
|
||||
* @param name 名字
|
||||
* @param regex 表达式
|
||||
*/
|
||||
public UserAgentInfo(String name, String regex) {
|
||||
public UserAgentInfo(final String name, final String regex) {
|
||||
this(name, (null == regex) ? null : Pattern.compile(regex, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UserAgentInfo implements Serializable {
|
||||
* @param name 名字
|
||||
* @param pattern 匹配模式
|
||||
*/
|
||||
public UserAgentInfo(String name, Pattern pattern) {
|
||||
public UserAgentInfo(final String name, final Pattern pattern) {
|
||||
this.name = name;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class UserAgentInfo implements Serializable {
|
||||
* @param content User-Agent字符串
|
||||
* @return 是否包含匹配此信息的内容
|
||||
*/
|
||||
public boolean isMatch(String content) {
|
||||
public boolean isMatch(final String content) {
|
||||
return ReUtil.contains(this.pattern, content);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class UserAgentInfo implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UserAgentParser {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return {@link UserAgent}
|
||||
*/
|
||||
public static UserAgent parse(String userAgentString) {
|
||||
public static UserAgent parse(final String userAgentString) {
|
||||
if(StrUtil.isBlank(userAgentString)){
|
||||
return null;
|
||||
}
|
||||
@@ -52,8 +52,8 @@ public class UserAgentParser {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 浏览器类型
|
||||
*/
|
||||
private static Browser parseBrowser(String userAgentString) {
|
||||
for (Browser browser : Browser.browers) {
|
||||
private static Browser parseBrowser(final String userAgentString) {
|
||||
for (final Browser browser : Browser.browers) {
|
||||
if (browser.isMatch(userAgentString)) {
|
||||
return browser;
|
||||
}
|
||||
@@ -67,8 +67,8 @@ public class UserAgentParser {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 引擎类型
|
||||
*/
|
||||
private static Engine parseEngine(String userAgentString) {
|
||||
for (Engine engine : Engine.engines) {
|
||||
private static Engine parseEngine(final String userAgentString) {
|
||||
for (final Engine engine : Engine.engines) {
|
||||
if (engine.isMatch(userAgentString)) {
|
||||
return engine;
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public class UserAgentParser {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 系统类型
|
||||
*/
|
||||
private static OS parseOS(String userAgentString) {
|
||||
for (OS os : OS.oses) {
|
||||
private static OS parseOS(final String userAgentString) {
|
||||
for (final OS os : OS.oses) {
|
||||
if (os.isMatch(userAgentString)) {
|
||||
return os;
|
||||
}
|
||||
@@ -97,8 +97,8 @@ public class UserAgentParser {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return 平台类型
|
||||
*/
|
||||
private static Platform parsePlatform(String userAgentString) {
|
||||
for (Platform platform : Platform.platforms) {
|
||||
private static Platform parsePlatform(final String userAgentString) {
|
||||
for (final Platform platform : Platform.platforms) {
|
||||
if (platform.isMatch(userAgentString)) {
|
||||
return platform;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class UserAgentUtil {
|
||||
* @param userAgentString User-Agent字符串
|
||||
* @return {@link UserAgent}
|
||||
*/
|
||||
public static UserAgent parse(String userAgentString) {
|
||||
public static UserAgent parse(final String userAgentString) {
|
||||
return UserAgentParser.parse(userAgentString);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param url WS的URL地址
|
||||
* @return this
|
||||
*/
|
||||
public static SoapClient create(String url) {
|
||||
public static SoapClient create(final String url) {
|
||||
return new SoapClient(url);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param protocol 协议,见{@link SoapProtocol}
|
||||
* @return this
|
||||
*/
|
||||
public static SoapClient create(String url, SoapProtocol protocol) {
|
||||
public static SoapClient create(final String url, final SoapProtocol protocol) {
|
||||
return new SoapClient(url, protocol);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public static SoapClient create(String url, SoapProtocol protocol, String namespaceURI) {
|
||||
public static SoapClient create(final String url, final SoapProtocol protocol, final String namespaceURI) {
|
||||
return new SoapClient(url, protocol, namespaceURI);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
*
|
||||
* @param url WS的URL地址
|
||||
*/
|
||||
public SoapClient(String url) {
|
||||
public SoapClient(final String url) {
|
||||
this(url, SoapProtocol.SOAP_1_1);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param url WS的URL地址
|
||||
* @param protocol 协议版本,见{@link SoapProtocol}
|
||||
*/
|
||||
public SoapClient(String url, SoapProtocol protocol) {
|
||||
public SoapClient(final String url, final SoapProtocol protocol) {
|
||||
this(url, protocol, null);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param namespaceURI 方法上的命名空间URI
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient(String url, SoapProtocol protocol, String namespaceURI) {
|
||||
public SoapClient(final String url, final SoapProtocol protocol, final String namespaceURI) {
|
||||
this.url = url;
|
||||
this.namespaceURI = namespaceURI;
|
||||
this.protocol = protocol;
|
||||
@@ -172,13 +172,13 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param protocol 协议版本枚举,见{@link SoapProtocol}
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient init(SoapProtocol protocol) {
|
||||
public SoapClient init(final SoapProtocol protocol) {
|
||||
// 创建消息工厂
|
||||
try {
|
||||
this.factory = MessageFactory.newInstance(protocol.getValue());
|
||||
// 根据消息工厂创建SoapMessage
|
||||
this.message = factory.createMessage();
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
public SoapClient reset() {
|
||||
try {
|
||||
this.message = factory.createMessage();
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
this.methodEle = null;
|
||||
@@ -212,17 +212,17 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @see #charset(Charset)
|
||||
*/
|
||||
public SoapClient setCharset(Charset charset) {
|
||||
public SoapClient setCharset(final Charset charset) {
|
||||
return this.charset(charset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoapClient charset(Charset charset) {
|
||||
public SoapClient charset(final Charset charset) {
|
||||
super.charset(charset);
|
||||
try {
|
||||
this.message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, this.charset());
|
||||
this.message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param url Webservice请求地址
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setUrl(String url) {
|
||||
public SoapClient setUrl(final String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return {@link SOAPHeaderElement}
|
||||
* @since 5.4.4
|
||||
*/
|
||||
public SOAPHeaderElement addSOAPHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay) {
|
||||
public SOAPHeaderElement addSOAPHeader(final QName name, final String actorURI, final String roleUri, final Boolean mustUnderstand, final Boolean relay) {
|
||||
final SOAPHeaderElement ele = addSOAPHeader(name);
|
||||
try {
|
||||
if (StrUtil.isNotBlank(roleUri)) {
|
||||
@@ -260,7 +260,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
if (null != relay) {
|
||||
ele.setRelay(relay);
|
||||
}
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return {@link SOAPHeaderElement}
|
||||
* @since 5.4.7
|
||||
*/
|
||||
public SOAPHeaderElement addSOAPHeader(String localName) {
|
||||
public SOAPHeaderElement addSOAPHeader(final String localName) {
|
||||
return addSOAPHeader(new QName(localName));
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return {@link SOAPHeaderElement}
|
||||
* @since 5.4.7
|
||||
*/
|
||||
public SOAPHeaderElement addSOAPHeader(String localName, String value) {
|
||||
public SOAPHeaderElement addSOAPHeader(final String localName, final String value) {
|
||||
final SOAPHeaderElement soapHeaderElement = addSOAPHeader(localName);
|
||||
soapHeaderElement.setTextContent(value);
|
||||
return soapHeaderElement;
|
||||
@@ -306,11 +306,11 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return {@link SOAPHeaderElement}
|
||||
* @since 5.4.4
|
||||
*/
|
||||
public SOAPHeaderElement addSOAPHeader(QName name) {
|
||||
SOAPHeaderElement ele;
|
||||
public SOAPHeaderElement addSOAPHeader(final QName name) {
|
||||
final SOAPHeaderElement ele;
|
||||
try {
|
||||
ele = this.message.getSOAPHeader().addHeaderElement(name);
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
return ele;
|
||||
@@ -324,7 +324,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param useMethodPrefix 是否使用方法的命名空间前缀
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(Name name, Map<String, Object> params, boolean useMethodPrefix) {
|
||||
public SoapClient setMethod(final Name name, final Map<String, Object> params, final boolean useMethodPrefix) {
|
||||
return setMethod(new QName(name.getURI(), name.getLocalName(), name.getPrefix()), params, useMethodPrefix);
|
||||
}
|
||||
|
||||
@@ -336,11 +336,11 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param useMethodPrefix 是否使用方法的命名空间前缀
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(QName name, Map<String, Object> params, boolean useMethodPrefix) {
|
||||
public SoapClient setMethod(final QName name, final Map<String, Object> params, final boolean useMethodPrefix) {
|
||||
setMethod(name);
|
||||
final String prefix = useMethodPrefix ? name.getPrefix() : null;
|
||||
final SOAPBodyElement methodEle = this.methodEle;
|
||||
for (Entry<String, Object> entry : MapUtil.wrap(params)) {
|
||||
for (final Entry<String, Object> entry : MapUtil.wrap(params)) {
|
||||
setParam(methodEle, entry.getKey(), entry.getValue(), prefix);
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param methodName 方法名
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(String methodName) {
|
||||
public SoapClient setMethod(final String methodName) {
|
||||
return setMethod(methodName, ObjUtil.defaultIfNull(this.namespaceURI, XMLConstants.NULL_NS_URI));
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param namespaceURI 命名空间URI
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(String methodName, String namespaceURI) {
|
||||
public SoapClient setMethod(final String methodName, final String namespaceURI) {
|
||||
final List<String> methodNameList = StrUtil.split(methodName, ':');
|
||||
final QName qName;
|
||||
if (2 == methodNameList.size()) {
|
||||
@@ -385,10 +385,10 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param name 方法名及其命名空间
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setMethod(QName name) {
|
||||
public SoapClient setMethod(final QName name) {
|
||||
try {
|
||||
this.methodEle = this.message.getSOAPBody().addBodyElement(name);
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param value 参数值,可以是字符串或Map或{@link SOAPElement}
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setParam(String name, Object value) {
|
||||
public SoapClient setParam(final String name, final Object value) {
|
||||
return setParam(name, value, true);
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param useMethodPrefix 是否使用方法的命名空间前缀
|
||||
* @return this
|
||||
*/
|
||||
public SoapClient setParam(String name, Object value, boolean useMethodPrefix) {
|
||||
public SoapClient setParam(final String name, final Object value, final boolean useMethodPrefix) {
|
||||
setParam(this.methodEle, name, value, useMethodPrefix ? this.methodEle.getPrefix() : null);
|
||||
return this;
|
||||
}
|
||||
@@ -426,7 +426,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient setParams(Map<String, Object> params) {
|
||||
public SoapClient setParams(final Map<String, Object> params) {
|
||||
return setParams(params, true);
|
||||
}
|
||||
|
||||
@@ -438,8 +438,8 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient setParams(Map<String, Object> params, boolean useMethodPrefix) {
|
||||
for (Entry<String, Object> entry : MapUtil.wrap(params)) {
|
||||
public SoapClient setParams(final Map<String, Object> params, final boolean useMethodPrefix) {
|
||||
for (final Entry<String, Object> entry : MapUtil.wrap(params)) {
|
||||
setParam(entry.getKey(), entry.getValue(), useMethodPrefix);
|
||||
}
|
||||
return this;
|
||||
@@ -472,7 +472,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param pretty 是否格式化
|
||||
* @return 消息字符串
|
||||
*/
|
||||
public String getMsgStr(boolean pretty) {
|
||||
public String getMsgStr(final boolean pretty) {
|
||||
return SoapUtil.toString(this.message, pretty, this.charset);
|
||||
}
|
||||
|
||||
@@ -483,10 +483,10 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient write(OutputStream out) {
|
||||
public SoapClient write(final OutputStream out) {
|
||||
try {
|
||||
this.message.writeTo(out);
|
||||
} catch (SOAPException | IOException e) {
|
||||
} catch (final SOAPException | IOException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
@@ -506,7 +506,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @see #setConnectionTimeout(int)
|
||||
* @see #setReadTimeout(int)
|
||||
*/
|
||||
public SoapClient timeout(int milliseconds) {
|
||||
public SoapClient timeout(final int milliseconds) {
|
||||
setConnectionTimeout(milliseconds);
|
||||
setReadTimeout(milliseconds);
|
||||
return this;
|
||||
@@ -519,7 +519,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient setConnectionTimeout(int milliseconds) {
|
||||
public SoapClient setConnectionTimeout(final int milliseconds) {
|
||||
this.connectionTimeout = milliseconds;
|
||||
return this;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return this
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public SoapClient setReadTimeout(int milliseconds) {
|
||||
public SoapClient setReadTimeout(final int milliseconds) {
|
||||
this.readTimeout = milliseconds;
|
||||
return this;
|
||||
}
|
||||
@@ -544,14 +544,14 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
public SOAPMessage sendForMessage() {
|
||||
final HttpResponse res = sendForResponse();
|
||||
final MimeHeaders headers = new MimeHeaders();
|
||||
for (Entry<String, List<String>> entry : res.headers().entrySet()) {
|
||||
for (final Entry<String, List<String>> entry : res.headers().entrySet()) {
|
||||
if (StrUtil.isNotEmpty(entry.getKey())) {
|
||||
headers.setHeader(entry.getKey(), CollUtil.get(entry.getValue(), 0));
|
||||
}
|
||||
}
|
||||
try {
|
||||
return this.factory.createMessage(headers, res.bodyStream());
|
||||
} catch (IOException | SOAPException e) {
|
||||
} catch (final IOException | SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
} finally {
|
||||
IoUtil.close(res);
|
||||
@@ -573,7 +573,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @param pretty 是否格式化
|
||||
* @return 返回结果
|
||||
*/
|
||||
public String send(boolean pretty) {
|
||||
public String send(final boolean pretty) {
|
||||
final String body = sendForResponse().body();
|
||||
return pretty ? XmlUtil.format(body) : body;
|
||||
}
|
||||
@@ -622,7 +622,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
* @return {@link SOAPElement}子节点
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static SOAPElement setParam(SOAPElement ele, String name, Object value, String prefix) {
|
||||
private static SOAPElement setParam(final SOAPElement ele, final String name, final Object value, final String prefix) {
|
||||
final SOAPElement childEle;
|
||||
try {
|
||||
if (StrUtil.isNotBlank(prefix)) {
|
||||
@@ -630,7 +630,7 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
} else {
|
||||
childEle = ele.addChildElement(name);
|
||||
}
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -639,13 +639,13 @@ public class SoapClient extends HttpBase<SoapClient> {
|
||||
// 单个子节点
|
||||
try {
|
||||
ele.addChildElement((SOAPElement) value);
|
||||
} catch (SOAPException e) {
|
||||
} catch (final SOAPException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
} else if (value instanceof Map) {
|
||||
// 多个字节点
|
||||
Entry entry;
|
||||
for (Object obj : ((Map) value).entrySet()) {
|
||||
for (final Object obj : ((Map) value).entrySet()) {
|
||||
entry = (Entry) obj;
|
||||
setParam(childEle, entry.getKey().toString(), entry.getValue(), prefix);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import javax.xml.soap.SOAPConstants;
|
||||
|
||||
/**
|
||||
* SOAP协议版本枚举
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@@ -16,10 +16,10 @@ public enum SoapProtocol {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param value {@link SOAPConstants} 中的协议版本值
|
||||
*/
|
||||
SoapProtocol(String value) {
|
||||
SoapProtocol(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public enum SoapProtocol {
|
||||
|
||||
/**
|
||||
* 获取版本值信息
|
||||
*
|
||||
*
|
||||
* @return 版本值信息
|
||||
*/
|
||||
public String getValue() {
|
||||
|
||||
@@ -10,23 +10,23 @@ import cn.hutool.core.text.StrUtil;
|
||||
public class SoapRuntimeException extends RuntimeException {
|
||||
private static final long serialVersionUID = 8247610319171014183L;
|
||||
|
||||
public SoapRuntimeException(Throwable e) {
|
||||
public SoapRuntimeException(final Throwable e) {
|
||||
super(e.getMessage(), e);
|
||||
}
|
||||
|
||||
public SoapRuntimeException(String message) {
|
||||
public SoapRuntimeException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SoapRuntimeException(String messageTemplate, Object... params) {
|
||||
public SoapRuntimeException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
}
|
||||
|
||||
public SoapRuntimeException(String message, Throwable throwable) {
|
||||
public SoapRuntimeException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
|
||||
public SoapRuntimeException(Throwable throwable, String messageTemplate, Object... params) {
|
||||
public SoapRuntimeException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SoapUtil {
|
||||
* @param url WS的URL地址
|
||||
* @return {@link SoapClient}
|
||||
*/
|
||||
public static SoapClient createClient(String url) {
|
||||
public static SoapClient createClient(final String url) {
|
||||
return SoapClient.create(url);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SoapUtil {
|
||||
* @param protocol 协议,见{@link SoapProtocol}
|
||||
* @return {@link SoapClient}
|
||||
*/
|
||||
public static SoapClient createClient(String url, SoapProtocol protocol) {
|
||||
public static SoapClient createClient(final String url, final SoapProtocol protocol) {
|
||||
return SoapClient.create(url, protocol);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SoapUtil {
|
||||
* @return {@link SoapClient}
|
||||
* @since 4.5.6
|
||||
*/
|
||||
public static SoapClient createClient(String url, SoapProtocol protocol, String namespaceURI) {
|
||||
public static SoapClient createClient(final String url, final SoapProtocol protocol, final String namespaceURI) {
|
||||
return SoapClient.create(url, protocol, namespaceURI);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SoapUtil {
|
||||
* @param pretty 是否格式化
|
||||
* @return SOAP XML字符串
|
||||
*/
|
||||
public static String toString(SOAPMessage message, boolean pretty) {
|
||||
public static String toString(final SOAPMessage message, final boolean pretty) {
|
||||
return toString(message, pretty, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
@@ -74,17 +74,17 @@ public class SoapUtil {
|
||||
* @return SOAP XML字符串
|
||||
* @since 4.5.7
|
||||
*/
|
||||
public static String toString(SOAPMessage message, boolean pretty, Charset charset) {
|
||||
public static String toString(final SOAPMessage message, final boolean pretty, final Charset charset) {
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
message.writeTo(out);
|
||||
} catch (SOAPException | IOException e) {
|
||||
} catch (final SOAPException | IOException e) {
|
||||
throw new SoapRuntimeException(e);
|
||||
}
|
||||
String messageToString;
|
||||
final String messageToString;
|
||||
try {
|
||||
messageToString = out.toString(charset.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
throw new UtilException(e);
|
||||
}
|
||||
return pretty ? XmlUtil.format(messageToString) : messageToString;
|
||||
|
||||
Reference in New Issue
Block a user