com.aliyuncs.v5.http.UserAgentConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Show all versions of aliyun-java-sdk-core-v5 Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyuncs.v5.http;
import com.aliyuncs.v5.CoreMessage;
import com.aliyuncs.v5.utils.StringUtils;
import java.util.*;
public class UserAgentConfig {
static {
Properties sysProps = System.getProperties();
DEFAULT_MESSAGE = String.format("AlibabaCloud (%s; %s) Java/%s %s/%s", sysProps.getProperty("os.name"), sysProps
.getProperty("os.arch"), sysProps.getProperty("java.runtime.version"), "Core", CoreMessage.coreVersion);
}
private static String DEFAULT_MESSAGE;
private List excludeList = new ArrayList();
private final Map userAgents = new LinkedHashMap();
public UserAgentConfig() {
excludeList.add("java");
excludeList.add("Core");
}
public static String getDefaultMessage() {
return DEFAULT_MESSAGE;
}
public void append(String key, String value) {
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
return;
}
if (excludeList.contains(key.toLowerCase())) {
return;
}
this.userAgents.put(key, value);
}
public Map getSysUserAgentsMap() {
return Collections.unmodifiableMap(this.userAgents);
}
public static String resolve(UserAgentConfig requestConfig, UserAgentConfig clientConfig) {
Map finalMap = new LinkedHashMap();
if (clientConfig != null && clientConfig.getSysUserAgentsMap().size() > 0) {
finalMap.putAll(clientConfig.getSysUserAgentsMap());
}
if (requestConfig != null && requestConfig.getSysUserAgentsMap().size() > 0) {
finalMap.putAll(requestConfig.getSysUserAgentsMap());
}
StringBuilder agents = new StringBuilder(DEFAULT_MESSAGE);
for (Map.Entry entry : finalMap.entrySet()) {
agents.append(" ");
agents.append(entry.getKey());
agents.append("/");
agents.append(entry.getValue());
}
return agents.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy