Camel Data Format

JAXB

Using the Java DSL
For example the following uses a named DataFormat of jaxb which is
configured with a number of Java package names to initialize the
JAXBContext.
DataFormat jaxb = new JaxbDataFormat("com.acme.model");
from("activemq:My.Queue").
unmarshal(jaxb).
to("mqseries:Another.Queue");
You can if you prefer use a named reference to a data format which can then
be defined in your Registry such as via your Spring XML file. e.g.
from("activemq:My.Queue").
unmarshal("myJaxbDataType").
to("mqseries:Another.Queue");


Using Spring XML
The following example shows how to use JAXB to unmarshal using Spring
configuring the jaxb data type
<camelContext id="camel" xmlns="
http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
306 DATA FORMAT APPENDIX
<unmarshal>
<jaxb prettyPrint="true" contextPath="org.apache.camel.example"/>
</unmarshal>
<to uri="mock:result"/>
</route>
</camelContext>
This example shows how to configure the data type just once and reuse it on
multiple routes. For Camel versions below 1.5.0 you have to set the <jaxb>
element directly in <camelContext>.
<camelContext id="camel" xmlns="
http://camel.apache.org/schema/spring">
<dataFormats>
<jaxb id="myJaxb" prettyPrint="true" contextPath="org.apache.camel.example"/>
</dataFormats>
<route>
<from uri="direct:start"/>
<marshal ref="myJaxb"/>
<to uri="direct:marshalled"/>
</route>
<route>
<from uri="direct:marshalled"/>
<unmarshal ref="myJaxb"/>
<to uri="mock:result"/>
</route>
</camelContext>


Partial marshalling/unmarshalling
This feature is new to Camel 2.2.0.
JAXB 2 supports marshalling and unmarshalling XML tree fragments. By
default JAXB looks for @XmlRootElement annotation on given class to operate
on whole XML tree. This is useful but not always - sometimes generated code
does not have @XmlRootElement annotation, sometimes you need
unmarshall only part of tree.
In that case you can use partial unmarshalling. To enable this behaviours you
need set property partClass. Camel will pass this class to JAXB's
unmarshaler.
<camelContext id="camel" xmlns="
http://camel.apache.org/schema/spring">
<route>
<from uri="direct:marshal"/>
<marshal>
<jaxb prettyPrint="false" contextPath="org.apache.camel.example"
partClass="org.apache.camel.example.PurchaseOrder"


 Multiple context paths
It is possible to use this data format with more than one context
path. You can specify context path using : as separator, for
example com.mycompany:com.mycompany2. Note that this is
handled by JAXB implementation and might change if you use
different vendor than RI.


fragment="true"
partNamespace="{http://example.camel.org/apache}po" />
</marshal>
<to uri="mock:marshal"/>
</route>
<route>
<from uri="direct:unmarshal"/>
<unmarshal>
<jaxb prettyPrint="false" contextPath="org.apache.camel.example"
partClass="org.apache.camel.example.Partial" />
</unmarshal>
<to uri="mock:unmarshal"/>
</route>
</camelContext>
For marshalling you have to add partNamespace attribute with QName of
destination namespace. Example of Spring DSL you can find above.

 

 

XMLBEANS

XmlBeans is a Data Format which uses the XmlBeans library to unmarshal an
XML payload into Java objects or to marshal Java objects into an XML
payload.

XSTREAM

XStream is a Data Format which uses the XStream library to marshal and
unmarshal Java objects to and from XML

CSV

EDI DATAFORMAT

FLATPACK DATAFORMAT

JSON

TIDYMARKUP

TidyMarkup is a Data Format that uses the TagSoup to tidy up HTML. It can be
used to parse ugly HTML and return it as pretty wellformed HTML

ANNOTATIONS

XMLSECURITY DATA FORMAT

The XMLSecurity DataFormat facilitates encryption and decryption of XML
payloads at the Document, Element and Element Content levels (including
simultaneous multi-node encryption/decryption using XPATH)

CASTOR

Castor is a Data Format which uses the Castor XML library to unmarshal an
XML payload into Java objects or to marshal Java objects into an XML
payload

Protobuf - Protocol Buffers

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值