Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 122. StAX
StAX Component 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Available as of Camel 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:
URI format 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
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
Usage of a content handler as StAX parser 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The message body after the handling is the handler itself.
Here an example:
Iterate over a collection using JAXB and StAX 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
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");
The previous example with XML DSL 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The example above could be implemented as follows in XML DSL