Skip to content

Commit 312dd27

Browse files
committed
refactor(SdkCommon): Keep static userAgent value
1 parent 25defa2 commit 312dd27

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

common/src/main/java/com/ibm/watson/common/SdkCommon.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
public class SdkCommon {
1414
private static final Logger LOG = Logger.getLogger(SdkCommon.class.getName());
15+
private static String userAgent;
1516

1617
private static String loadSdkVersion() {
1718
ClassLoader classLoader = SdkCommon.class.getClassLoader();
@@ -28,7 +29,10 @@ private static String loadSdkVersion() {
2829
}
2930

3031
private static String getUserAgent() {
31-
return "watson-apis-java-sdk/" + loadSdkVersion() + "; " + RequestUtils.getUserAgent();
32+
if (userAgent == null) {
33+
userAgent = "watson-apis-java-sdk/" + loadSdkVersion() + "; " + RequestUtils.getUserAgent();
34+
}
35+
return userAgent;
3236
}
3337

3438
public static Map<String, String> getDefaultHeaders(String serviceName, String serviceVersion, String operationId) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.ibm.watson.common;
2+
3+
public interface HttpHeaders {
4+
/** Header containing analytics info. */
5+
String X_IBMCLOUD_SDK_ANALYTICS = "X-IBMCloud-SDK-Analytics";
6+
}

0 commit comments

Comments
 (0)