Remove Chinese comments
[msb/java-sdk.git] / src / main / java / org / onap / msb / sdk / httpclient / ProxyRetrofitCall.java
1 /*******************************************************************************
2  * Copyright 2017 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.sdk.httpclient;
15
16 import java.io.IOException;
17 import java.lang.reflect.Method;
18
19 import org.onap.msb.sdk.httpclient.handler.RetrofitServiceHandler;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import okhttp3.Request;
24 import retrofit2.Call;
25 import retrofit2.Callback;
26 import retrofit2.Response;
27
28 public class ProxyRetrofitCall<T extends Object> implements Call<T> {
29
30   private static final Logger logger = LoggerFactory.getLogger(ProxyRetrofitCall.class);
31
32   private Call<T> targetCall;
33
34   private RetrofitServiceHandler handler;
35
36   private ServiceHttpEndPointObject endPoint;
37
38   private Object proxy;
39
40   private Method method;
41
42   private Object[] args;
43
44   public ProxyRetrofitCall(Call targetCall, RetrofitServiceHandler retrofitServiceHandler,
45       ServiceHttpEndPointObject endPoint, Object proxy, Method method, Object[] args) {
46     super();
47     this.targetCall = targetCall;
48     this.handler = retrofitServiceHandler;
49     this.endPoint = endPoint;
50     this.proxy = proxy;
51     this.method = method;
52     this.args = args;
53   }
54
55   @Override
56   public Response<T> execute() throws IOException {
57
58
59     try {
60       return targetCall.execute();
61     } catch (Exception e) {
62
63       logger.warn("first invoke httpclient error,endPoint:{},method:{},msg:{}", endPoint, method,
64           e.getMessage());
65
66       handler.clean();
67       try {
68         return ((Call) handler.reInvoke(proxy, method, args, endPoint)).execute();
69       } catch (IOException e1) {
70         logger.error("sencond invoke httpclient error,endPoint:{},method:{}", endPoint, method, e1);
71         throw e1;
72       } catch (Throwable e2) {
73         logger.error("sencond invoke httpclient error,endPoint:{},method:{}", endPoint, method, e2);
74         throw e;
75       }
76
77
78
79     } finally {
80
81     }
82
83   }
84
85   @Override
86   public void enqueue(Callback<T> callback) {
87     targetCall.enqueue(callback);
88   }
89
90   @Override
91   public boolean isExecuted() {
92     return targetCall.isExecuted();
93   }
94
95   @Override
96   public void cancel() {
97     targetCall.cancel();
98
99   }
100
101   @Override
102   public boolean isCanceled() {
103     // TODO Auto-generated method stub
104     return targetCall.isCanceled();
105   }
106
107   @Override
108   public Call<T> clone() {
109     // TODO Auto-generated method stub
110     return new ProxyRetrofitCall(targetCall.clone(), this.handler, this.endPoint, this.proxy,
111         this.method, this.args);
112   }
113
114   @Override
115   public Request request() {
116     return targetCall.request();
117   }
118
119 }