Skip to content

Commit

Permalink
improve coding styles
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jul 9, 2024
1 parent 64983d9 commit 3699f65
Show file tree
Hide file tree
Showing 33 changed files with 50 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class AcsRequest<T extends AcsResponse> extends HttpRequest {
private UserAgentConfig userAgentConfig;
protected ISignatureComposer composer = null;
private String version = null;
private String product = null;
private String product;
private String actionName = null;
private String regionId = null;
private String securityToken = null;
Expand Down Expand Up @@ -76,7 +76,7 @@ public static String concatQueryString(Map<String, String> parameters) throws Un
return null;
}

StringBuilder urlBuilder = new StringBuilder("");
StringBuilder urlBuilder = new StringBuilder();
for (Entry<String, String> entry : parameters.entrySet()) {
String key = entry.getKey();
String val = entry.getValue();
Expand Down
24 changes: 0 additions & 24 deletions aliyun-java-sdk-core/src/main/java/com/aliyuncs/CommonRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,30 +509,6 @@ public Map<String, String> getSysPathParameters() {
return pathParameters;
}

public void setSysAccept(FormatType type) {
this.accept = type;
}

public FormatType getSysAccept() {
return this.accept;
}

public SignatureVersion getSysSignatureVersion() {
return signatureVersion;
}

public void setSysSignatureVersion(SignatureVersion signatureVersion) {
this.signatureVersion = signatureVersion;
}

public SignatureAlgorithm getSysSignatureAlgorithm() {
return signatureAlgorithm;
}

public void setSysSignatureAlgorithm(SignatureAlgorithm signatureAlgorithm) {
this.signatureAlgorithm = signatureAlgorithm;
}

public RetryPolicy getSysRetryPolicy() {
return this.retryPolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected void putPathParameter(String name, String value) {
@Override
public String composeUrl(String endpoint, Map<String, String> queries) throws UnsupportedEncodingException {
Map<String, String> mapQueries = (queries == null) ? this.getSysQueryParameters() : queries;
StringBuilder urlBuilder = new StringBuilder("");
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append(this.getSysProtocol().toString());
urlBuilder.append("://").append(endpoint);
if (null != this.uriPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void setSysSecurityToken(String securityToken) {
@Override
public String composeUrl(String endpoint, Map<String, String> queries) throws UnsupportedEncodingException {
Map<String, String> mapQueries = (queries == null) ? this.getSysQueryParameters() : queries;
StringBuilder urlBuilder = new StringBuilder("");
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.append(this.getSysProtocol().toString());
urlBuilder.append("://").append(endpoint);
if (-1 == urlBuilder.indexOf("?")) {
Expand Down Expand Up @@ -166,7 +166,7 @@ public HttpRequest signRequest(Signer signer, AlibabaCloudCredentials credential
format);
headerMap.putAll(this.getSysHeaders());
headerMap = this.composer.refreshSignParameters(headerMap, signer, null, null);
if (imutableMap.get("RegionId") == null && this.getSysRegionId() != null && !this.getSysRegionId().equals("")) {
if (imutableMap.get("RegionId") == null && this.getSysRegionId() != null && !this.getSysRegionId().isEmpty()) {
if ((bodyParams == null || bodyParams.get("RegionId") == null)) {
imutableMap.put("RegionId", getSysRegionId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DefaultCredentialsProvider() throws ClientException {
defaultProviders.add(new ProfileCredentialsProvider());
String roleName = AuthUtils.getEnvironmentECSMetaData();
if (roleName != null) {
if (roleName.length() == 0) {
if (roleName.isEmpty()) {
throw new ClientException("Environment variable roleName('ALIBABA_CLOUD_ECS_METADATA') cannot be empty");
}
defaultProviders.add(new InstanceProfileCredentialsProvider(roleName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class LegacyCredentials implements AlibabaCloudCredentials {

private final Credential legacyCredential;

public LegacyCredentials(Credential legacyCrendential) {
this.legacyCredential = legacyCrendential;
public LegacyCredentials(Credential legacyCredential) {
this.legacyCredential = legacyCredential;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AlibabaCloudCredentials getCredentials() throws ClientException {
if (filePath == null) {
filePath = AuthConstant.DEFAULT_CREDENTIALS_FILE_PATH;
}
if (filePath.length() == 0) {
if (filePath.isEmpty()) {
throw new ClientException("The specified credentials file is empty");
}
Wini ini;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public String signString(String stringToSign, String accessKeySecret) {
rsaSign.initSign(privateKey);
rsaSign.update(stringToSign.getBytes(ENCODING));
byte[] sign = rsaSign.sign();
String signature = DatatypeConverter.printBase64Binary(sign);
return signature;
return DatatypeConverter.printBase64Binary(sign);
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e.toString());
} catch (InvalidKeySpecException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private BasicSessionCredentials getNewSessionCredentials() throws ClientExceptio

return new BasicSessionCredentials(
response.getSessionAccessKey().getSessionAccessKeyId(),
response.getSessionAccessKey().getSessionAccessKeySecert(),
response.getSessionAccessKey().getSessionAccessKeySecret(),
null,
sessionDurationSeconds
);
Expand Down
10 changes: 0 additions & 10 deletions aliyun-java-sdk-core/src/main/java/com/aliyuncs/auth/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ public abstract class Signer {
private final static Signer HMAC_SM3 = new HmacSM3Signer();
private final static Signer HMAC_SHA256 = new HmacSHA256Signer();

public static Signer getSigner(AlibabaCloudCredentials credentials) {
if (credentials instanceof KeyPairCredentials) {
return SHA256_WITH_RSA_SIGNER;
} else if (credentials instanceof BearerTokenCredentials) {
return BEARER_TOKEN_SIGNER;
} else {
return HMACSHA1_SIGNER;
}
}

public static Signer getSigner(AlibabaCloudCredentials credentials, SignatureVersion signatureVersion, SignatureAlgorithm signatureAlgorithm) {
switch (signatureVersion) {
case V3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private Map<String, String> getCanonicalizedHeadersMap(Map<String, String> heade
}

private String getCanonicalizedResource(Map<String, String> query) {
if (query == null || query.size() == 0) {
if (query == null || query.isEmpty()) {
return "";
}
String[] keys = query.keySet().toArray(new String[query.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@

package com.aliyuncs.auth.sts;

/**
* Created by haowei.yao on 2017/9/14.
*/

import com.aliyuncs.RpcAcsRequest;
import com.aliyuncs.http.ProtocolType;

/**
* @author auto create
*/
public class AssumeRoleRequest extends RpcAcsRequest<AssumeRoleResponse> {

private Long durationSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public void setSessionAccessKeyId(String sessionAccessKeyId) {
this.sessionAccessKeyId = sessionAccessKeyId;
}

public String getSessionAccessKeySecert() {
public String getSessionAccessKeySecret() {
return sessionAccessKeySecret;
}

@XmlElement(name = "SessionAccessKeySecret")
public void setSessionAccessKeySecert(String sessionAccessKeySecert) {
this.sessionAccessKeySecret = sessionAccessKeySecert;
public void setSessionAccessKeySecret(String sessionAccessKeySecret) {
this.sessionAccessKeySecret = sessionAccessKeySecret;
}

public String getExpiration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static GenerateSessionAccessKeyResponse unmarshall(GenerateSessionAccessK

SessionAccessKey credentials = new SessionAccessKey();
credentials.setSessionAccessKeyId(context.stringValue("GenerateSessionAccessKeyResponse.SessionAccessKey.SessionAccessKeyId"));
credentials.setSessionAccessKeySecert(context.stringValue("GenerateSessionAccessKeyResponse.SessionAccessKey.SessionAccessKeySecret"));
credentials.setSessionAccessKeySecret(context.stringValue("GenerateSessionAccessKeyResponse.SessionAccessKey.SessionAccessKeySecret"));
credentials.setExpiration(context.stringValue("GenerateSessionAccessKeyResponse.SessionAccessKey.Expiration"));

getSessionAccessKeyResponse.setSessionAccessKey(credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ private String getEndpoint(String productCode, String regionId) {
}
}

String endpoint = "";
String endpoint;
if ("regional".equals(this.productEndpointRegional)) {
endpoint = "<product_id><suffix><network>.<region_id>.aliyuncs.com";
endpoint = endpoint.replace("<region_id>", regionId.toLowerCase());
} else {
endpoint = "<product_id><suffix><network>.aliyuncs.com";
}
if (this.productSuffix == null || "".equals(this.productSuffix)) {
if (StringUtils.isEmpty(this.productSuffix)) {
endpoint = endpoint.replace("<suffix>", "");
} else {
endpoint = endpoint.replace("<suffix>", "-" + this.productSuffix.toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.utils.StringUtils;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -38,7 +39,7 @@ public static void setLocationServiceEndpoint(String endpoint) {

@Override
public String resolve(ResolveEndpointRequest request) throws ClientException {
if (request.locationServiceCode == null || request.locationServiceCode.length() == 0) {
if (StringUtils.isEmpty(request.locationServiceCode)) {
return null;
}

Expand Down Expand Up @@ -106,7 +107,6 @@ private void callLocationService(String key, ResolveEndpointRequest request) thr
validProductCodes.add(request.productCodeLower);
validRegionIds.add(request.regionId);


boolean foundFlag = false;
for (DescribeEndpointsResponse.Endpoint endpoint : response.getEndpoints()) {
if (endpoint.getSerivceCode().equals(request.locationServiceCode)
Expand Down Expand Up @@ -143,10 +143,6 @@ public String makeEndpointKey(ResolveEndpointRequest request) {
);
}

public String makeRegionIdKey(ResolveEndpointRequest request) {
return request.locationServiceCode + "." + request.regionId + "." + request.endpointType;
}

public String makeEndpointKey(String productCode, String locationServiceCode, String regionId,
String endpointType) {
return productCode.toLowerCase() + "." + locationServiceCode + "."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.aliyuncs.endpoint;

import com.aliyuncs.utils.StringUtils;

import java.util.HashMap;

public class ResolveEndpointRequest {

public static final String ENDPOINT_TYPE_INNER = "innerAPI";
public static final String ENDPOINT_TYPE_OPEN = "openAPI";

public String productCode = null;
public String regionId = null;
public String endpointType = null;
public String locationServiceCode = null;
public String productCodeLower = null;
public String productCode;
public String regionId;
public String endpointType;
public String locationServiceCode;
public String productCodeLower;
public HashMap<String, String> productEndpointMap = null;
public String productEndpointRegional = null;
public String productNetwork = "public";
Expand All @@ -24,7 +26,7 @@ public ResolveEndpointRequest(String regionId, String productCode,
this.productCode = productCode;
this.productCodeLower = productCode.toLowerCase();

if (endpointType == null || endpointType.length() == 0) {
if (StringUtils.isEmpty(endpointType)) {
endpointType = ENDPOINT_TYPE_OPEN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

/**
* 用于异步调用时的回调逻辑
*
* @author VK.Gao
* @date 2017/03/02
*/
public interface CallBack {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CompositeX509TrustManager(List<X509TrustManager> trustManagers) {
}

@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkClientTrusted(X509Certificate[] chain, String authType) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IHttpClient buildClient(IClientProfile profile) {
profile.setHttpClientConfig(clientConfig);
}

String customClientClassName = null;
String customClientClassName;
if (clientConfig.isCompatibleMode()) {
customClientClassName = COMPATIBLE_HTTP_CLIENT_CLASS_NAME;
} else if (clientConfig.getClientType() == HttpClientType.Custom && !StringUtils.isEmpty(clientConfig.getCustomClientClassName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static String debugHttpRequest(HttpRequest request) {
StringBuilder debugString = new StringBuilder();

String sysUrl = request.getSysUrl();
URL url = null;
URL url;
try {
url = new URL(sysUrl);
debugString.append("> " + request.getSysMethod() + " " + url.getProtocol().toUpperCase() + "/1.1\n> ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public IHttpClient(HttpClientConfig clientConfig) throws ClientException {
}
this.clientConfig = clientConfig;
init(clientConfig);

}

public IHttpClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ private SSLConnectionSocketFactory createSSLConnectionSocketFactory() throws Cli
} else {
hostnameVerifier = new DefaultHostnameVerifier();
}
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
return sslConnectionSocketFactory;
return new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
} else {
HostnameVerifier hostnameVerifier;
if (null == clientConfig.getHostnameVerifier()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ protected void init(HttpClientConfig clientConfig) {
@Override
public HttpResponse syncInvoke(HttpRequest request) throws IOException, ClientException {
InputStream content = null;
HttpResponse response = null;
HttpResponse response;
HttpURLConnection httpConn = buildHttpConnection(request);
OutputStream out = null;
OutputStream out;

try {
httpConn.connect();
Expand Down Expand Up @@ -85,8 +85,7 @@ public Future<HttpResponse> asyncInvoke(HttpRequest apiRequest, CallBack callbac
}

private boolean calcIgnoreSSLCert(HttpRequest request) {
boolean ignoreSSLCert = request.isIgnoreSSLCerts() ? request.isIgnoreSSLCerts() : clientConfig.isIgnoreSSLCerts();
return ignoreSSLCert;
return request.isIgnoreSSLCerts() ? request.isIgnoreSSLCerts() : clientConfig.isIgnoreSSLCerts();
}

private CompositeX509TrustManager calcX509TrustManager(HttpRequest request) throws KeyStoreException, NoSuchAlgorithmException {
Expand Down Expand Up @@ -246,7 +245,7 @@ private void setConnectionRequestProperty(HttpURLConnection httpConn, HttpReques
private HttpURLConnection buildHttpConnection(HttpRequest request) throws IOException, ClientException {
checkHttpRequest(request);
String strUrl = request.getSysUrl();
URL url = null;
URL url;
String[] urlArray = null;
if (MethodType.POST.equals(request.getSysMethod()) && null == request.getHttpContent()) {
urlArray = strUrl.split("\\?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.aliyuncs.auth.*;
import com.aliyuncs.endpoint.DefaultEndpointResolver;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpClientConfig;
import com.aliyuncs.utils.ParameterHelper;
Expand Down Expand Up @@ -55,8 +54,7 @@ public synchronized static DefaultProfile getProfile(String regionId, ICredentia
}

public synchronized static DefaultProfile getProfile(String regionId, String accessKeyId, String secret) {
Credential creden = new Credential(accessKeyId, secret);
profile = new DefaultProfile(regionId, creden);
profile = new DefaultProfile(regionId, new Credential(accessKeyId, secret));
return profile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.aliyuncs.http.HttpClientConfig;
import org.slf4j.Logger;

@SuppressWarnings("deprecation")
public interface IClientProfile {

/**
Expand Down
Loading

0 comments on commit 3699f65

Please sign in to comment.