diff --git a/sdk/management/README.md b/sdk/management/README.md
index 647a346676d1..e9c69857cac1 100644
--- a/sdk/management/README.md
+++ b/sdk/management/README.md
@@ -46,7 +46,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
com.azure
azure-identity
- 1.1.0-beta.5
+ 1.0.8
```
[//]: # ({x-version-update-end})
@@ -58,7 +58,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
com.azure
azure-core-http-netty
- 1.5.2
+ 1.5.3
```
[//]: # ({x-version-update-end})
diff --git a/sdk/management/pom.xml b/sdk/management/pom.xml
index a290e23ca8e7..3e1c72a73bdb 100644
--- a/sdk/management/pom.xml
+++ b/sdk/management/pom.xml
@@ -55,11 +55,6 @@
-
- com.azure
- azure-core
- 1.5.0
-
com.azure
azure-core-management
@@ -113,13 +108,13 @@
com.azure
azure-core-http-netty
- 1.4.0
+ 1.5.3
test
com.azure
azure-identity
- 1.1.0-beta.3
+ 1.0.8
test
diff --git a/sdk/resources/mgmt/pom.xml b/sdk/resources/mgmt/pom.xml
index 0894610293ef..030fcf07163a 100644
--- a/sdk/resources/mgmt/pom.xml
+++ b/sdk/resources/mgmt/pom.xml
@@ -47,10 +47,6 @@
-
- com.azure
- azure-core
-
com.azure
azure-core-management
@@ -92,6 +88,13 @@
+
+
+ src/main/resources
+ true
+
+
+
org.apache.maven.plugins
diff --git a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java
index 35c6193d74c4..27cc88d828cc 100644
--- a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java
+++ b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/AzureServiceClient.java
@@ -46,27 +46,22 @@ public abstract class AzureServiceClient {
private final ClientLogger logger = new ClientLogger(getClass());
- protected AzureServiceClient(HttpPipeline httpPipeline, AzureEnvironment environment) {
- ((AzureJacksonAdapter) serializerAdapter).serializer().registerModule(DateTimeDeserializer.getModule());
- }
-
- private static final String OS;
- private static final String OS_NAME;
- private static final String OS_VERSION;
- private static final String JAVA_VERSION;
- private static final String SDK_VERSION = "2.0.0-SNAPSHOT";
+ private static final Map PROPERTIES =
+ CoreUtils.getProperties("azure.properties");
+ private static final String SDK_VERSION;
static {
- OS_NAME = System.getProperty("os.name");
- OS_VERSION = System.getProperty("os.version");
- OS = OS_NAME + "/" + OS_VERSION;
- String version = System.getProperty("java.version");
- JAVA_VERSION = version != null ? version : "Unknown";
+ SDK_VERSION = PROPERTIES.getOrDefault("version", "UnknownVersion");
}
private final SerializerAdapter serializerAdapter = new AzureJacksonAdapter();
- private String sdkName;
+ private final String sdkName;
+
+ protected AzureServiceClient(HttpPipeline httpPipeline, AzureEnvironment environment) {
+ sdkName = this.getClass().getPackage().getName();
+ ((AzureJacksonAdapter) serializerAdapter).serializer().registerModule(DateTimeDeserializer.getModule());
+ }
/**
* Gets serializer adapter for JSON serialization/de-serialization.
@@ -83,24 +78,8 @@ public SerializerAdapter getSerializerAdapter() {
* @return the default client context.
*/
public Context getContext() {
- Context context = new Context("java.version", JAVA_VERSION);
- if (!CoreUtils.isNullOrEmpty(OS_NAME)) {
- context = context.addData("os.name", OS_NAME);
- }
- if (!CoreUtils.isNullOrEmpty(OS_VERSION)) {
- context = context.addData("os.version", OS_VERSION);
- }
- if (sdkName == null) {
- String packageName = this.getClass().getPackage().getName();
- if (packageName.endsWith(".models")) {
- sdkName = packageName.substring(0, packageName.length() - ".models".length());
- } else {
- sdkName = packageName;
- }
- }
- context = context.addData("Sdk-Name", sdkName);
- context = context.addData("Sdk-Version", SDK_VERSION);
- return context;
+ return new Context("Sdk-Name", sdkName)
+ .addData("Sdk-Version", SDK_VERSION);
}
/**
diff --git a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/UserAgentPolicy.java b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/UserAgentPolicy.java
index fb907e2bebf9..8bd010728836 100644
--- a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/UserAgentPolicy.java
+++ b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/UserAgentPolicy.java
@@ -21,36 +21,12 @@ public class UserAgentPolicy implements HttpPipelinePolicy {
private static final String SDK_VERSION_KEY = "Sdk-Version";
private static final String APPLICATION_ID_KEY = "Application-Id";
- private static final String OS_NAME = System.getProperty("os.name");
- private static final String OS_VERSION = System.getProperty("os.version");
- private static final String JAVA_VERSION = System.getProperty("java.version");
-
- /*
- * The base User-Agent header format is azsdk-java-/. Additional information such as the
- * application ID will be prepended and platform telemetry will be appended, a fully configured User-Agent header
- * format is azsdk-java-/ .
- */
- private static final String DEFAULT_USER_AGENT_FORMAT = "azsdk-java-%s/%s";
-
- // From the design guidelines, the platform info format is:
- // ;
- private static final String PLATFORM_INFO_FORMAT = "%s; %s %s";
-
private final String defaultSdkName = this.getClass().getPackage().getName();
private final String defaultSdkVersion = this.getClass().getPackage().getSpecificationVersion();
private final HttpLogOptions httpLogOptions;
private final Configuration configuration;
- private static final UserAgentPolicy DEFAULT_USER_AGENT_POLICY = new UserAgentPolicy(null, null);
-
- /**
- * @return default user agent policy
- */
- public static UserAgentPolicy getDefaultUserAgentPolicy() {
- return DEFAULT_USER_AGENT_POLICY;
- }
-
/**
* @param httpLogOptions used for get application id
* @param configuration used for check telemetry enable or not
@@ -69,32 +45,54 @@ public UserAgentPolicy(HttpLogOptions httpLogOptions, Configuration configuratio
}
}
- protected String buildUserAgent(String applicationId, String sdkName, String sdkVersion) {
+ // begin of UserAgentUtil.toUserAgentString
+ public static final String DEFAULT_USER_AGENT_HEADER = "azsdk-java";
+ private static final String PLATFORM_INFO_FORMAT = "%s; %s; %s";
+ private static final int MAX_APP_ID_LENGTH = 24;
+
+ private static String toUserAgentString(String applicationId, String sdkName, String sdkVersion,
+ Configuration configuration) {
StringBuilder userAgentBuilder = new StringBuilder();
// Only add the application ID if it is present as it is optional.
if (applicationId != null) {
+ applicationId = applicationId.length() > MAX_APP_ID_LENGTH ? applicationId.substring(0, MAX_APP_ID_LENGTH)
+ : applicationId;
userAgentBuilder.append(applicationId).append(" ");
}
// Add the required default User-Agent string.
- userAgentBuilder.append(String.format(DEFAULT_USER_AGENT_FORMAT, sdkName, sdkVersion));
+ userAgentBuilder.append(DEFAULT_USER_AGENT_HEADER)
+ .append("-")
+ .append(sdkName)
+ .append("/")
+ .append(sdkVersion);
// Only add the platform telemetry if it is allowed as it is optional.
- if (!telemetryDisabled()) {
- String platformInfo = String.format(PLATFORM_INFO_FORMAT, JAVA_VERSION, OS_NAME, OS_VERSION);
+ if (!isTelemetryDisabled(configuration)) {
userAgentBuilder.append(" ")
- .append("(")
- .append(platformInfo)
- .append(")");
+ .append("(")
+ .append(getPlatformInfo())
+ .append(")");
}
return userAgentBuilder.toString();
}
- private boolean telemetryDisabled() {
- return configuration.get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false);
+ private static String getPlatformInfo() {
+ String javaVersion = Configuration.getGlobalConfiguration().get("java.version");
+ String osName = Configuration.getGlobalConfiguration().get("os.name");
+ String osVersion = Configuration.getGlobalConfiguration().get("os.version");
+
+ return String.format(PLATFORM_INFO_FORMAT, javaVersion, osName, osVersion);
+ }
+
+ private static boolean isTelemetryDisabled(Configuration configuration) {
+ return (configuration == null)
+ ? Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false)
+ : configuration.get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false);
}
+ // end of UserAgentUtil.toUserAgentString
@Override
public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
@@ -124,7 +122,9 @@ public Mono process(HttpPipelineCallContext context, HttpPipelineN
applicationId = httpLogOptions.getApplicationId();
}
- context.getHttpRequest().setHeader(USER_AGENT_KEY, buildUserAgent(applicationId, sdkName, sdkVersion));
+ context.getHttpRequest().setHeader(USER_AGENT_KEY,
+ //UserAgentUtil.toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
+ toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
return next.process();
}
}
diff --git a/sdk/resources/mgmt/src/main/resources/azure.properties b/sdk/resources/mgmt/src/main/resources/azure.properties
new file mode 100644
index 000000000000..defbd48204e4
--- /dev/null
+++ b/sdk/resources/mgmt/src/main/resources/azure.properties
@@ -0,0 +1 @@
+version=${project.version}