Active IQ v6.7.1版本的 MD5 值为:5082594ca2b69fbfbe64e6d6ee2159a7
以下内容为反编译后的 ServiceGenerator.java 源代码,内容仅作参考
package com.netapp.myautosupport.services;
import android.os.Build;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.fabric.sdk.android.services.common.AbstractSpiCall;
import java.io.IOException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.Credentials;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ServiceGenerator {
public static String ACCESS_TOKEN = "";
public static String PUBLIC_API_BASE_URL = "https://api.activeiq-stg.netapp.com/v1/";
public static String SSO_COOKIE = "";
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Gson gson = new GsonBuilder().setLenient().create();
public static String API_BASE_URL = "https://soaexttst.netapp.com/";
private static Retrofit.Builder builder = new Retrofit.Builder().baseUrl(API_BASE_URL).addConverterFactory(GsonConverterFactory.create(gson));
private static Retrofit retrofit = builder.build();
public static <S> S createService(Class<S> cls) {
return (S) createService(cls, 15L);
}
public static <S> S createOAuthService(Class<S> cls) {
return (S) createOAuthService(cls, 360L);
}
public static <S> S createService(Class<S> cls, long j) {
return (S) createService((Class<Object>) cls, j, true);
}
public static <S> S createOAuthService(Class<S> cls, long j) {
return (S) createOAuthService(cls, j, true);
}
public static <S> S createService(Class<S> cls, long j, boolean z) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
final String substring = Locale.getDefault().toString().substring(0, 2);
CookieInterceptor cookieInterceptor = new CookieInterceptor(SSO_COOKIE);
httpClient = new OkHttpClient.Builder();
httpClient.readTimeout(j, TimeUnit.SECONDS);
httpClient.connectTimeout(j, TimeUnit.SECONDS);
if (!httpClient.interceptors().contains(cookieInterceptor)) {
if (z) {
httpClient.addInterceptor(cookieInterceptor);
httpClient.addInterceptor(httpLoggingInterceptor);
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request.Builder newBuilder = chain.request().newBuilder();
newBuilder.addHeader("mobile-os-version", "" + Build.VERSION.RELEASE).build();
newBuilder.addHeader("mobile-app-version", "35").build();
newBuilder.addHeader("mobile-device-type", AbstractSpiCall.ANDROID_CLIENT_TYPE).build();
newBuilder.addHeader("accept-language", substring).build();
return chain.proceed(newBuilder.build());
}
});
}
builder.baseUrl(API_BASE_URL);
builder.client(httpClient.build());
retrofit = builder.build();
}
return (S) retrofit.create(cls);
}
public static <S> S createOAuthService(Class<S> cls, long j, boolean z) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
Locale.getDefault().toString().substring(0, 2);
TokenInterceptor tokenInterceptor = new TokenInterceptor(ACCESS_TOKEN);
httpClient = new OkHttpClient.Builder();
httpClient.readTimeout(j, TimeUnit.SECONDS);
httpClient.connectTimeout(j, TimeUnit.SECONDS);
if (!httpClient.interceptors().contains(tokenInterceptor)) {
if (z) {
httpClient.addInterceptor(tokenInterceptor);
httpClient.addInterceptor(httpLoggingInterceptor);
}
builder.baseUrl(PUBLIC_API_BASE_URL);
builder.client(httpClient.build());
retrofit = builder.build();
}
return (S) retrofit.create(cls);
}
public static <S> S createAlexaOtpService(Class<S> cls) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
final String substring = Locale.getDefault().toString().substring(0, 2);
CookieInterceptor cookieInterceptor = new CookieInterceptor(SSO_COOKIE);
httpClient = getUnsafeOkHttpClient().newBuilder();
httpClient.readTimeout(15L, TimeUnit.SECONDS);
httpClient.connectTimeout(15L, TimeUnit.SECONDS);
if (!httpClient.interceptors().contains(cookieInterceptor)) {
httpClient.addInterceptor(cookieInterceptor);
httpClient.addInterceptor(httpLoggingInterceptor);
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request.Builder newBuilder = chain.request().newBuilder();
newBuilder.addHeader("mobile-os-version", "" + Build.VERSION.RELEASE).build();
newBuilder.addHeader("mobile-app-version", "35").build();
newBuilder.addHeader("mobile-device-type", AbstractSpiCall.ANDROID_CLIENT_TYPE).build();
newBuilder.addHeader("accept-language", substring).build();
return chain.proceed(newBuilder.build());
}
});
builder.baseUrl(API_BASE_URL);
builder.client(httpClient.build());
retrofit = builder.build();
}
return (S) retrofit.create(cls);
}
public static <S> S createService(Class<S> cls, String str, String str2) {
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
return (S) createService(cls, Credentials.basic(str, str2));
}
return (S) createService(cls, (String) null, (String) null);
}
public static <S> S createService(Class<S> cls, String str) {
if (!TextUtils.isEmpty(str)) {
AuthenticationInterceptor authenticationInterceptor = new AuthenticationInterceptor(str);
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
httpClient = new OkHttpClient.Builder();
httpClient.readTimeout(30L, TimeUnit.SECONDS);
httpClient.connectTimeout(30L, TimeUnit.SECONDS);
if (!httpClient.interceptors().contains(authenticationInterceptor)) {
httpClient.addInterceptor(authenticationInterceptor);
httpClient.addInterceptor(httpLoggingInterceptor);
builder.client(httpClient.build());
retrofit = builder.build();
}
}
return (S) retrofit.create(cls);
}
public static void setRequiredValues(String str, String str2, String str3, String str4) {
SSO_COOKIE = str;
ACCESS_TOKEN = str2;
API_BASE_URL = str3;
PUBLIC_API_BASE_URL = str4;
builder.baseUrl(API_BASE_URL);
}
public static OkHttpClient getUnsafeOkHttpClient() {
try {
TrustManager[] trustManagerArr = {new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}};
SSLContext sSLContext = SSLContext.getInstance("SSL");
sSLContext.init(null, trustManagerArr, new SecureRandom());
SSLSocketFactory socketFactory = sSLContext.getSocketFactory();
OkHttpClient.Builder builder2 = new OkHttpClient.Builder();
builder2.sslSocketFactory(socketFactory, (X509TrustManager) trustManagerArr[0]);
builder2.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String str, SSLSession sSLSession) {
return true;
}
});
return builder2.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}