GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(common): Retrieve User-Agent from core and append to current pac… · watson-developer-cloud/java-sdk@758f3f2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common/src/main
    • java/com/ibm/watson/common
      • SdkCommon.java
    • resources
      • java-sdk-version.properties
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboard
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.ibm.watson.common;
2+
3+
import com.ibm.cloud.sdk.core.http.HttpHeaders;
4+
import com.ibm.cloud.sdk.core.util.RequestUtils;
5+
6+
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.Properties;
10+
import java.util.logging.Level;
11+
import java.util.logging.Logger;
12+
13+
public class SdkCommon {
14+
private static final Logger LOG = Logger.getLogger(SdkCommon.class.getName());
15+
16+
private static String loadSdkVersion() {
17+
ClassLoader classLoader = SdkCommon.class.getClassLoader();
18+
InputStream inputStream = classLoader.getResourceAsStream("java-sdk-version.properties");
19+
Properties properties = new Properties();
20+
21+
try {
22+
properties.load(inputStream);
23+
} catch (Exception e) {
24+
LOG.log(Level.WARNING, "Could not load java-sdk-version.properties", e);
25+
}
26+
27+
return properties.getProperty("version", "unknown-version");
28+
}
29+
30+
private static String getUserAgent() {
31+
return "watson-apis-java-sdk/" + loadSdkVersion() + "; " + RequestUtils.getUserAgent();
32+
}
33+
34+
public static Map<String, String> getDefaultHeaders(String serviceName, String serviceVersion, String operationId) {
35+
Map<String, String> headers = new HashMap<>();
36+
37+
String sdkAnalyticsHeaderValue = String.format(
38+
"service_name=%s;service_version=%s;operation_id=%s",
39+
serviceName,
40+
serviceVersion,
41+
operationId
42+
);
43+
44+
headers.put(HttpHeaders.X_IBMCLOUD_SDK_ANALYTICS, sdkAnalyticsHeaderValue);
45+
headers.put(HttpHeaders.USER_AGENT, getUserAgent());
46+
return headers;
47+
}
48+
}
Collapse file

‎common/src/main/resources/java-sdk-version.properties‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version[email protected]@

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.