DEV Community

Sergey Shinder
Sergey Shinder

Posted on

Our customs broker changed an XML prefix and every shipment stayed on the dock

Our customs broker confirms each export declaration by sending an XML message with a status and a reference. In October they upgraded their messaging platform over a weekend. On Monday every shipment leaving our warehouse sat at awaiting clearance. The trucks were loaded, and the broker insisted, correctly, that every declaration had cleared.

Their messages had arrived with the same content. What changed was how the XML was written. The old platform declared the broker's namespace with the prefix cus and wrote cus:Status. The new one declared the same namespace URI with the prefix ns2 and wrote ns2:Status. To any XML parser those are the same element. To our reader they were not, because six years earlier someone had written it with an XPath expression containing the literal text cus:Status, plus a fallback regular expression looking for the same string. Neither matched. The reader found no status, and our model treated a missing status as pending, which is a sensible default for a declaration nobody has answered yet.

So nothing failed. The listener acknowledged every message, the parser threw no exceptions, and the dashboard counted messages received as normal. Two hundred and seventy declarations waited until two in the afternoon, when a warehouse lead rang the broker for the fourth time and somebody there sent us a raw message.

We patched the reader within the hour and replayed the day's messages from our archive. The lasting version uses a namespace aware parser and matches elements by namespace URI and local name, never by prefix, and the regular expression is gone. A message with no status we can read is no longer pending. It goes to a rejected queue that alerts, because an answer we cannot read is not the same thing as no answer. The contract tests for every XML partner now include each sample message rewritten with different prefixes, with a default namespace and with reordered attributes, and all of them must produce the same result. We also asked the broker to tell us about platform changes in advance, something they had never known we needed.

A prefix is a local nickname chosen by whoever serialises the document, and the specification lets them change it whenever they like. We had built on the spelling of their XML rather than its meaning, and the spelling was the one part they never promised to keep.

– Sergey Shinder

Top comments (0)