Skip to content

Commit 20888a4

Browse files
authored
Merge pull request #7501 from entur/stream-siri-et-initial-data-parse
Stream SIRI-ET initial data HTTP response directly into XML parser
2 parents 096bcc7 + 57914e8 commit 20888a4

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

application/src/main/java/org/opentripplanner/updater/trip/siri/updater/google/GooglePubsubEstimatedTimetableSource.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)