Este contenido no está disponible en el idioma seleccionado.
Chapter 322. StAX Component
Available as of Camel version 2.9
The StAX component allows messages to be process through a SAX ContentHandler.
Another feature of this component is to allow to iterate over JAXB records using StAX, for example using the Splitter EIP.
Maven users will need to add the following dependency to their pom.xml
for this component:
322.1. URI format Copiar enlaceEnlace copiado en el portapapeles!
stax:content-handler-class
stax:content-handler-class
example:
stax:org.superbiz.FooContentHandler
stax:org.superbiz.FooContentHandler
From Camel 2.11.1 onwards you can lookup a org.xml.sax.ContentHandler
bean from the Registry using the # syntax as shown:
stax:#myHandler
stax:#myHandler
322.2. Options Copiar enlaceEnlace copiado en el portapapeles!
The StAX component has no options.
The StAX endpoint is configured using URI syntax:
stax:contentHandlerClass
stax:contentHandlerClass
with the following path and query parameters:
322.2.1. Path Parameters (1 parameters): Copiar enlaceEnlace copiado en el portapapeles!
Name | Description | Default | Type |
---|---|---|---|
contentHandlerClass | Required The FQN class name for the ContentHandler implementation to use. | String |
322.2.2. Query Parameters (1 parameters): Copiar enlaceEnlace copiado en el portapapeles!
Name | Description | Default | Type |
---|---|---|---|
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
322.3. Usage of a content handler as StAX parser Copiar enlaceEnlace copiado en el portapapeles!
The message body after the handling is the handler itself.
Here an example:
322.4. Iterate over a collection using JAXB and StAX Copiar enlaceEnlace copiado en el portapapeles!
First we suppose you have JAXB objects.
For instance a list of records in a wrapper object:
and
Then you get a XML file to process:
The StAX component provides an StAXBuilder
which can be used when iterating XML elements with the Camel Splitter
from("file:target/in") .split(stax(Record.class)).streaming() .to("mock:records");
from("file:target/in")
.split(stax(Record.class)).streaming()
.to("mock:records");
Where stax
is a static method on org.apache.camel.component.stax.StAXBuilder
which you can static import in the Java code. The stax builder is by default namespace aware on the XMLReader it uses. From Camel 2.11.1 onwards you can turn this off by setting the boolean parameter to false, as shown below:
from("file:target/in") .split(stax(Record.class, false)).streaming() .to("mock:records");
from("file:target/in")
.split(stax(Record.class, false)).streaming()
.to("mock:records");
322.4.1. The previous example with XML DSL Copiar enlaceEnlace copiado en el portapapeles!
The example above could be implemented as follows in XML DSL
322.5. See Also Copiar enlaceEnlace copiado en el portapapeles!
- Configuring Camel
- Component
- Endpoint
- Getting Started