28
28
import java .util .ArrayList ;
29
29
30
30
import static com .google .common .base .Preconditions .checkNotNull ;
31
- import static io .split .Spec .SPEC_VERSION ;
32
31
import static io .split .Spec .SPEC_1_3 ;
33
32
import static io .split .Spec .SPEC_1_1 ;
34
33
@@ -44,6 +43,7 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
44
43
private static final String TILL = "till" ;
45
44
private static final String SETS = "sets" ;
46
45
private static final String SPEC = "s" ;
46
+ private String specVersion = SPEC_1_3 ;
47
47
private int PROXY_CHECK_INTERVAL_MILLISECONDS_SS = 24 * 60 * 60 * 1000 ;
48
48
private Long _lastProxyCheckTimestamp = 0L ;
49
49
private final SplitHttpClient _client ;
@@ -75,9 +75,9 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
75
75
long start = System .currentTimeMillis ();
76
76
SplitHttpResponse response ;
77
77
try {
78
- if (SPEC_VERSION .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
78
+ if (specVersion .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
79
79
_log .info ("Switching to new Feature flag spec ({}) and fetching." , SPEC_1_3 );
80
- SPEC_VERSION = SPEC_1_3 ;
80
+ specVersion = SPEC_1_3 ;
81
81
}
82
82
URI uri = buildURL (options , since , sinceRBS );
83
83
response = _client .get (uri , options , null );
@@ -87,8 +87,8 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
87
87
throw new UriTooLongException (String .format ("Status code: %s. Message: %s" , response .statusCode (), response .statusMessage ()));
88
88
}
89
89
90
- if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && SPEC_VERSION .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
91
- SPEC_VERSION = Spec .SPEC_1_1 ;
90
+ if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && specVersion .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
91
+ specVersion = Spec .SPEC_1_1 ;
92
92
_log .warn ("Detected proxy without support for Feature flags spec {} version, will switch to spec version {}" ,
93
93
SPEC_1_3 , SPEC_1_1 );
94
94
_lastProxyCheckTimestamp = System .currentTimeMillis ();
@@ -107,7 +107,7 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
107
107
}
108
108
109
109
SplitChange splitChange = new SplitChange ();
110
- if (SPEC_VERSION .equals (Spec .SPEC_1_1 )) {
110
+ if (specVersion .equals (Spec .SPEC_1_1 )) {
111
111
splitChange .featureFlags = convertBodyToOldSpec (response .body ());
112
112
splitChange .ruleBasedSegments = createEmptyDTO ();
113
113
} else {
@@ -134,11 +134,11 @@ private ChangeDto<RuleBasedSegment> createEmptyDTO() {
134
134
return dto ;
135
135
}
136
136
private ChangeDto <Split > convertBodyToOldSpec (String body ) {
137
- return Json .fromJson (body , SplitChangesOldPayloadDto .class ).toChangeDTO () ;
137
+ return Json .fromJson (body , SplitChangesOldPayloadDto .class ).toSplitChange (). featureFlags ;
138
138
}
139
139
140
140
private URI buildURL (FetchOptions options , long since , long sinceRBS ) throws URISyntaxException {
141
- URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + SPEC_VERSION );
141
+ URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + specVersion );
142
142
uriBuilder .addParameter (SINCE , "" + since );
143
143
uriBuilder .addParameter (RB_SINCE , "" + sinceRBS );
144
144
if (!options .flagSetsFilter ().isEmpty ()) {
0 commit comments