Skip to content

Commit aa9aafd

Browse files
author
Bilal Al
committed
Renamed UserCustomHeaderDecorator to CustomHeaderDecorator
1 parent 807a815 commit aa9aafd

14 files changed

+81
-66
lines changed

client/src/main/java/io/split/client/UserCustomHeaderDecorator.java renamed to client/src/main/java/io/split/client/CustomHeaderDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Map;
44
import java.util.List;
55

6-
public interface UserCustomHeaderDecorator
6+
public interface CustomHeaderDecorator
77
{
88
/**
99
* Get the additional headers needed for all http operations

client/src/main/java/io/split/client/HttpSegmentChangeFetcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ public SegmentChange fetch(String segmentName, long since, FetchOptions options)
6464

6565
SplitHttpResponse response = _client.get(uri, options, null);
6666

67-
if (response.statusCode < HttpStatus.SC_OK || response.statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
68-
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SEGMENT_SYNC, response.statusCode);
69-
if (response.statusCode == HttpStatus.SC_FORBIDDEN) {
67+
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
68+
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SEGMENT_SYNC, response.statusCode());
69+
if (response.statusCode() == HttpStatus.SC_FORBIDDEN) {
7070
_log.error("factory instantiation: you passed a client side type sdkKey, " +
7171
"please grab an sdk key from the Split user interface that is of type server side");
7272
}
7373
throw new IllegalStateException(String.format("Could not retrieve segment changes for %s, since %s; http return code %s",
74-
segmentName, since, response.statusCode));
74+
segmentName, since, response.statusCode()));
7575
}
7676
_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.SEGMENTS, System.currentTimeMillis());
7777

78-
return Json.fromJson(response.body, SegmentChange.class);
78+
return Json.fromJson(response.body(), SegmentChange.class);
7979
} catch (Exception e) {
8080
throw new IllegalStateException(String.format("Error occurred when trying to sync segment: %s, since: %s. Details: %s",
8181
segmentName, since, e), e);

client/src/main/java/io/split/client/HttpSplitChangeFetcher.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ public SplitChange fetch(long since, FetchOptions options) {
6868
URI uri = uriBuilder.build();
6969
SplitHttpResponse response = _client.get(uri, options, null);
7070

71-
if (response.statusCode < HttpStatus.SC_OK || response.statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
72-
if (response.statusCode == HttpStatus.SC_REQUEST_URI_TOO_LONG) {
71+
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
72+
if (response.statusCode() == HttpStatus.SC_REQUEST_URI_TOO_LONG) {
7373
_log.error("The amount of flag sets provided are big causing uri length error.");
74-
throw new UriTooLongException(String.format("Status code: %s. Message: %s", response.statusCode, response.statusMessage));
74+
throw new UriTooLongException(String.format("Status code: %s. Message: %s", response.statusCode(), response.statusMessage()));
7575
}
76-
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SPLIT_SYNC, response.statusCode);
76+
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SPLIT_SYNC, response.statusCode());
7777
throw new IllegalStateException(
78-
String.format("Could not retrieve splitChanges since %s; http return code %s", since, response.statusCode)
78+
String.format("Could not retrieve splitChanges since %s; http return code %s", since, response.statusCode())
7979
);
8080
}
8181

82-
return Json.fromJson(response.body, SplitChange.class);
82+
return Json.fromJson(response.body(), SplitChange.class);
8383
} catch (Exception e) {
8484
throw new IllegalStateException(String.format("Problem fetching splitChanges since %s: %s", since, e), e);
8585
} finally {

client/src/main/java/io/split/client/RequestDecorator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.Set;
99
import java.util.List;
1010

11-
class NoOpHeaderDecorator implements UserCustomHeaderDecorator {
11+
class NoOpHeaderDecorator implements CustomHeaderDecorator {
1212
public NoOpHeaderDecorator() {}
1313
@Override
1414
public Map<String, List<String>> getHeaderOverrides() {
@@ -17,7 +17,7 @@ public Map<String, List<String>> getHeaderOverrides() {
1717
}
1818

1919
public final class RequestDecorator {
20-
UserCustomHeaderDecorator _headerDecorator;
20+
CustomHeaderDecorator _headerDecorator;
2121

2222
private static final Set<String> forbiddenHeaders = new HashSet<>(Arrays.asList(
2323
"splitsdkversion",
@@ -34,7 +34,7 @@ public final class RequestDecorator {
3434
"x-fastly-debug"
3535
));
3636

37-
public RequestDecorator(UserCustomHeaderDecorator headerDecorator) {
37+
public RequestDecorator(CustomHeaderDecorator headerDecorator) {
3838
_headerDecorator = (headerDecorator == null)
3939
? new NoOpHeaderDecorator()
4040
: headerDecorator;

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class SplitClientConfig {
9090
private final long _lastSeenCacheSize;
9191
private final HashSet<String> _flagSetsFilter;
9292
private final int _invalidSets;
93-
private final UserCustomHeaderDecorator _userCustomHeaderDecorator;
93+
private final CustomHeaderDecorator _customHeaderDecorator;
9494

9595

9696
public static Builder builder() {
@@ -148,7 +148,7 @@ private SplitClientConfig(String endpoint,
148148
ThreadFactory threadFactory,
149149
HashSet<String> flagSetsFilter,
150150
int invalidSets,
151-
UserCustomHeaderDecorator userCustomHeaderDecorator) {
151+
CustomHeaderDecorator customHeaderDecorator) {
152152
_endpoint = endpoint;
153153
_eventsEndpoint = eventsEndpoint;
154154
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
@@ -200,7 +200,7 @@ private SplitClientConfig(String endpoint,
200200
_threadFactory = threadFactory;
201201
_flagSetsFilter = flagSetsFilter;
202202
_invalidSets = invalidSets;
203-
_userCustomHeaderDecorator = userCustomHeaderDecorator;
203+
_customHeaderDecorator = customHeaderDecorator;
204204

205205
Properties props = new Properties();
206206
try {
@@ -397,8 +397,8 @@ public int getInvalidSets() {
397397
return _invalidSets;
398398
}
399399

400-
public UserCustomHeaderDecorator userCustomHeaderDecorator() {
401-
return _userCustomHeaderDecorator;
400+
public CustomHeaderDecorator customHeaderDecorator() {
401+
return _customHeaderDecorator;
402402
}
403403

404404
public static final class Builder {
@@ -457,7 +457,7 @@ public static final class Builder {
457457
private ThreadFactory _threadFactory;
458458
private HashSet<String> _flagSetsFilter = new HashSet<>();
459459
private int _invalidSetsCount = 0;
460-
private UserCustomHeaderDecorator _userCustomHeaderDecorator = null;
460+
private CustomHeaderDecorator _customHeaderDecorator = null;
461461

462462
public Builder() {
463463
}
@@ -944,11 +944,11 @@ public Builder flagSetsFilter(List<String> flagSetsFilter) {
944944
/**
945945
* User Custom Header Decorator
946946
*
947-
* @param userCustomHeaderDecorator
947+
* @param customHeaderDecorator
948948
* @return this builder
949949
*/
950-
public Builder userCustomHeaderDecorator(UserCustomHeaderDecorator userCustomHeaderDecorator) {
951-
_userCustomHeaderDecorator = userCustomHeaderDecorator;
950+
public Builder customHeaderDecorator(CustomHeaderDecorator customHeaderDecorator) {
951+
_customHeaderDecorator = customHeaderDecorator;
952952
return this;
953953
}
954954

@@ -1112,7 +1112,7 @@ public SplitClientConfig build() {
11121112
_threadFactory,
11131113
_flagSetsFilter,
11141114
_invalidSetsCount,
1115-
_userCustomHeaderDecorator);
1115+
_customHeaderDecorator);
11161116
}
11171117
}
11181118
}

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ private static SplitHttpClient buildSplitHttpClient(String apiToken, SplitClient
508508
httpClientbuilder = setupProxy(httpClientbuilder, config);
509509
}
510510

511-
return SplitHttpClientImpl.create(httpClientbuilder.build(), new RequestDecorator(config.userCustomHeaderDecorator()));
511+
return SplitHttpClientImpl.create(httpClientbuilder.build(), new RequestDecorator(config.customHeaderDecorator()));
512512
}
513513

514514
private static CloseableHttpClient buildSSEdHttpClient(String apiToken, SplitClientConfig config, SDKMetadata sdkMetadata) {

client/src/main/java/io/split/client/dtos/SplitHttpResponse.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,30 @@
55
/**
66
* A structure for returning http call results information
77
*/
8-
public final class SplitHttpResponse {
9-
public Integer statusCode;
10-
public String statusMessage;
11-
public String body;
12-
public Header[] responseHeaders;
8+
public class SplitHttpResponse {
9+
private final Integer _statusCode;
10+
private final String _statusMessage;
11+
private final String _body;
12+
private final Header[] _responseHeaders;
13+
14+
public SplitHttpResponse(Integer statusCode, String statusMessage, String body, Header[] headers) {
15+
_statusCode = statusCode;
16+
_statusMessage = statusMessage;
17+
_body = body;
18+
_responseHeaders = headers;
19+
}
20+
public Integer statusCode() {
21+
return _statusCode;
22+
}
23+
public String statusMessage() {
24+
return _statusMessage;
25+
}
26+
27+
public String body() {
28+
return _body;
29+
}
30+
31+
public Header[] responseHeaders() {
32+
return _responseHeaders;
33+
}
1334
}

client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public void postImpressionsBulk(List<TestImpressions> impressions) {
6969
additionalHeader.put(IMPRESSIONS_MODE_HEADER, _mode.toString());
7070
SplitHttpResponse response = _client.post(_impressionBulkTarget, entity, additionalHeader);
7171

72-
if (response.statusCode < HttpStatus.SC_OK || response.statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
73-
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.IMPRESSION_SYNC, response.statusCode);
72+
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
73+
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.IMPRESSION_SYNC, response.statusCode());
7474
}
7575
_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.IMPRESSIONS, System.currentTimeMillis());
7676

@@ -94,8 +94,8 @@ public void postCounters(HashMap<ImpressionCounter.Key, Integer> raw) {
9494
Utils.toJsonEntity(ImpressionCount.fromImpressionCounterData(raw)),
9595
null);
9696

97-
if (response.statusCode < HttpStatus.SC_OK || response.statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
98-
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.IMPRESSION_COUNT_SYNC, response.statusCode);
97+
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
98+
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.IMPRESSION_COUNT_SYNC, response.statusCode());
9999
}
100100
_telemetryRuntimeProducer.recordSyncLatency(HTTPLatenciesEnum.IMPRESSIONS_COUNT, System.currentTimeMillis() - initTime);
101101
_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.IMPRESSIONS_COUNT, System.currentTimeMillis());

client/src/main/java/io/split/engine/sse/AuthApiClientImp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public AuthenticationResponse Authenticate() {
3838
long initTime = System.currentTimeMillis();
3939
URI uri = new URIBuilder(_target).build();
4040
SplitHttpResponse response = _httpClient.get(uri, new FetchOptions.Builder().cacheControlHeaders(false).build(), null);
41-
Integer statusCode = response.statusCode;
41+
Integer statusCode = response.statusCode();
4242

4343
if (statusCode == HttpStatus.SC_OK) {
4444
_log.debug(String.format("Success connection to: %s", _target));
4545

4646
_telemetryRuntimeProducer.recordTokenRefreshes();
4747
_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.TOKEN, System.currentTimeMillis());
4848
_telemetryRuntimeProducer.recordSyncLatency(HTTPLatenciesEnum.TOKEN, System.currentTimeMillis()-initTime);
49-
return getSuccessResponse(response.body);
49+
return getSuccessResponse(response.body());
5050
}
5151

5252
_log.error(String.format("Problem to connect to : %s. Response status: %s", _target, statusCode));

client/src/main/java/io/split/service/HttpPostImp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public void post(URI uri, Object object, String posted, HttpParamsWrapper httpPa
2929

3030
try {
3131
SplitHttpResponse response = _client.post(uri, entity, null);
32-
if (response.statusCode < HttpStatus.SC_OK || response.statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
33-
_telemetryRuntimeProducer.recordSyncError(httpParamsWrapper.getResourceEnum(), response.statusCode);
32+
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
33+
_telemetryRuntimeProducer.recordSyncError(httpParamsWrapper.getResourceEnum(), response.statusCode());
3434
return;
3535
}
3636
_telemetryRuntimeProducer.recordSyncLatency(httpParamsWrapper.getHttpLatenciesEnum(), System.currentTimeMillis() - initTime);

0 commit comments

Comments
 (0)