@@ -66,48 +66,40 @@ long makeRandomTill() {
6666 @ Override
6767 public SplitChange fetch (long since , long sinceRBS , FetchOptions options ) {
6868 long start = System .currentTimeMillis ();
69- for (int i =0 ; i <2 ; i ++) {
70- try {
71- URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + SPEC_VERSION );
72- uriBuilder .addParameter (SINCE , "" + since );
73- if (SPEC_VERSION .equals (Spec .SPEC_1_3 )) {
74- uriBuilder .addParameter (RB_SINCE , "" + sinceRBS );
75- }
76- if (!options .flagSetsFilter ().isEmpty ()) {
77- uriBuilder .addParameter (SETS , "" + options .flagSetsFilter ());
78- }
79- if (options .hasCustomCN ()) {
80- uriBuilder .addParameter (TILL , "" + options .targetCN ());
81- }
82- URI uri = uriBuilder .build ();
83- SplitHttpResponse response = _client .get (uri , options , null );
69+ try {
70+ URI uri = buildURL (options , since , sinceRBS );
71+ SplitHttpResponse response = _client .get (uri , options , null );
8472
85- if (response .statusCode () < HttpStatus .SC_OK || response .statusCode () >= HttpStatus .SC_MULTIPLE_CHOICES ) {
86- if (response .statusCode () == HttpStatus .SC_REQUEST_URI_TOO_LONG ) {
87- _log .error ("The amount of flag sets provided are big causing uri length error." );
88- throw new UriTooLongException (String .format ("Status code: %s. Message: %s" , response .statusCode (), response .statusMessage ()));
89- }
90- if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && response .statusMessage ().equals ("unknown spec" )) {
91- _log .warn (String .format ("Detected old spec response, falling back to spec 1.1" ));
92- SPEC_VERSION = Spec .SPEC_1_1 ;
93- continue ;
94- }
95- _telemetryRuntimeProducer .recordSyncError (ResourceEnum .SPLIT_SYNC , response .statusCode ());
96- throw new IllegalStateException (
97- String .format ("Could not retrieve splitChanges since %s; http return code %s" , since , response .statusCode ())
98- );
73+ if (response .statusCode () < HttpStatus .SC_OK || response .statusCode () >= HttpStatus .SC_MULTIPLE_CHOICES ) {
74+ if (response .statusCode () == HttpStatus .SC_REQUEST_URI_TOO_LONG ) {
75+ _log .error ("The amount of flag sets provided are big causing uri length error." );
76+ throw new UriTooLongException (String .format ("Status code: %s. Message: %s" , response .statusCode (), response .statusMessage ()));
9977 }
100- if (SPEC_VERSION .equals (Spec .SPEC_1_1 )) {
101- return Json .fromJson (response .body (), SplitChange .class );
102- }
103- return GenericClientUtil .ExtractFeatureFlagsAndRuleBasedSegments (response .body ());
104- } catch (Exception e ) {
105- throw new IllegalStateException (String .format ("Problem fetching splitChanges since %s: %s" , since , e ), e );
106- } finally {
107- _telemetryRuntimeProducer .recordSyncLatency (HTTPLatenciesEnum .SPLITS , System .currentTimeMillis () - start );
78+
79+ _telemetryRuntimeProducer .recordSyncError (ResourceEnum .SPLIT_SYNC , response .statusCode ());
80+ throw new IllegalStateException (
81+ String .format ("Could not retrieve splitChanges since %s; http return code %s" , since , response .statusCode ())
82+ );
10883 }
84+ return GenericClientUtil .ExtractFeatureFlagsAndRuleBasedSegments (response .body ());
85+ } catch (Exception e ) {
86+ throw new IllegalStateException (String .format ("Problem fetching splitChanges since %s: %s" , since , e ), e );
87+ } finally {
88+ _telemetryRuntimeProducer .recordSyncLatency (HTTPLatenciesEnum .SPLITS , System .currentTimeMillis () - start );
89+ }
90+ }
91+
92+ private URI buildURL (FetchOptions options , long since , long sinceRBS ) throws URISyntaxException {
93+ URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + SPEC_VERSION );
94+ uriBuilder .addParameter (SINCE , "" + since );
95+ uriBuilder .addParameter (RB_SINCE , "" + sinceRBS );
96+ if (!options .flagSetsFilter ().isEmpty ()) {
97+ uriBuilder .addParameter (SETS , "" + options .flagSetsFilter ());
98+ }
99+ if (options .hasCustomCN ()) {
100+ uriBuilder .addParameter (TILL , "" + options .targetCN ());
109101 }
110- return null ;
102+ return uriBuilder . build () ;
111103 }
112104
113105 @ VisibleForTesting
0 commit comments