Skip to content

Commit 6653a9f

Browse files
committed
updates
Signed-off-by: liran2000 <[email protected]>
1 parent 34deb32 commit 6653a9f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tools/flagd-http-connector/src/main/java/dev/openfeature/contrib/tools/flagd/resolver/process/storage/connector/sync/http/HttpConnector.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class HttpConnector implements QueueSource {
5555

5656
@NonNull
5757
private String url;
58+
private URI uri;
5859

5960
/**
6061
* HttpConnector constructor.
@@ -71,6 +72,7 @@ public HttpConnector(HttpConnectorOptions httpConnectorOptions) {
7172
httpConnectorOptions.getProxyPort()));
7273
}
7374
this.url = httpConnectorOptions.getUrl();
75+
uri = URI.create(url);
7476
this.headers = httpConnectorOptions.getHeaders();
7577
this.httpClientExecutor = httpConnectorOptions.getHttpClientExecutor();
7678
scheduler = Executors.newScheduledThreadPool(httpConnectorOptions.getScheduledThreadPoolSize());
@@ -154,7 +156,7 @@ private boolean fetchAndUpdate() {
154156
}
155157
}
156158
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
157-
.uri(URI.create(url))
159+
.uri(uri)
158160
.timeout(Duration.ofSeconds(requestTimeoutSeconds))
159161
.GET();
160162
headers.forEach(requestBuilder::header);
@@ -188,6 +190,11 @@ private boolean fetchAndUpdate() {
188190
log.warn("Unable to offer file content to queue: queue is full");
189191
return false;
190192
}
193+
updateCache(payload);
194+
return true;
195+
}
196+
197+
private void updateCache(String payload) {
191198
if (payloadCache != null) {
192199
log.debug("scheduling cache update if needed");
193200
scheduler.execute(() -> {
@@ -202,7 +209,6 @@ private boolean fetchAndUpdate() {
202209
}
203210
);
204211
}
205-
return true;
206212
}
207213

208214
private static boolean isSuccessful(HttpResponse<String> response) {

tools/flagd-http-connector/src/main/java/dev/openfeature/contrib/tools/flagd/resolver/process/storage/connector/sync/http/HttpConnectorOptions.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dev.openfeature.contrib.tools.flagd.resolver.process.storage.connector.sync.http;
22

33
import java.lang.reflect.Method;
4+
import java.net.MalformedURLException;
5+
import java.net.URISyntaxException;
46
import java.net.URL;
57
import java.util.HashMap;
68
import java.util.Map;
@@ -117,7 +119,7 @@ private void validate(String url, Integer pollIntervalSeconds, Integer linkedBlo
117119
Integer scheduledThreadPoolSize, Integer requestTimeoutSeconds, Integer connectTimeoutSeconds,
118120
String proxyHost, Integer proxyPort, PayloadCacheOptions payloadCacheOptions,
119121
PayloadCache payloadCache, Boolean useFailsafeCache, Boolean usePollingCache) {
120-
new URL(url).toURI();
122+
validateUrl(url);
121123
if (linkedBlockingQueueCapacity != null
122124
&& (linkedBlockingQueueCapacity < 1 || linkedBlockingQueueCapacity > 1000)) {
123125
throw new IllegalArgumentException("linkedBlockingQueueCapacity must be between 1 and 1000");
@@ -170,4 +172,8 @@ private void validate(String url, Integer pollIntervalSeconds, Integer linkedBlo
170172
}
171173
}
172174
}
175+
176+
private static void validateUrl(String url) throws URISyntaxException, MalformedURLException {
177+
new URL(url).toURI();
178+
}
173179
}

0 commit comments

Comments
 (0)