use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestRequest method testUrl.
@Test
public void testUrl() {
ForestRequest request = Forest.request();
assertThat(request.getUrl()).isEqualTo("http://localhost/");
assertThat(request.host()).isEqualTo("localhost");
assertThat(request.port()).isEqualTo(80);
assertThat(request.getPath()).isEqualTo("/");
request.url("http://127.0.0.1:8080/xxx/yyy");
assertThat(request.urlString()).isEqualTo("http://127.0.0.1:8080/xxx/yyy");
assertThat(request.host()).isEqualTo("127.0.0.1");
assertThat(request.port()).isEqualTo(8080);
assertThat(request.getPath()).isEqualTo("/xxx/yyy");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestGetClient method testPath3.
@Test
public void testPath3() {
ForestRequest request = getClient.testPath3();
assertThat(request).isNotNull();
assertThat(request.urlString()).isEqualTo("https://localhost/xxx:yyy");
System.out.println(request.urlString());
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestGetClient method testPath4.
@Test
public void testPath4() {
ForestRequest request = getClient.testPath4();
assertThat(request).isNotNull();
assertThat(request.urlString()).isEqualTo("https://localhost/xxx:111");
System.out.println(request.urlString());
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestGetClient method testPath_userInfo.
@Test
public void testPath_userInfo() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestRequest request = getClient.testPath_userInfo();
assertThat(request).isNotNull();
assertThat(request.urlString()).isEqualTo("http://aaa%2Fbbb%2Fskip:123456@localhost:" + server.getPort());
System.out.println(request.urlString());
assertThat(request.executeAsString()).isNotNull().isEqualTo(EXPECTED);
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class ForestMethod method invoke.
/**
* 调用方法
* @param args 调用本对象对应方法时传入的参数数组
* @return 调用本对象对应方法结束后返回的值,任意类型的对象实例
*/
public Object invoke(Object[] args) {
Type rType = this.getReturnType();
ForestRequest request = makeRequest(args);
MethodLifeCycleHandler<T> lifeCycleHandler = null;
request.setBackend(configuration.getBackend());
// 如果返回类型为ForestRequest,直接返回请求对象
if (ForestRequest.class.isAssignableFrom(returnClass)) {
Type retType = getReturnType();
if (retType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) retType;
Type[] genTypes = parameterizedType.getActualTypeArguments();
if (genTypes.length > 0) {
Type targetType = genTypes[0];
rType = targetType;
} else {
rType = String.class;
}
if (rType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) rType;
Type[] bounds = wildcardType.getUpperBounds();
if (bounds.length > 0) {
rType = bounds[0];
} else {
rType = String.class;
}
}
Type successType = rType;
if (onSuccessClassGenericType != null) {
successType = onSuccessClassGenericType;
}
lifeCycleHandler = new MethodLifeCycleHandler<>(rType, successType);
request.setLifeCycleHandler(lifeCycleHandler);
lifeCycleHandler.handleInvokeMethod(request, this, args);
return request;
} else {
lifeCycleHandler = new MethodLifeCycleHandler<>(rType, onSuccessClassGenericType);
}
request.setLifeCycleHandler(lifeCycleHandler);
lifeCycleHandler.handleInvokeMethod(request, this, args);
return request;
}
lifeCycleHandler = new MethodLifeCycleHandler<>(rType, onSuccessClassGenericType);
request.setLifeCycleHandler(lifeCycleHandler);
lifeCycleHandler.handleInvokeMethod(request, this, args);
return request.execute();
}
Aggregations