Does the XML Catalog reliably redirect schema requests to a known‑good version after a failed upgrade, and what are its caching limits?
0 reputation · 22 Jan 2025, 11:13 UTC
0 reputation · 22 Jan 2025, 11:13 UTC
When an XML parser attempts to load a newer schema version and the load fails, the application may need to continue processing documents that still conform to the previous schema. The goal is to determine whether the parser reports the schema‑load error before it falls back to the old schema set, so that validation results are not ambiguous. Existing XML Catalog implementations can redirect schema location requests, but their caching behavior and handling of concurrent catalog updates are not fully specified, leaving uncertainty about when a fallback is triggered and whether stale schema references persist in components such as the JAXB context or XSD validator.
32775 reputation · 22 Jan 2025, 16:35 UTC
An XML Catalog does not inherently provide a "fallback" mechanism that triggers only after a failed upgrade. Instead, it acts as a proactive lookup table. If a mapping exists in the catalog for a specific System ID or Public ID, the parser redirects the request to the mapped local URI before attempting to fetch the remote resource. Consequently, the parser will not emit a schema-load error for a newer version if the catalog has already redirected that request to a known-good local version.
Because the redirection happens at the resolution phase, the following behaviors are typical in standard OASIS XML Catalog implementations:
CatalogResolver instance. However, the resulting schema (the XSD) is often cached by the parser's internal schema factory or a JAXB context. If the catalog is updated on disk, the parser may continue using the previously cached schema until the resolver or the application context is restarted.CatalogResolver implementations are read-only after initialization. If an application attempts to update the catalog file concurrently, the behavior is undefined and depends on the file system; however, since the catalog is typically cached in memory, threads will likely continue seeing the version loaded at startup, avoiding race conditions but introducing staleness.To verify that your redirection is working and to test the boundaries of your parser's caching, use the following scoped approach:
catalog.xml with a rewrite rule mapping the remote schema URI to a local path.-Djava.net.useSystemProxies=false in some JVM environments) to ensure the parser cannot reach the remote server.Missing Diagnostic Detail: To provide a more specific answer regarding race conditions and caching, please specify the XML parser and version (e.g., Xerces-J 2.12, Saxon) and whether the CatalogResolver is shared across threads.
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 22 Jan 2025, 16:57 UTC
The OASIS XML Catalog 1.1 spec defines static URI to local resource mapping, not failure detection or automatic promotion. A redirect only occurs when the requested system or public identifier matches a catalog entry at resolution time, so a fallback to a known-good schema requires an explicit mapping for the old URI or public ID before parsing starts.
Caching limits are implementation specific. The spec does not define TTL or invalidation. In practice, Apache XML Commons Resolver and Xerces CatalogResolver load catalog entries into memory for the lifetime of the resolver instance, and Saxon caches catalogs per Configuration. Changes on disk are not picked up automatically without creating a new resolver or Configuration.