376.3. Spring DSL에서 YAML 사용
Spring DSL에서 데이터 형식을 사용할 때는 먼저 데이터 형식을 선언해야 합니다. 이 작업은 DataFormats XML 태그에서 수행됩니다.
<dataFormats> <!-- here we define a YAML data format with the id snake and that it should use the TestPojo as the class type when doing unmarshal. The unmarshalTypeName is optional --> <yaml id="snake" library="SnakeYAML" unmarshalTypeName="org.apache.camel.component.yaml.model.TestPojo"/> <!-- here we define a YAML data format with the id snake-safe which restricts the classes to be loaded from YAML to TestPojo and those belonging to package com.mycompany --> <yaml id="snake-safe"> <typeFilter value="org.apache.camel.component.yaml.model.TestPojo"/> <typeFilter value="com.mycompany\..*" type="regexp"/> </yaml> </dataFormats>
<dataFormats>
<!--
here we define a YAML data format with the id snake and that it should use
the TestPojo as the class type when doing unmarshal. The unmarshalTypeName
is optional
-->
<yaml
id="snake"
library="SnakeYAML"
unmarshalTypeName="org.apache.camel.component.yaml.model.TestPojo"/>
<!--
here we define a YAML data format with the id snake-safe which restricts the
classes to be loaded from YAML to TestPojo and those belonging to package
com.mycompany
-->
<yaml id="snake-safe">
<typeFilter value="org.apache.camel.component.yaml.model.TestPojo"/>
<typeFilter value="com.mycompany\..*" type="regexp"/>
</yaml>
</dataFormats>
그런 다음 경로에서 이러한 ID를 참조할 수 있습니다.
<route> <from uri="direct:unmarshal"/> <unmarshal> <custom ref="snake"/> </unmarshal> <to uri="mock:unmarshal"/> </route> <route> <from uri="direct:unmarshal-safe"/> <unmarshal> <custom ref="snake-safe"/> </unmarshal> <to uri="mock:unmarshal-safe"/> </route>
<route>
<from uri="direct:unmarshal"/>
<unmarshal>
<custom ref="snake"/>
</unmarshal>
<to uri="mock:unmarshal"/>
</route>
<route>
<from uri="direct:unmarshal-safe"/>
<unmarshal>
<custom ref="snake-safe"/>
</unmarshal>
<to uri="mock:unmarshal-safe"/>
</route>