To use XStream in your camel routes you need to add the a dependency on camel-xstream which implements this data format.
Maven users will need to add the following dependency to their
pom.xml for this component:
Using the Java DSL
If you would like to configure the
XStream instance used by the Camel for the message transformation, you can simply pass a reference to that instance on the DSL level.
XMLInputFactory and XMLOutputFactory
The XStream library uses the
javax.xml.stream.XMLOutputFactory, you can control which implementation of this factory should be used.
The Factory is discovered using this algorithm:
1. Use the
javax.xml.stream.XMLOutputFactory system property.
2. Use the
lib/xml.stream.properties file in the
3. Use the Services API, if available, to determine the classname by looking in the
META-INF/services/javax.xml.stream.XMLOutputFactory files in jars available to the JRE.
4. Use the platform default XMLInputFactory,XMLOutputFactory instance.
How to set the XML encoding in Xstream DataFormat?
From Camel 2.2.0, you can set the encoding of XML in Xstream DataFormat by setting the Exchange's property with the key
Exchange.CHARSET_NAME, or setting the encoding property on Xstream from DSL or Spring config.
Setting the type permissions of Xstream DataFormat
In Camel, one can always use its own processing step in the route to filter and block certain XML documents to be routed to the XStream's unmarhall step. From Camel 2.16.1, 2.15.5, you can set XStream's type permissions to automatically allow or deny the instantiation of certain types.
The default type permissions setting used by Camel denies all types except for those from java.lang and java.util packages. This setting can be changed by setting System property org.apache.camel.xstream.permissions. Its value is a string of comma-separated permission terms, each representing a type being allowed or denied, depending on whether the term is prefixed with '+' (note '+' may be omitted) or with '-', respectively.
Each term may contain a wildcard character '*'. For example, value "-*,java.lang.*,java.util.*" indicates denying all types except for java.lang.* and java.util.* classes. Setting this value to an empty string "" reverts to the default XStream's type permissions handling which denies certain blacklisted classes and allow others.
The type permissions setting can be extended at an individual XStream DataFormat instance by setting its type permissions property.