1 /*******************************************************************************
2 * Copyright 2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
13 ******************************************************************************/
14 package org.onap.msb.sdk.httpclient;
16 import java.io.IOException;
17 import java.lang.reflect.Method;
19 import org.onap.msb.sdk.httpclient.handler.RetrofitServiceHandler;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import okhttp3.Request;
24 import retrofit2.Call;
25 import retrofit2.Callback;
26 import retrofit2.Response;
28 public class ProxyRetrofitCall<T extends Object> implements Call<T> {
30 private static final Logger logger = LoggerFactory.getLogger(ProxyRetrofitCall.class);
32 private Call<T> targetCall;
34 private RetrofitServiceHandler handler;
36 private ServiceHttpEndPointObject endPoint;
40 private Method method;
42 private Object[] args;
44 public ProxyRetrofitCall(Call targetCall, RetrofitServiceHandler retrofitServiceHandler,
45 ServiceHttpEndPointObject endPoint, Object proxy, Method method, Object[] args) {
47 this.targetCall = targetCall;
48 this.handler = retrofitServiceHandler;
49 this.endPoint = endPoint;
56 public Response<T> execute() throws IOException {
60 return targetCall.execute();
61 } catch (Exception e) {
63 logger.warn("first invoke httpclient error,endPoint:{},method:{},msg:{}", endPoint, method,
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);
72 } catch (Throwable e2) {
73 logger.error("sencond invoke httpclient error,endPoint:{},method:{}", endPoint, method, e2);
86 public void enqueue(Callback<T> callback) {
87 targetCall.enqueue(callback);
91 public boolean isExecuted() {
92 return targetCall.isExecuted();
96 public void cancel() {
102 public boolean isCanceled() {
103 // TODO Auto-generated method stub
104 return targetCall.isCanceled();
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);
115 public Request request() {
116 return targetCall.request();