use of com.dtflys.forest.handler.LifeCycleHandler in project forest by dromara.
the class ForestRequest method execute.
/**
* 执行请求发送过程
*
* @param type 结果返回类型, {@link Type} 接口实例
* @param <R> 泛型参数: 结果返回类型
* @return 请求执行响应后返回的结果, 其为 {@link Type} 参数所指定的类型
*/
public <R> R execute(Type type) {
LifeCycleHandler lifeCycleHandler = getLifeCycleHandler();
MethodLifeCycleHandler<R> methodLifeCycleHandler = new MethodLifeCycleHandler<>(type, lifeCycleHandler.getOnSuccessClassGenericType());
Object ret = execute(getBackend(), methodLifeCycleHandler);
return (R) ret;
}
use of com.dtflys.forest.handler.LifeCycleHandler in project forest by dromara.
the class ForestRequest method execute.
/**
* 执行请求发送过程
*
* @param clazz 结果返回类型, {@link Class} 对象
* @param <R> 泛型参数: 结果返回类型
* @return 请求执行响应后返回的结果, 其为 {@code Class<R>} 参数所指定的类型
*/
public <R> R execute(Class<R> clazz) {
LifeCycleHandler lifeCycleHandler = getLifeCycleHandler();
MethodLifeCycleHandler<R> methodLifeCycleHandler = new MethodLifeCycleHandler<>(clazz, lifeCycleHandler.getOnSuccessClassGenericType());
Object ret = execute(getBackend(), methodLifeCycleHandler);
return (R) ret;
}
use of com.dtflys.forest.handler.LifeCycleHandler in project forest by dromara.
the class TestResponseFactory method testHttpclientForestResponseFactory.
@Test
public void testHttpclientForestResponseFactory() {
ForestRequest request = new ForestRequest(ForestConfiguration.configuration());
Date requestTime = new Date();
HttpclientForestResponseFactory responseFactory = new HttpclientForestResponseFactory();
HttpResponse httpResponse = mock(HttpResponse.class);
StatusLine statusLine = mock(StatusLine.class);
when(statusLine.getStatusCode()).thenReturn(200);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
LifeCycleHandler lifeCycleHandler = new NoneLifeCycleHandler();
ForestResponse response = responseFactory.createResponse(request, httpResponse, lifeCycleHandler, null, requestTime);
assertThat(response).isNotNull().extracting(ForestResponse::getStatusCode, ForestResponse::getContent, ForestResponse::getResult).contains(200, "", null);
}
Aggregations