|
5 | 5 | import com.getui.push.v2.sdk.anno.param.GtQueryParam; |
6 | 6 | import com.getui.push.v2.sdk.common.ApiException; |
7 | 7 | import com.getui.push.v2.sdk.common.Assert; |
8 | | -import com.getui.push.v2.sdk.common.util.Utils; |
9 | 8 | import com.getui.push.v2.sdk.core.client.DefaultApiClient; |
10 | 9 | import com.getui.push.v2.sdk.core.registry.DefaultGtApiRegistry; |
11 | 10 | import com.getui.push.v2.sdk.core.registry.GtApiRegistry; |
|
26 | 25 | * |
27 | 26 | * @author getui |
28 | 27 | */ |
29 | | -public class GtApiProxyFactory implements InvocationHandler { |
| 28 | +public class GtApiProxyFactory { |
30 | 29 |
|
31 | 30 | /** |
32 | 31 | * 保证一个{@link DefaultApiClient}对象对应一个{@link GtApiProxyFactory}对象 |
@@ -71,19 +70,25 @@ private GtApiProxyFactory(DefaultApiClient defaultApiClient) { |
71 | 70 | * @return |
72 | 71 | */ |
73 | 72 | public <T> T createProxy(Class<T> apiService) { |
74 | | - return (T) Proxy.newProxyInstance(apiService.getClassLoader(), new Class[]{apiService}, this); |
| 73 | + return (T) Proxy.newProxyInstance(apiService.getClassLoader(), new Class[]{apiService}, new ApiProxyHandler()); |
75 | 74 | } |
76 | 75 |
|
77 | | - @Override |
78 | | - public Object invoke(Object proxy, Method method, Object[] args) { |
79 | | - if ("toString".equalsIgnoreCase(method.getName()) && Utils.isEmpty(args)) { |
80 | | - return this.toString(); |
| 76 | + class ApiProxyHandler implements InvocationHandler { |
| 77 | + @Override |
| 78 | + public Object invoke(Object proxy, Method method, Object[] args) { |
| 79 | + try { |
| 80 | + if (Object.class.equals(method.getDeclaringClass())) { |
| 81 | + return method.invoke(this, args); |
| 82 | + } |
| 83 | + } catch (Throwable t) { |
| 84 | + throw new RuntimeException(t); |
| 85 | + } |
| 86 | + final BaseParam baseParam = gtApiRegistry.get(method); |
| 87 | + ApiParam apiParam = new ApiParam(baseParam); |
| 88 | + // 解析参数 -> HTTP参数 |
| 89 | + handleApiParam(method, args, apiParam); |
| 90 | + return defaultApiClient.execute(apiParam); |
81 | 91 | } |
82 | | - final BaseParam baseParam = gtApiRegistry.get(method); |
83 | | - ApiParam apiParam = new ApiParam(baseParam); |
84 | | - // 解析参数 -> HTTP参数 |
85 | | - handleApiParam(method, args, apiParam); |
86 | | - return defaultApiClient.execute(apiParam); |
87 | 92 | } |
88 | 93 |
|
89 | 94 | /** |
|
0 commit comments