正在查看: CallApp v2.226 应用的 AWSUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: CallApp v2.226 应用的 AWSUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.callapp.contacts.util.aws;
import a1.d0;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.BasicSessionCredentials;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.StorageClass;
import com.callapp.common.model.json.JSONAWSSessionCredentials;
import com.callapp.contacts.R;
import com.callapp.contacts.manager.analytics.AnalyticsManager;
import com.callapp.contacts.manager.cache.CacheManager;
import com.callapp.contacts.model.Constants;
import com.callapp.contacts.util.CLog;
import com.callapp.contacts.util.http.HttpRequestParams;
import com.callapp.contacts.util.http.HttpUtils;
import com.callapp.contacts.util.serializer.string.ClassParserHttpResponseHandler;
import com.callapp.framework.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class AWSUtils {
public static String a(String str) {
if (str == null) {
str = "jpg";
}
return d0.p(StringUtils.s(7, false, true), "_", String.valueOf(System.currentTimeMillis()), ".", str);
}
public static String b(File file, String str, String str2) {
if (file != null) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
long length = file.length();
JSONAWSSessionCredentials s3PutSessionCredentials = getS3PutSessionCredentials();
if (s3PutSessionCredentials != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
if (StringUtils.x("image/jpg")) {
objectMetadata.setContentType("image/jpg");
}
objectMetadata.setContentLength(length);
PutObjectRequest putObjectRequest = new PutObjectRequest(str2, str, fileInputStream, objectMetadata);
putObjectRequest.setStorageClass(StorageClass.IntelligentTiering);
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
try {
if (new AmazonS3Client(new BasicSessionCredentials(s3PutSessionCredentials.getAccessKey(), s3PutSessionCredentials.getSecretKey(), s3PutSessionCredentials.getSessionToken()), RegionUtils.a(Regions.US_EAST_1.getName())).c(putObjectRequest).getETag() == null) {
AnalyticsManager.get().o(Constants.AWS_S3, "Upload to S3 failed - no ETag");
return null;
}
StringBuilder sb2 = new StringBuilder();
sb2.append("https://s3.amazonaws.com/" + str2 + '/');
sb2.append(str);
return sb2.toString();
} catch (AmazonClientException e) {
AnalyticsManager.get().o(Constants.AWS_S3, "Upload to S3 failed - put exception");
CLog.b(AWSUtils.class, e);
}
}
} catch (FileNotFoundException e2) {
CLog.b(AWSUtils.class, e2);
}
}
return null;
}
private static synchronized JSONAWSSessionCredentials getS3PutSessionCredentials() {
JSONAWSSessionCredentials jSONAWSSessionCredentials;
synchronized (AWSUtils.class) {
try {
jSONAWSSessionCredentials = (JSONAWSSessionCredentials) CacheManager.get().c("awss3putsessioncredentials", JSONAWSSessionCredentials.class, false, false);
if (jSONAWSSessionCredentials == null) {
ClassParserHttpResponseHandler classParserHttpResponseHandler = new ClassParserHttpResponseHandler(JSONAWSSessionCredentials.class);
HttpUtils.getCallAppServerHost();
if (HttpUtils.b()) {
HttpRequestParams.HttpRequestParamsBuilder httpRequestParamsBuilder = new HttpRequestParams.HttpRequestParamsBuilder(HttpUtils.getAWSCredentialsUrl());
httpRequestParamsBuilder.d = classParserHttpResponseHandler;
HttpUtils.g(httpRequestParamsBuilder.a());
}
jSONAWSSessionCredentials = (JSONAWSSessionCredentials) classParserHttpResponseHandler.getResult();
if (jSONAWSSessionCredentials != null) {
CacheManager.get().h(JSONAWSSessionCredentials.class, "awss3putsessioncredentials", jSONAWSSessionCredentials, R.integer.aws_session_credentials_cache_ttl_minutes);
} else {
AnalyticsManager.get().o(Constants.AWS_S3, "Upload to S3 failed - can't get credentials from server");
}
}
} catch (Throwable th) {
throw th;
}
}
return jSONAWSSessionCredentials;
}
}