Skip to content

Commit 8d8933d

Browse files
author
jianggang
committed
fix: fix sdk version report
1 parent 845b624 commit 8d8933d

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.featureprobe</groupId>
88
<artifactId>server-sdk-java</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1</version>
1010
<name>server-sdk-java</name>
1111
<url>https://github.com/FeatureProbe/server-sdk-java</url>
1212
<description>FeatureProbe Server Side SDK for Java</description>

src/main/java/com/featureprobe/sdk/server/FPConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public final class FPConfig {
88

9-
static final URI DEFAULT_REMOTE_URI = URI.create("http://127.0.0.1:4007");
9+
static final URI DEFAULT_REMOTE_URI = URI.create("http://localhost:4009/server");
1010

1111
static final Duration DEFAULT_INTERVAL = Duration.ofSeconds(5);
1212

src/main/java/com/featureprobe/sdk/server/FPContext.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import okhttp3.Headers;
44
import org.slf4j.Logger;
55

6-
import java.io.IOException;
6+
import java.io.InputStream;
77
import java.net.MalformedURLException;
88
import java.net.URL;
99
import java.time.Duration;
1010
import java.util.Objects;
11+
import java.util.Properties;
1112

1213
final class FPContext {
1314

@@ -58,12 +59,7 @@ final class FPContext {
5859
this.refreshInterval = config.refreshInterval;
5960
this.location = config.location;
6061
this.httpConfiguration = config.httpConfiguration;
61-
String sdkVersion = DEFAULT_SDK_VERSION;
62-
try {
63-
sdkVersion = Utils.readSdkVersion();
64-
} catch (IOException e) {
65-
logger.error("read sdk version error", e);
66-
}
62+
String sdkVersion = getVersion();
6763
this.headers = config.httpConfiguration.headers.newBuilder()
6864
.add(GET_SDK_KEY_HEADER, serverSdkKey)
6965
.add(USER_AGENT_HEADER, SDK_FLAG_PREFIX + sdkVersion)
@@ -97,4 +93,33 @@ public HttpConfiguration getHttpConfiguration() {
9793
public Headers getHeaders() {
9894
return headers;
9995
}
96+
97+
private synchronized String getVersion() {
98+
String version = null;
99+
try {
100+
Properties p = new Properties();
101+
InputStream is = getClass()
102+
.getResourceAsStream("/META-INF/maven/com.featureprobe/server-sdk-java/pom.properties");
103+
if (is != null) {
104+
p.load(is);
105+
version = p.getProperty("version", "");
106+
}
107+
} catch (Exception e) {
108+
109+
}
110+
if (version == null) {
111+
Package aPackage = getClass().getPackage();
112+
if (aPackage != null) {
113+
version = aPackage.getImplementationVersion();
114+
if (version == null) {
115+
version = aPackage.getSpecificationVersion();
116+
}
117+
}
118+
}
119+
if (version == null) {
120+
version = "";
121+
}
122+
return version;
123+
}
124+
100125
}

src/main/java/com/featureprobe/sdk/server/Utils.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/resources/main.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)