@@ -265,16 +265,12 @@ private Optional<ServiceDelivery> serviceDelivery(ByteString data) {
265265 */
266266 private void initializeData () {
267267 if (dataInitializationUrl != null ) {
268- LOG .info ("Fetching initial data from {}" , dataInitializationUrl );
268+ LOG .info ("Fetching and parsing initial data from {}" , dataInitializationUrl );
269269 final long t1 = System .currentTimeMillis ();
270- ByteString value = fetchInitialData ();
270+ var serviceDelivery = fetchAndParseInitialData ();
271271 final long t2 = System .currentTimeMillis ();
272- LOG .info (
273- "Fetching initial data - finished after {} ms, got {}" ,
274- (t2 - t1 ),
275- FileSizeToTextConverter .fileSizeToString (value .size ())
276- );
277- serviceDelivery (value )
272+ LOG .info ("Fetching and parsing initial data - finished after {} ms" , (t2 - t1 ));
273+ serviceDelivery
278274 .map (serviceDeliveryConsumer )
279275 .ifPresent (future -> {
280276 try {
@@ -299,17 +295,18 @@ private void initializeData() {
299295 }
300296
301297 /**
302- * Fetch the backlog of messages over HTTP from the configured data initialization URL .
298+ * Fetch the backlog of messages over HTTP and parse the XML response .
303299 */
304- private ByteString fetchInitialData () {
300+ private Optional < ServiceDelivery > fetchAndParseInitialData () {
305301 try (OtpHttpClientFactory otpHttpClientFactory = new OtpHttpClientFactory ()) {
306302 var otpHttpClient = otpHttpClientFactory .create (LOG );
307- return otpHttpClient .getAndMap (
303+ var siri = otpHttpClient .getAndMap (
308304 dataInitializationUrl ,
309305 initialGetDataTimeout ,
310306 HttpHeaders .of (Map .of ("Content-Type" , "application/xml" )),
311- response -> ByteString . readFrom (response .body ())
307+ response -> SiriXml . parseXml (response .body ())
312308 );
309+ return Optional .ofNullable (siri .getServiceDelivery ());
313310 }
314311 }
315312
0 commit comments