He-Pin opened a new pull request, #1492: URL: https://github.com/apache/pekko-connectors/pull/1492
## Motivation The XML connector currently provides `parser()` which produces a `Flow[ByteString, ParseEvent, NotUsed]`, but there is no way to attach contextual information (such as line numbers, source identifiers, or custom metadata) to the XML parse events as they flow through the stream. This is a migration of upstream [akka/alpakka#2935](https://github.com/akka/alpakka/pull/2935) (commit [`b813e7f`](https://github.com/akka/alpakka/commit/b813e7fb772153edf14f7e5997abad72f5acef07)), which is now Apache licensed. ## Modification ### New `ContextHandler` abstraction (`StreamingXmlParser.scala`) - Added a sealed `ContextHandler[Ctx]` trait with two implementations: - `UncontextualHandler` — used by the existing `parser()` API, emits events without context - `ContextualHandler[Ctx]` — wraps events with user-supplied context via `FlowWithContext` - Made `StreamingXmlParser` generic with type parameters `[A, B, Ctx]` to support both contextual and non-contextual modes - All `push()` calls now go through `transform.buildOutput()` which handles context attachment ### Scala DSL (`scaladsl/XmlParsing.scala`) - Added `parserWithContext[Ctx]()` method returning `FlowWithContext[ByteString, Ctx, ParseEvent, Ctx, NotUsed]` - Enables idiomatic Scala usage: `FlowWithContext[ByteString, Ctx].via(XmlParsing.parserWithContext())` ### Java DSL (`javadsl/XmlParsing.scala`) - Added 3 `parserWithContext` overloads: - `parserWithContext[Ctx]()` — default settings - `parserWithContext[Ctx](configPath: String)` — custom config - `parserWithContext[Ctx](xmlInputFactory: XMLInputFactory)` — custom factory ### Tests (`XmlProcessingSpec.scala`) - Added test "parse XML and attach line numbers as context" demonstrating the new API - Verifies context (line numbers) flows through correctly alongside parse events ## Result - All 49 XML connector tests pass (including the new context-aware test) - Code formatted with scalafmt - No breaking changes to existing API — `parser()` continues to work unchanged - New `parserWithContext[Ctx]()` API available for both Scala and Java ## References - Upstream PR: [akka/alpakka#2935](https://github.com/akka/alpakka/pull/2935) (which is now Apache licensed) - Upstream commit: [`b813e7f`](https://github.com/akka/alpakka/commit/b813e7fb772153edf14f7e5997abad72f5acef07) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
