Skip to content

Commit

Permalink
每次请求都用最新的client
Browse files Browse the repository at this point in the history
  • Loading branch information
yhyzgn committed May 29, 2020
1 parent d8eb662 commit 91b12a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.yhyzgn.http</groupId>
<artifactId>pigeon</artifactId>
<version>1.1.8</version>
<version>1.2.0</version>
<name>Pigeon</name>
<description>Java http proxy.</description>
<url>/~https://github.com/yhyzgn/Pigeon</url>
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/yhy/http/pigeon/http/HttpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.yhy.http.pigeon.common.OkCall;
import com.yhy.http.pigeon.converter.Converter;
import com.yhy.http.pigeon.http.request.RequestFactory;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;

import java.lang.annotation.Annotation;
Expand All @@ -18,24 +17,24 @@
* e-mail : yhyzgn@gmail.com
* time : 2019-09-02 17:31
* version: 1.0.0
* desc :
* desc : http请求处理器
*/
@SuppressWarnings("unchecked")
public abstract class HttpHandler<Res, Ret> extends HttpMethod<Ret> {

private final RequestFactory requestFactory;
private final OkHttpClient.Builder client;
private final Pigeon pigeon;
private final Converter<ResponseBody, Res> responseConverter;

private HttpHandler(RequestFactory requestFactory, OkHttpClient.Builder client, Converter<ResponseBody, Res> responseConverter) {
private HttpHandler(RequestFactory requestFactory, Pigeon pigeon, Converter<ResponseBody, Res> responseConverter) {
this.requestFactory = requestFactory;
this.client = client;
this.pigeon = pigeon;
this.responseConverter = responseConverter;
}

@Override
public Ret invoke(Object[] args) throws Exception {
OkCall<Res> call = new OkCall<>(requestFactory, client, responseConverter, args);
// 每次请求都用最新(干净)的 pigeon.client()
OkCall<Res> call = new OkCall<>(requestFactory, pigeon.client(), responseConverter, args);
return adapt(call, args);
}

Expand All @@ -48,7 +47,7 @@ public static <Res, Ret> HttpHandler<Res, Ret> parseAnnotations(Pigeon pigeon, M
Type responseType = callAdapter.responseType();
Converter<ResponseBody, Res> responseConverter = createResponseConverter(pigeon, annotations, responseType);

return new AdaptedCall<>(factory, pigeon.client(), responseConverter, callAdapter);
return new AdaptedCall<>(factory, pigeon, responseConverter, callAdapter);
}

private static <Res> Converter<ResponseBody, Res> createResponseConverter(Pigeon pigeon, Annotation[] annotations, Type responseType) {
Expand All @@ -63,8 +62,8 @@ public static class AdaptedCall<Res, Ret> extends HttpHandler<Res, Ret> {

private final CallAdapter<Res, Ret> callAdapter;

AdaptedCall(RequestFactory requestFactory, OkHttpClient.Builder client, Converter<ResponseBody, Res> responseConverter, CallAdapter<Res, Ret> callAdapter) {
super(requestFactory, client, responseConverter);
AdaptedCall(RequestFactory requestFactory, Pigeon pigeon, Converter<ResponseBody, Res> responseConverter, CallAdapter<Res, Ret> callAdapter) {
super(requestFactory, pigeon, responseConverter);
this.callAdapter = callAdapter;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/yhy/http/pigeon/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class Utils {
private static final Type[] EMPTY_TYPE_ARRAY = new Type[0];
public final static String VERSION = "1.1.8";
public final static String VERSION = "1.2.0";

public static boolean isEmpty(Object object) {
if (null == object) return true;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/pigeon/get/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public interface Api {
Cat mp(@Header Map<String, Object> header, @Query Map<String, Object> params);

@GET
@Interceptor(value = TestInterceptor.class, net = true)
Cat def(@Header Map<String, Object> header, @Query Map<String, Object> params);
}
2 changes: 2 additions & 0 deletions src/test/java/pigeon/get/ApiTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public static void main(String[] args) throws IOException {
// Cat cat = api.mp(header, params);
Cat cat = api.def(header, params);
System.out.println(cat);
cat = api.def(header, params);
System.out.println(cat);
}
}

0 comments on commit 91b12a7

Please sign in to comment.