what-the-bank/sources/retrofit2/HttpServiceMethod.java

160 lines
7.8 KiB
Java

package retrofit2;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import o.InterfaceC14907gbi;
import okhttp3.Call;
import okhttp3.ResponseBody;
import retrofit2.Utils;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public abstract class HttpServiceMethod<ResponseT, ReturnT> extends ServiceMethod<ReturnT> {
private final Call.Factory callFactory;
private final RequestFactory requestFactory;
private final Converter<ResponseBody, ResponseT> responseConverter;
protected abstract ReturnT adapt(Call<ResponseT> call, Object[] objArr);
/* JADX INFO: Access modifiers changed from: package-private */
public static <ResponseT, ReturnT> HttpServiceMethod<ResponseT, ReturnT> parseAnnotations(Retrofit retrofit, Method method, RequestFactory requestFactory) {
Type genericReturnType;
boolean z;
boolean z2 = requestFactory.isKotlinSuspendFunction;
Annotation[] annotations = method.getAnnotations();
if (z2) {
Type[] genericParameterTypes = method.getGenericParameterTypes();
z = true;
Type parameterLowerBound = Utils.getParameterLowerBound(0, (ParameterizedType) genericParameterTypes[genericParameterTypes.length - 1]);
if (Utils.getRawType(parameterLowerBound) == Response.class && (parameterLowerBound instanceof ParameterizedType)) {
parameterLowerBound = Utils.getParameterUpperBound(0, (ParameterizedType) parameterLowerBound);
} else {
z = false;
}
genericReturnType = new Utils.ParameterizedTypeImpl(null, Call.class, parameterLowerBound);
annotations = SkipCallbackExecutorImpl.ensurePresent(annotations);
} else {
genericReturnType = method.getGenericReturnType();
z = false;
}
CallAdapter createCallAdapter = createCallAdapter(retrofit, method, genericReturnType, annotations);
Type responseType = createCallAdapter.responseType();
if (responseType == okhttp3.Response.class) {
StringBuilder sb = new StringBuilder("'");
sb.append(Utils.getRawType(responseType).getName());
sb.append("' is not a valid response body type. Did you mean ResponseBody?");
throw Utils.methodError(method, sb.toString(), new Object[0]);
}
if (responseType == Response.class) {
throw Utils.methodError(method, "Response must include generic type (e.g., Response<String>)", new Object[0]);
}
if (requestFactory.httpMethod.equals("HEAD") && !Void.class.equals(responseType)) {
throw Utils.methodError(method, "HEAD method must use Void as response type.", new Object[0]);
}
Converter createResponseConverter = createResponseConverter(retrofit, method, responseType);
Call.Factory factory = retrofit.callFactory;
if (!z2) {
return new CallAdapted(requestFactory, factory, createResponseConverter, createCallAdapter);
}
if (z) {
return new SuspendForResponse(requestFactory, factory, createResponseConverter, createCallAdapter);
}
return new SuspendForBody(requestFactory, factory, createResponseConverter, createCallAdapter, false);
}
private static <ResponseT, ReturnT> CallAdapter<ResponseT, ReturnT> createCallAdapter(Retrofit retrofit, Method method, Type type, Annotation[] annotationArr) {
try {
return (CallAdapter<ResponseT, ReturnT>) retrofit.callAdapter(type, annotationArr);
} catch (RuntimeException e) {
throw Utils.methodError(method, e, "Unable to create call adapter for %s", type);
}
}
private static <ResponseT> Converter<ResponseBody, ResponseT> createResponseConverter(Retrofit retrofit, Method method, Type type) {
try {
return retrofit.responseBodyConverter(type, method.getAnnotations());
} catch (RuntimeException e) {
throw Utils.methodError(method, e, "Unable to create converter for %s", type);
}
}
HttpServiceMethod(RequestFactory requestFactory, Call.Factory factory, Converter<ResponseBody, ResponseT> converter) {
this.requestFactory = requestFactory;
this.callFactory = factory;
this.responseConverter = converter;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ServiceMethod
public final ReturnT invoke(Object[] objArr) {
return adapt(new OkHttpCall(this.requestFactory, objArr, this.callFactory, this.responseConverter), objArr);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class CallAdapted<ResponseT, ReturnT> extends HttpServiceMethod<ResponseT, ReturnT> {
private final CallAdapter<ResponseT, ReturnT> callAdapter;
CallAdapted(RequestFactory requestFactory, Call.Factory factory, Converter<ResponseBody, ResponseT> converter, CallAdapter<ResponseT, ReturnT> callAdapter) {
super(requestFactory, factory, converter);
this.callAdapter = callAdapter;
}
@Override // retrofit2.HttpServiceMethod
protected final ReturnT adapt(Call<ResponseT> call, Object[] objArr) {
return this.callAdapter.adapt(call);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class SuspendForResponse<ResponseT> extends HttpServiceMethod<ResponseT, Object> {
private final CallAdapter<ResponseT, Call<ResponseT>> callAdapter;
SuspendForResponse(RequestFactory requestFactory, Call.Factory factory, Converter<ResponseBody, ResponseT> converter, CallAdapter<ResponseT, Call<ResponseT>> callAdapter) {
super(requestFactory, factory, converter);
this.callAdapter = callAdapter;
}
@Override // retrofit2.HttpServiceMethod
protected final Object adapt(Call<ResponseT> call, Object[] objArr) {
Call<ResponseT> adapt = this.callAdapter.adapt(call);
InterfaceC14907gbi interfaceC14907gbi = (InterfaceC14907gbi) objArr[objArr.length - 1];
try {
return KotlinExtensions.awaitResponse(adapt, interfaceC14907gbi);
} catch (Exception e) {
return KotlinExtensions.suspendAndThrow(e, interfaceC14907gbi);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class SuspendForBody<ResponseT> extends HttpServiceMethod<ResponseT, Object> {
private final CallAdapter<ResponseT, Call<ResponseT>> callAdapter;
private final boolean isNullable;
SuspendForBody(RequestFactory requestFactory, Call.Factory factory, Converter<ResponseBody, ResponseT> converter, CallAdapter<ResponseT, Call<ResponseT>> callAdapter, boolean z) {
super(requestFactory, factory, converter);
this.callAdapter = callAdapter;
this.isNullable = z;
}
@Override // retrofit2.HttpServiceMethod
protected final Object adapt(Call<ResponseT> call, Object[] objArr) {
Call<ResponseT> adapt = this.callAdapter.adapt(call);
InterfaceC14907gbi interfaceC14907gbi = (InterfaceC14907gbi) objArr[objArr.length - 1];
try {
if (this.isNullable) {
return KotlinExtensions.awaitNullable(adapt, interfaceC14907gbi);
}
return KotlinExtensions.await(adapt, interfaceC14907gbi);
} catch (Exception e) {
return KotlinExtensions.suspendAndThrow(e, interfaceC14907gbi);
}
}
}
}