/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Jun Gong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.dtflys.forest.http;
import com.dtflys.forest.auth.BasicAuth;
import com.dtflys.forest.auth.ForestAuthenticator;
import com.dtflys.forest.backend.ContentType;
import com.dtflys.forest.backend.HttpBackend;
import com.dtflys.forest.backend.HttpExecutor;
import com.dtflys.forest.callback.OnCanceled;
import com.dtflys.forest.callback.OnError;
import com.dtflys.forest.callback.OnLoadCookie;
import com.dtflys.forest.callback.OnProgress;
import com.dtflys.forest.callback.OnRedirection;
import com.dtflys.forest.callback.OnRetry;
import com.dtflys.forest.callback.OnSaveCookie;
import com.dtflys.forest.callback.OnSuccess;
import com.dtflys.forest.callback.RetryWhen;
import com.dtflys.forest.callback.SuccessWhen;
import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.converter.ConvertOptions;
import com.dtflys.forest.converter.ForestConverter;
import com.dtflys.forest.converter.ForestEncoder;
import com.dtflys.forest.converter.json.ForestJsonConverter;
import com.dtflys.forest.exceptions.ForestAsyncAbortException;
import com.dtflys.forest.exceptions.ForestRetryException;
import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.exceptions.ForestVariableUndefinedException;
import com.dtflys.forest.handler.LifeCycleHandler;
import com.dtflys.forest.http.body.ByteArrayRequestBody;
import com.dtflys.forest.http.body.FileRequestBody;
import com.dtflys.forest.http.body.InputStreamRequestBody;
import com.dtflys.forest.http.body.MultipartRequestBody;
import com.dtflys.forest.http.body.NameValueRequestBody;
import com.dtflys.forest.http.body.ObjectRequestBody;
import com.dtflys.forest.http.body.StringRequestBody;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.interceptor.InterceptorAttributes;
import com.dtflys.forest.interceptor.InterceptorChain;
import com.dtflys.forest.lifecycles.file.DownloadLifeCycle;
import com.dtflys.forest.logging.LogConfiguration;
import com.dtflys.forest.logging.RequestLogMessage;
import com.dtflys.forest.mapping.MappingURLTemplate;
import com.dtflys.forest.mapping.MappingVariable;
import com.dtflys.forest.multipart.ByteArrayMultipart;
import com.dtflys.forest.multipart.FileMultipart;
import com.dtflys.forest.multipart.ForestMultipart;
import com.dtflys.forest.multipart.InputStreamMultipart;
import com.dtflys.forest.pool.ForestRequestPool;
import com.dtflys.forest.reflection.ForestMethod;
import com.dtflys.forest.reflection.MethodLifeCycleHandler;
import com.dtflys.forest.retryer.ForestRetryer;
import com.dtflys.forest.ssl.SSLKeyStore;
import com.dtflys.forest.ssl.SSLSocketFactoryBuilder;
import com.dtflys.forest.ssl.SSLUtils;
import com.dtflys.forest.ssl.TrustAllHostnameVerifier;
import com.dtflys.forest.utils.ForestDataType;
import com.dtflys.forest.utils.RequestNameValue;
import com.dtflys.forest.utils.StringUtils;
import com.dtflys.forest.utils.TimeUtils;
import com.dtflys.forest.utils.TypeReference;
import com.dtflys.forest.utils.URLUtils;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.dtflys.forest.mapping.MappingParameter.TARGET_BODY;
import static com.dtflys.forest.mapping.MappingParameter.TARGET_HEADER;
import static com.dtflys.forest.mapping.MappingParameter.TARGET_QUERY;
/**
* Forest请求对象
*
* @author gongjun[dt_flys@hotmail.com]
* @since 2016-03-24
*/
public class ForestRequest<T> implements HasURL, HasHeaders {
private final static Object[] EMPTY_RENDER_ARGS = new Object[0];
/**
* 默认上传/下载进度监听的步长
* <p>
* 每上传/下载一定的比特数,执行一次监听回调函数
*/
private final static long DEFAULT_PROGRESS_STEP = 1024 * 10;
/**
* Forest配置信息对象
*/
private final ForestConfiguration configuration;
/**
* Forest方法
*/
private final ForestMethod method;
/**
* HTTP后端
*/
private HttpBackend backend;
/**
* HTTP 后端 Client 对象或对象工厂
*
* @since 1.5.23
*/
private Object backendClient;
/**
* 是否缓存 HTTP 后端 Client 对象
*/
private boolean cacheBackendClient = true;
/**
* HTTP 执行器
*
* @since 1.5.27
*/
private HttpExecutor executor;
/**
* 生命周期处理器
*/
private volatile LifeCycleHandler lifeCycleHandler;
/**
* HTTP协议
* <p>默认为 HTTP 1.1
*/
private ForestProtocol protocol = ForestProtocol.HTTP_1_1;
/**
* 请求是否以取消
*
* @since 1.5.27
*/
private volatile boolean canceled = false;
/**
* URL路径
*/
private ForestURL url;
/**
* URL中的Query参数表
*/
private ForestQueryMap query = new ForestQueryMap(this);
/**
* 请求类型
*/
private ForestRequestType type;
/**
* 请求类型变更历史
*/
private List<ForestRequestType> typeChangeHistory;
/**
* 请求日志消息
*/
private RequestLogMessage requestLogMessage;
/**
* 请求参数编码字符集
*/
private String charset;
/**
* 请求响应返回数据的字符编码
*/
private String responseEncode;
/**
* 是否异步
*/
private boolean async;
/**
* 异步请求模式
* <p>该字段只有在 async = true 时有效</p>
*
* @since 1.5.27
*/
private ForestAsyncMode asyncMode = ForestAsyncMode.PLATFORM;
/**
* 请求认证器
*
* @since 1.5.28
*/
private ForestAuthenticator authenticator = new BasicAuth();
/**
* 是否打开自动重定向
*/
private boolean autoRedirection;
/**
* 响应数据类型
* <p>该类型决定请求响应返回的数据将以何种方式进行反序列化
*/
private ForestDataType dataType;
/**
* 请求超时时间
*/
private int timeout = 3000;
/**
* 请求连接超时时间
*/
private Integ
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
声明式HTTP客户端API框架,让Java发送HTTP/HTTPS请求不再难。它比OkHttp和HttpClient更高层,是封装调用第三方restful api client接口的好帮手,是retrofit和feign之外另一个选择。通过在接口上声明注解的方式配置HTTP请求接口
资源推荐
资源详情
资源评论
收起资源包目录
声明式HTTP客户端API框架,让Java发送HTTP/HTTPS请求不再难 (1020个子文件)
client_key.cer 847B
server_key.cer 847B
vue.css 12KB
spring.factories 119B
com.dtflys.forest.converter.xml.ForestXmlConverter 69B
com.dtflys.forest.converter.xml.ForestXmlConverter 57B
.gitignore 852B
.gitignore 9B
spring.handlers 88B
index.html 1KB
org.springframework.boot.autoconfigure.AutoConfiguration.imports 52B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 52B
ForestRequest.java 144KB
TestGenericForestClient.java 79KB
ProtobufProto.java 69KB
ForestMethod.java 66KB
ForestConfiguration.java 54KB
TestUploadClient.java 51KB
TestGetClient.java 50KB
TestPostClient.java 47KB
TestBaseRedirectClient.java 32KB
ForestResponse.java 21KB
MappingTemplate.java 20KB
ReflectUtils.java 19KB
ForestURL.java 17KB
ForestBody.java 17KB
PostClient.java 17KB
JsonTest.java 16KB
TestAsyncGetClient.java 16KB
ForestHeaderMap.java 15KB
ForestBeanRegister.java 15KB
ForestBeanRegister.java 15KB
MappingURLTemplate.java 15KB
ForestQueryMap.java 15KB
GetClient.java 14KB
ForestBeanBuilder.java 14KB
ForestConfigurationBeanDefinitionParser.java 14KB
ForestFastjsonConverter.java 13KB
OAuth2LifeCycle.java 13KB
TestDownloadClient.java 13KB
OkHttp3Executor.java 12KB
ForestCookie.java 12KB
ForestConfigurationProperties.java 11KB
ForestConfigurationProperties.java 11KB
TestForestFastjsonConverter.java 11KB
TestExceptions.java 11KB
TestPoolClient.java 11KB
OkHttp3ConnectionManager.java 11KB
ForestConfigurationProperties.java 11KB
DefaultFormConvertor.java 10KB
InterfaceProxyHandler.java 10KB
TestCookieClient.java 10KB
TestSSLClient.java 10KB
CookieTest.java 10KB
Interceptor.java 10KB
ForestGsonConverter.java 9KB
MethodLifeCycleHandler.java 9KB
DefaultLogHandler.java 9KB
TestForestConfiguration.java 9KB
URLUtils.java 9KB
HttpclientConnectionManager.java 9KB
MockHttpServletRequest.java 9KB
ForestMultipartFactory.java 8KB
TestUploadController.java 8KB
URLEncoder.java 8KB
OAuth2.java 8KB
TestHeadClient.java 8KB
TestForestProtobufConverter.java 8KB
ForestJsonConverter.java 8KB
TestUploadController.java 8KB
OkHttp3BodyBuilder.java 8KB
MockServerRequest.java 8KB
ContentType.java 7KB
ClassPathClientScanner.java 7KB
MetaRequest.java 7KB
TestForestJacksonConverter.java 7KB
DefaultAutoConverter.java 7KB
HttpclientBodyBuilder.java 7KB
ResultHandler.java 7KB
TestBodyAnnotation.java 7KB
TestRetryClient.java 7KB
TestGsonConverter.java 7KB
TestEncoderClient.java 7KB
ForestCookies.java 7KB
TestBackendClientProviderClient.java 7KB
TestUploadController.java 7KB
OkHttp3ForestResponse.java 6KB
HttpclientForestResponse.java 6KB
Forest.java 6KB
TestBaseReqClient.java 6KB
DefaultBinaryConverter.java 6KB
SyncHttpclientRequestSender.java 6KB
BaseRequest.java 6KB
ForestJacksonConverter.java 6KB
TestPostXml.java 6KB
ForestAddress.java 6KB
ForestHeader.java 6KB
Request.java 6KB
HttpclientLogBodyMessage.java 6KB
SSLKeyStore.java 6KB
共 1020 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功