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.onap.msb.sdk.httpclient.metric.MetricObject;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import okhttp3.Request;
25 import retrofit2.Call;
26 import retrofit2.Callback;
27 import retrofit2.Response;
29 public class ProxyRetrofitCall<T extends Object> implements Call<T> {
31 private static final Logger logger = LoggerFactory.getLogger(ProxyRetrofitCall.class);
33 private Call<T> targetCall;
35 private RetrofitServiceHandler handler;
37 private ServiceHttpEndPointObject endPoint;
41 private Method method;
43 private Object[] args;
45 private MetricObject metricObject;
49 public ProxyRetrofitCall(Call targetCall, RetrofitServiceHandler retrofitServiceHandler,
50 ServiceHttpEndPointObject endPoint, Object proxy, Method method, Object[] args,
51 MetricObject metricObject) {
53 this.targetCall = targetCall;
54 this.handler = retrofitServiceHandler;
55 this.endPoint = endPoint;
59 this.metricObject = metricObject;
63 public Response<T> execute() throws IOException {
67 return targetCall.execute();
68 } catch (Exception e) {
70 logger.warn("first invoke httpclient error,endPoint:{},method:{},msg:{}", endPoint, method,
76 return ((Call) handler.reInvoke(proxy, method, args, endPoint)).execute();
77 } catch (IOException e1) {
78 logger.error("sencond invoke httpclient error,endPoint:{},method:{}", endPoint, method, e1);
80 } catch (Throwable e2) {
81 logger.error("sencond invoke httpclient error,endPoint:{},method:{}", endPoint, method, e2);
94 public void enqueue(Callback<T> callback) {
95 targetCall.enqueue(callback);
99 public boolean isExecuted() {
100 return targetCall.isExecuted();
104 public void cancel() {
110 public boolean isCanceled() {
111 // TODO Auto-generated method stub
112 return targetCall.isCanceled();
116 public Call<T> clone() {
117 // TODO Auto-generated method stub
118 return new ProxyRetrofitCall(targetCall.clone(), this.handler, this.endPoint, this.proxy,
119 this.method, this.args, metricObject);
123 public Request request() {
124 return targetCall.request();