Initial commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog;
|
||||
import com.alibaba.sdk.android.oss.common.utils.CaseInsensitiveHashMap;
|
||||
import com.alibaba.sdk.android.oss.model.OSSResult;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigInteger;
|
||||
import java.util.zip.CheckedInputStream;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Response;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class AbstractResponseParser<T extends OSSResult> implements ResponseParser {
|
||||
public static void b(ResponseMessage responseMessage) {
|
||||
try {
|
||||
responseMessage.a();
|
||||
} catch (Exception unused) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.alibaba.sdk.android.oss.internal.ResponseParser
|
||||
public T a(ResponseMessage responseMessage) throws IOException {
|
||||
try {
|
||||
try {
|
||||
T t = (T) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
|
||||
if (t != null) {
|
||||
t.a(responseMessage.d().get("x-oss-request-id"));
|
||||
t.a(responseMessage.h());
|
||||
t.a(a(responseMessage.g()));
|
||||
a((AbstractResponseParser<T>) t, responseMessage);
|
||||
t = a(responseMessage, (ResponseMessage) t);
|
||||
}
|
||||
return t;
|
||||
} catch (Exception e) {
|
||||
IOException iOException = new IOException(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
OSSLog.a(e);
|
||||
throw iOException;
|
||||
}
|
||||
} finally {
|
||||
if (a()) {
|
||||
b(responseMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract T a(ResponseMessage responseMessage, T t) throws Exception;
|
||||
|
||||
public boolean a() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private CaseInsensitiveHashMap<String, String> a(Response response) {
|
||||
CaseInsensitiveHashMap<String, String> caseInsensitiveHashMap = new CaseInsensitiveHashMap<>();
|
||||
Headers headers = response.headers();
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
caseInsensitiveHashMap.put(headers.name(i), headers.value(i));
|
||||
}
|
||||
return caseInsensitiveHashMap;
|
||||
}
|
||||
|
||||
public <Result extends OSSResult> void a(Result result, ResponseMessage responseMessage) {
|
||||
InputStream b = responseMessage.f().b();
|
||||
if (b != null && (b instanceof CheckedInputStream)) {
|
||||
result.a(Long.valueOf(((CheckedInputStream) b).getChecksum().getValue()));
|
||||
}
|
||||
String str = responseMessage.d().get("x-oss-hash-crc64ecma");
|
||||
if (str != null) {
|
||||
result.b(Long.valueOf(new BigInteger(str).longValue()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ExtensionRequestOperation {
|
||||
static {
|
||||
Executors.newFixedThreadPool(5, new ThreadFactory() { // from class: com.alibaba.sdk.android.oss.internal.ExtensionRequestOperation.1
|
||||
@Override // java.util.concurrent.ThreadFactory
|
||||
public Thread newThread(Runnable runnable) {
|
||||
return new Thread(runnable, "oss-android-extensionapi-thread");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ExtensionRequestOperation(InternalRequestOperation internalRequestOperation) {
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import com.alibaba.sdk.android.oss.common.utils.CaseInsensitiveHashMap;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: package-private */
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class HttpMessage {
|
||||
private Map<String, String> a = new CaseInsensitiveHashMap();
|
||||
private InputStream b;
|
||||
private long c;
|
||||
private String d;
|
||||
|
||||
HttpMessage() {
|
||||
}
|
||||
|
||||
public void a(Map<String, String> map) {
|
||||
if (this.a == null) {
|
||||
this.a = new CaseInsensitiveHashMap();
|
||||
}
|
||||
Map<String, String> map2 = this.a;
|
||||
if (map2 != null && map2.size() > 0) {
|
||||
this.a.clear();
|
||||
}
|
||||
this.a.putAll(map);
|
||||
}
|
||||
|
||||
public InputStream b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public long c() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public Map<String, String> d() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public String e() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public void a(String str, String str2) {
|
||||
this.a.put(str, str2);
|
||||
}
|
||||
|
||||
public void a(InputStream inputStream) {
|
||||
this.b = inputStream;
|
||||
}
|
||||
|
||||
public void a(long j) {
|
||||
this.c = j;
|
||||
}
|
||||
|
||||
public void a() throws IOException {
|
||||
InputStream inputStream = this.b;
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
this.b = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,200 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import com.alibaba.sdk.android.oss.ClientConfiguration;
|
||||
import com.alibaba.sdk.android.oss.ClientException;
|
||||
import com.alibaba.sdk.android.oss.ServiceException;
|
||||
import com.alibaba.sdk.android.oss.callback.OSSCompletedCallback;
|
||||
import com.alibaba.sdk.android.oss.common.HttpMethod;
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog;
|
||||
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
|
||||
import com.alibaba.sdk.android.oss.common.utils.DateUtil;
|
||||
import com.alibaba.sdk.android.oss.common.utils.OSSUtils;
|
||||
import com.alibaba.sdk.android.oss.common.utils.VersionInfoUtils;
|
||||
import com.alibaba.sdk.android.oss.exception.InconsistentException;
|
||||
import com.alibaba.sdk.android.oss.internal.ResponseParsers;
|
||||
import com.alibaba.sdk.android.oss.model.OSSRequest;
|
||||
import com.alibaba.sdk.android.oss.model.OSSResult;
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectRequest;
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectResult;
|
||||
import com.alibaba.sdk.android.oss.network.ExecutionContext;
|
||||
import com.alibaba.sdk.android.oss.network.OSSRequestTask;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.Dispatcher;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class InternalRequestOperation {
|
||||
private static ExecutorService g = Executors.newFixedThreadPool(5, new ThreadFactory() { // from class: com.alibaba.sdk.android.oss.internal.InternalRequestOperation.1
|
||||
@Override // java.util.concurrent.ThreadFactory
|
||||
public Thread newThread(Runnable runnable) {
|
||||
return new Thread(runnable, "oss-android-api-thread");
|
||||
}
|
||||
});
|
||||
private volatile URI a;
|
||||
private OkHttpClient b;
|
||||
private Context c;
|
||||
private OSSCredentialProvider d;
|
||||
private int e;
|
||||
private ClientConfiguration f;
|
||||
|
||||
public InternalRequestOperation(Context context, final URI uri, OSSCredentialProvider oSSCredentialProvider, ClientConfiguration clientConfiguration) {
|
||||
this.e = 2;
|
||||
this.c = context;
|
||||
this.a = uri;
|
||||
this.d = oSSCredentialProvider;
|
||||
this.f = clientConfiguration;
|
||||
OkHttpClient.Builder hostnameVerifier = new OkHttpClient.Builder().followRedirects(false).followSslRedirects(false).retryOnConnectionFailure(false).cache(null).hostnameVerifier(new HostnameVerifier(this) { // from class: com.alibaba.sdk.android.oss.internal.InternalRequestOperation.2
|
||||
@Override // javax.net.ssl.HostnameVerifier
|
||||
public boolean verify(String str, SSLSession sSLSession) {
|
||||
return HttpsURLConnection.getDefaultHostnameVerifier().verify(uri.getHost(), sSLSession);
|
||||
}
|
||||
});
|
||||
if (clientConfiguration != null) {
|
||||
Dispatcher dispatcher = new Dispatcher();
|
||||
dispatcher.setMaxRequests(clientConfiguration.e());
|
||||
hostnameVerifier.connectTimeout(clientConfiguration.a(), TimeUnit.MILLISECONDS).readTimeout(clientConfiguration.j(), TimeUnit.MILLISECONDS).writeTimeout(clientConfiguration.j(), TimeUnit.MILLISECONDS).dispatcher(dispatcher);
|
||||
if (clientConfiguration.h() != null && clientConfiguration.i() != 0) {
|
||||
hostnameVerifier.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(clientConfiguration.h(), clientConfiguration.i())));
|
||||
}
|
||||
this.e = clientConfiguration.f();
|
||||
}
|
||||
this.b = hostnameVerifier.build();
|
||||
}
|
||||
|
||||
public OSSAsyncTask<PutObjectResult> a(PutObjectRequest putObjectRequest, final OSSCompletedCallback<PutObjectRequest, PutObjectResult> oSSCompletedCallback) {
|
||||
OSSLog.a(" Internal putObject Start ");
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
requestMessage.d(putObjectRequest.b());
|
||||
requestMessage.a(this.a);
|
||||
requestMessage.a(HttpMethod.PUT);
|
||||
requestMessage.a(putObjectRequest.c());
|
||||
requestMessage.c(putObjectRequest.g());
|
||||
if (putObjectRequest.j() != null) {
|
||||
requestMessage.a(putObjectRequest.j());
|
||||
}
|
||||
if (putObjectRequest.k() != null) {
|
||||
requestMessage.d(putObjectRequest.k());
|
||||
}
|
||||
if (putObjectRequest.l() != null) {
|
||||
requestMessage.a(putObjectRequest.l());
|
||||
}
|
||||
if (putObjectRequest.d() != null) {
|
||||
requestMessage.d().put("x-oss-callback", OSSUtils.a(putObjectRequest.d()));
|
||||
}
|
||||
if (putObjectRequest.e() != null) {
|
||||
requestMessage.d().put("x-oss-callback-var", OSSUtils.a(putObjectRequest.e()));
|
||||
}
|
||||
OSSLog.a(" populateRequestMetadata ");
|
||||
OSSUtils.a(requestMessage.d(), putObjectRequest.f());
|
||||
OSSLog.a(" canonicalizeRequestMessage ");
|
||||
a(requestMessage, putObjectRequest);
|
||||
OSSLog.a(" ExecutionContext ");
|
||||
ExecutionContext executionContext = new ExecutionContext(a(), putObjectRequest, this.c);
|
||||
if (oSSCompletedCallback != null) {
|
||||
executionContext.a(new OSSCompletedCallback<PutObjectRequest, PutObjectResult>() { // from class: com.alibaba.sdk.android.oss.internal.InternalRequestOperation.4
|
||||
@Override // com.alibaba.sdk.android.oss.callback.OSSCompletedCallback
|
||||
public void a(PutObjectRequest putObjectRequest2, PutObjectResult putObjectResult) {
|
||||
InternalRequestOperation.this.a(putObjectRequest2, putObjectResult, oSSCompletedCallback);
|
||||
}
|
||||
|
||||
@Override // com.alibaba.sdk.android.oss.callback.OSSCompletedCallback
|
||||
public void a(PutObjectRequest putObjectRequest2, ClientException clientException, ServiceException serviceException) {
|
||||
oSSCompletedCallback.a(putObjectRequest2, clientException, serviceException);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (putObjectRequest.i() != null) {
|
||||
executionContext.a(putObjectRequest.i());
|
||||
}
|
||||
executionContext.a(putObjectRequest.h());
|
||||
OSSRequestTask oSSRequestTask = new OSSRequestTask(requestMessage, new ResponseParsers.PutObjectResponseParser(), executionContext, this.e);
|
||||
OSSLog.a(" call OSSRequestTask ");
|
||||
return OSSAsyncTask.a(g.submit(oSSRequestTask), executionContext);
|
||||
}
|
||||
|
||||
private boolean a(boolean z) {
|
||||
String host;
|
||||
if (!z || this.c == null) {
|
||||
return false;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 14) {
|
||||
host = System.getProperty("http.proxyHost");
|
||||
} else {
|
||||
host = android.net.Proxy.getHost(this.c);
|
||||
}
|
||||
String h = this.f.h();
|
||||
if (!TextUtils.isEmpty(h)) {
|
||||
host = h;
|
||||
}
|
||||
return TextUtils.isEmpty(host);
|
||||
}
|
||||
|
||||
public OkHttpClient a() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
private void a(RequestMessage requestMessage, OSSRequest oSSRequest) {
|
||||
Map<String, String> d = requestMessage.d();
|
||||
if (d.get("Date") == null) {
|
||||
d.put("Date", DateUtil.a());
|
||||
}
|
||||
if ((requestMessage.j() == HttpMethod.POST || requestMessage.j() == HttpMethod.PUT) && OSSUtils.c(d.get("Content-Type"))) {
|
||||
d.put("Content-Type", OSSUtils.a((String) null, requestMessage.n(), requestMessage.k()));
|
||||
}
|
||||
requestMessage.c(a(this.f.m()));
|
||||
requestMessage.a(this.d);
|
||||
requestMessage.f(this.f.n());
|
||||
requestMessage.b(this.f.l());
|
||||
requestMessage.b(this.f.d());
|
||||
requestMessage.d().put("User-Agent", VersionInfoUtils.a(this.f.c()));
|
||||
boolean z = false;
|
||||
if (requestMessage.d().containsKey("Range") || requestMessage.l().containsKey("x-oss-process")) {
|
||||
requestMessage.a(false);
|
||||
}
|
||||
requestMessage.e(OSSUtils.a(this.a.getHost(), this.f.b()));
|
||||
if (oSSRequest.a() == OSSRequest.CRC64Config.NULL) {
|
||||
z = this.f.k();
|
||||
} else if (oSSRequest.a() == OSSRequest.CRC64Config.YES) {
|
||||
z = true;
|
||||
}
|
||||
requestMessage.a(z);
|
||||
oSSRequest.a(z ? OSSRequest.CRC64Config.YES : OSSRequest.CRC64Config.NO);
|
||||
}
|
||||
|
||||
private <Request extends OSSRequest, Result extends OSSResult> void a(Request request, Result result) throws ClientException {
|
||||
if (request.a() == OSSRequest.CRC64Config.YES) {
|
||||
try {
|
||||
OSSUtils.a(result.a(), result.c(), result.b());
|
||||
} catch (InconsistentException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public <Request extends OSSRequest, Result extends OSSResult> void a(Request request, Result result, OSSCompletedCallback<Request, Result> oSSCompletedCallback) {
|
||||
try {
|
||||
a((InternalRequestOperation) request, (Request) result);
|
||||
if (oSSCompletedCallback != null) {
|
||||
oSSCompletedCallback.a(request, result);
|
||||
}
|
||||
} catch (ClientException e) {
|
||||
if (oSSCompletedCallback != null) {
|
||||
oSSCompletedCallback.a(request, e, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import com.alibaba.sdk.android.oss.model.OSSResult;
|
||||
import com.alibaba.sdk.android.oss.network.ExecutionContext;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OSSAsyncTask<T extends OSSResult> {
|
||||
private ExecutionContext a;
|
||||
private volatile boolean b;
|
||||
|
||||
public static OSSAsyncTask a(Future future, ExecutionContext executionContext) {
|
||||
OSSAsyncTask oSSAsyncTask = new OSSAsyncTask();
|
||||
oSSAsyncTask.a = executionContext;
|
||||
return oSSAsyncTask;
|
||||
}
|
||||
|
||||
public boolean b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public void a() {
|
||||
this.b = true;
|
||||
ExecutionContext executionContext = this.a;
|
||||
if (executionContext != null) {
|
||||
executionContext.b().a();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import com.alibaba.sdk.android.oss.ClientException;
|
||||
import com.alibaba.sdk.android.oss.ServiceException;
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OSSRetryHandler {
|
||||
private int a = 2;
|
||||
|
||||
/* renamed from: com.alibaba.sdk.android.oss.internal.OSSRetryHandler$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[OSSRetryType.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[OSSRetryType.OSSRetryTypeShouldRetry.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OSSRetryHandler(int i) {
|
||||
a(i);
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
this.a = i;
|
||||
}
|
||||
|
||||
public OSSRetryType a(Exception exc, int i) {
|
||||
if (i >= this.a) {
|
||||
return OSSRetryType.OSSRetryTypeShouldNotRetry;
|
||||
}
|
||||
if (!(exc instanceof ClientException)) {
|
||||
if (!(exc instanceof ServiceException)) {
|
||||
return OSSRetryType.OSSRetryTypeShouldNotRetry;
|
||||
}
|
||||
ServiceException serviceException = (ServiceException) exc;
|
||||
return (serviceException.getErrorCode() == null || !serviceException.getErrorCode().equalsIgnoreCase("RequestTimeTooSkewed")) ? serviceException.getStatusCode() >= 500 ? OSSRetryType.OSSRetryTypeShouldRetry : OSSRetryType.OSSRetryTypeShouldNotRetry : OSSRetryType.OSSRetryTypeShouldFixedTimeSkewedAndRetry;
|
||||
}
|
||||
if (((ClientException) exc).isCanceledException().booleanValue()) {
|
||||
return OSSRetryType.OSSRetryTypeShouldNotRetry;
|
||||
}
|
||||
Exception exc2 = (Exception) exc.getCause();
|
||||
if ((exc2 instanceof InterruptedIOException) && !(exc2 instanceof SocketTimeoutException)) {
|
||||
OSSLog.b("[shouldRetry] - is interrupted!");
|
||||
return OSSRetryType.OSSRetryTypeShouldNotRetry;
|
||||
}
|
||||
if (exc2 instanceof IllegalArgumentException) {
|
||||
return OSSRetryType.OSSRetryTypeShouldNotRetry;
|
||||
}
|
||||
OSSLog.a("shouldRetry - " + exc.toString());
|
||||
exc.getCause().printStackTrace();
|
||||
return OSSRetryType.OSSRetryTypeShouldRetry;
|
||||
}
|
||||
|
||||
public long a(int i, OSSRetryType oSSRetryType) {
|
||||
if (AnonymousClass1.a[oSSRetryType.ordinal()] != 1) {
|
||||
return 0L;
|
||||
}
|
||||
return ((long) Math.pow(2.0d, i)) * 200;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public enum OSSRetryType {
|
||||
OSSRetryTypeShouldNotRetry,
|
||||
OSSRetryTypeShouldRetry,
|
||||
OSSRetryTypeShouldFixedTimeSkewedAndRetry
|
||||
}
|
210
sources/com/alibaba/sdk/android/oss/internal/RequestMessage.java
Normal file
210
sources/com/alibaba/sdk/android/oss/internal/RequestMessage.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import com.alibaba.sdk.android.oss.common.HttpMethod;
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog;
|
||||
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
|
||||
import com.alibaba.sdk.android.oss.common.utils.HttpUtil;
|
||||
import com.alibaba.sdk.android.oss.common.utils.HttpdnsMini;
|
||||
import com.alibaba.sdk.android.oss.common.utils.OSSUtils;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class RequestMessage extends HttpMessage {
|
||||
private URI e;
|
||||
private String f;
|
||||
private String g;
|
||||
private HttpMethod h;
|
||||
private boolean k;
|
||||
private OSSCredentialProvider l;
|
||||
private String p;
|
||||
private String r;
|
||||
private byte[] s;
|
||||
private Uri t;
|
||||
private boolean i = true;
|
||||
private Map<String, String> j = new LinkedHashMap();
|
||||
private boolean m = false;
|
||||
private boolean n = false;
|
||||
private boolean o = false;
|
||||
private boolean q = false;
|
||||
|
||||
public void f(boolean z) {
|
||||
this.n = z;
|
||||
}
|
||||
|
||||
public String g() {
|
||||
return this.f;
|
||||
}
|
||||
|
||||
public OSSCredentialProvider h() {
|
||||
return this.l;
|
||||
}
|
||||
|
||||
public String i() {
|
||||
return this.p;
|
||||
}
|
||||
|
||||
public HttpMethod j() {
|
||||
return this.h;
|
||||
}
|
||||
|
||||
public String k() {
|
||||
return this.g;
|
||||
}
|
||||
|
||||
public Map<String, String> l() {
|
||||
return this.j;
|
||||
}
|
||||
|
||||
public byte[] m() {
|
||||
return this.s;
|
||||
}
|
||||
|
||||
public String n() {
|
||||
return this.r;
|
||||
}
|
||||
|
||||
public Uri o() {
|
||||
return this.t;
|
||||
}
|
||||
|
||||
public boolean p() {
|
||||
return this.i;
|
||||
}
|
||||
|
||||
public boolean q() {
|
||||
return this.k;
|
||||
}
|
||||
|
||||
public boolean r() {
|
||||
return this.m;
|
||||
}
|
||||
|
||||
public void b(String str) {
|
||||
this.p = str;
|
||||
}
|
||||
|
||||
public void c(boolean z) {
|
||||
this.m = z;
|
||||
}
|
||||
|
||||
public void d(String str) {
|
||||
this.r = str;
|
||||
}
|
||||
|
||||
public void e(boolean z) {
|
||||
this.q = z;
|
||||
}
|
||||
|
||||
public String f() throws Exception {
|
||||
boolean z = false;
|
||||
OSSUtils.a(this.e != null, "Endpoint haven't been set!");
|
||||
String scheme = this.e.getScheme();
|
||||
String host = this.e.getHost();
|
||||
String path = this.e.getPath();
|
||||
int port = this.e.getPort();
|
||||
String str = null;
|
||||
String valueOf = port != -1 ? String.valueOf(port) : null;
|
||||
if (TextUtils.isEmpty(host)) {
|
||||
OSSLog.a("endpoint url : " + this.e.toString());
|
||||
}
|
||||
OSSLog.a(" scheme : " + scheme);
|
||||
OSSLog.a(" originHost : " + host);
|
||||
OSSLog.a(" port : " + valueOf);
|
||||
String str2 = scheme + "://" + host;
|
||||
if (!TextUtils.isEmpty(valueOf)) {
|
||||
str2 = str2 + ":" + valueOf;
|
||||
}
|
||||
if (!TextUtils.isEmpty(this.f)) {
|
||||
if (OSSUtils.d(host)) {
|
||||
String str3 = this.f + "." + host;
|
||||
if (r()) {
|
||||
str = HttpdnsMini.a().a(str3);
|
||||
} else {
|
||||
OSSLog.a("[buildCannonicalURL], disable httpdns");
|
||||
}
|
||||
a("Host", str3);
|
||||
str2 = TextUtils.isEmpty(str) ? scheme + "://" + str3 : scheme + "://" + str;
|
||||
} else if (this.q) {
|
||||
if (!this.n) {
|
||||
str2 = scheme + "://" + this.f + "." + host;
|
||||
}
|
||||
z = true;
|
||||
} else if (OSSUtils.e(host)) {
|
||||
if (!OSSUtils.c(this.p)) {
|
||||
a("Host", i());
|
||||
}
|
||||
z = true;
|
||||
}
|
||||
}
|
||||
if (this.o && path != null) {
|
||||
str2 = str2 + path;
|
||||
}
|
||||
if (z) {
|
||||
str2 = str2 + "/" + this.f;
|
||||
}
|
||||
if (!TextUtils.isEmpty(this.g)) {
|
||||
str2 = str2 + "/" + HttpUtil.a(this.g, "utf-8");
|
||||
}
|
||||
String a = OSSUtils.a(this.j, "utf-8");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("request---------------------\n");
|
||||
sb.append("request url=" + str2 + "\n");
|
||||
sb.append("request params=" + a + "\n");
|
||||
for (String str4 : d().keySet()) {
|
||||
sb.append("requestHeader [" + str4 + "]: ");
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
sb2.append(d().get(str4));
|
||||
sb2.append("\n");
|
||||
sb.append(sb2.toString());
|
||||
}
|
||||
OSSLog.a(sb.toString());
|
||||
if (OSSUtils.c(a)) {
|
||||
return str2;
|
||||
}
|
||||
return str2 + "?" + a;
|
||||
}
|
||||
|
||||
public void b(boolean z) {
|
||||
this.o = z;
|
||||
}
|
||||
|
||||
public void c(String str) {
|
||||
this.g = str;
|
||||
}
|
||||
|
||||
public void d(boolean z) {
|
||||
this.i = z;
|
||||
}
|
||||
|
||||
public void a(HttpMethod httpMethod) {
|
||||
this.h = httpMethod;
|
||||
}
|
||||
|
||||
public void a(OSSCredentialProvider oSSCredentialProvider) {
|
||||
this.l = oSSCredentialProvider;
|
||||
}
|
||||
|
||||
public void a(URI uri) {
|
||||
this.e = uri;
|
||||
}
|
||||
|
||||
public void a(String str) {
|
||||
this.f = str;
|
||||
}
|
||||
|
||||
public void a(byte[] bArr) {
|
||||
this.s = bArr;
|
||||
}
|
||||
|
||||
public void a(Uri uri) {
|
||||
this.t = uri;
|
||||
}
|
||||
|
||||
public void a(boolean z) {
|
||||
this.k = z;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import okhttp3.Response;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ResponseMessage extends HttpMessage {
|
||||
private Response e;
|
||||
private RequestMessage f;
|
||||
private int g;
|
||||
|
||||
public RequestMessage f() {
|
||||
return this.f;
|
||||
}
|
||||
|
||||
public Response g() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public int h() {
|
||||
return this.g;
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
this.g = i;
|
||||
}
|
||||
|
||||
public void a(Response response) {
|
||||
this.e = response;
|
||||
}
|
||||
|
||||
public void a(RequestMessage requestMessage) {
|
||||
this.f = requestMessage;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import com.alibaba.sdk.android.oss.model.OSSResult;
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface ResponseParser<T extends OSSResult> {
|
||||
T a(ResponseMessage responseMessage) throws IOException;
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
package com.alibaba.sdk.android.oss.internal;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Xml;
|
||||
import com.alibaba.sdk.android.oss.ClientException;
|
||||
import com.alibaba.sdk.android.oss.ServiceException;
|
||||
import com.alibaba.sdk.android.oss.common.OSSLog;
|
||||
import com.alibaba.sdk.android.oss.model.PutObjectResult;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class ResponseParsers {
|
||||
|
||||
public static final class PutObjectResponseParser extends AbstractResponseParser<PutObjectResult> {
|
||||
@Override // com.alibaba.sdk.android.oss.internal.AbstractResponseParser
|
||||
public /* bridge */ /* synthetic */ PutObjectResult a(ResponseMessage responseMessage, PutObjectResult putObjectResult) throws Exception {
|
||||
PutObjectResult putObjectResult2 = putObjectResult;
|
||||
a2(responseMessage, putObjectResult2);
|
||||
return putObjectResult2;
|
||||
}
|
||||
|
||||
/* renamed from: a, reason: avoid collision after fix types in other method */
|
||||
public PutObjectResult a2(ResponseMessage responseMessage, PutObjectResult putObjectResult) throws IOException {
|
||||
putObjectResult.b(ResponseParsers.a(responseMessage.d().get("ETag")));
|
||||
String string = responseMessage.g().body().string();
|
||||
if (!TextUtils.isEmpty(string)) {
|
||||
putObjectResult.c(string);
|
||||
}
|
||||
return putObjectResult;
|
||||
}
|
||||
}
|
||||
|
||||
public static String a(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
String trim = str.trim();
|
||||
if (trim.startsWith("\"")) {
|
||||
trim = trim.substring(1);
|
||||
}
|
||||
return trim.endsWith("\"") ? trim.substring(0, trim.length() - 1) : trim;
|
||||
}
|
||||
|
||||
public static ServiceException a(ResponseMessage responseMessage, boolean z) throws ClientException {
|
||||
String str;
|
||||
String str2;
|
||||
String str3;
|
||||
String str4;
|
||||
String str5;
|
||||
String str6;
|
||||
int h = responseMessage.h();
|
||||
String header = responseMessage.g().header("x-oss-request-id");
|
||||
String str7 = null;
|
||||
if (z) {
|
||||
str4 = header;
|
||||
str6 = null;
|
||||
str3 = null;
|
||||
str = null;
|
||||
str5 = null;
|
||||
str2 = null;
|
||||
} else {
|
||||
try {
|
||||
String string = responseMessage.g().body().string();
|
||||
OSSLog.a("errorMessage : \n " + string);
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(string.getBytes());
|
||||
XmlPullParser newPullParser = Xml.newPullParser();
|
||||
newPullParser.setInput(byteArrayInputStream, "utf-8");
|
||||
int eventType = newPullParser.getEventType();
|
||||
String str8 = null;
|
||||
str = null;
|
||||
String str9 = null;
|
||||
str2 = null;
|
||||
while (eventType != 1) {
|
||||
if (eventType == 2) {
|
||||
if ("Code".equals(newPullParser.getName())) {
|
||||
str7 = newPullParser.nextText();
|
||||
} else if ("Message".equals(newPullParser.getName())) {
|
||||
str8 = newPullParser.nextText();
|
||||
} else if ("RequestId".equals(newPullParser.getName())) {
|
||||
header = newPullParser.nextText();
|
||||
} else if ("HostId".equals(newPullParser.getName())) {
|
||||
str = newPullParser.nextText();
|
||||
} else if ("PartNumber".equals(newPullParser.getName())) {
|
||||
str9 = newPullParser.nextText();
|
||||
} else if ("PartEtag".equals(newPullParser.getName())) {
|
||||
str2 = newPullParser.nextText();
|
||||
}
|
||||
}
|
||||
eventType = newPullParser.next();
|
||||
if (eventType == 4) {
|
||||
eventType = newPullParser.next();
|
||||
}
|
||||
}
|
||||
str3 = str7;
|
||||
str7 = str8;
|
||||
str4 = header;
|
||||
String str10 = str9;
|
||||
str5 = string;
|
||||
str6 = str10;
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e);
|
||||
} catch (XmlPullParserException e2) {
|
||||
throw new ClientException(e2);
|
||||
}
|
||||
}
|
||||
ServiceException serviceException = new ServiceException(h, str7, str3, str4, str, str5);
|
||||
if (!TextUtils.isEmpty(str2)) {
|
||||
serviceException.setPartEtag(str2);
|
||||
}
|
||||
if (!TextUtils.isEmpty(str6)) {
|
||||
serviceException.setPartNumber(str6);
|
||||
}
|
||||
return serviceException;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user