camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > XStream
Date Fri, 29 Jan 2010 12:23:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/XStream">XStream</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
     CAMEL-2407
          <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
     CAMEL-2407<br />
     </div>
          <br/>
     <div class="notificationGreySide">
         <h2><a name="XStream-XStream"></a>XStream</h2>

<p>XStream is a <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> which uses the <a href="http://xstream.codehaus.org/" rel="nofollow">XStream
library</a> to marshal and unmarshal Java objects to and from XML.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// lets turn <span class="code-object">Object</span>
messages into XML then send to MQSeries
</span>from(<span class="code-quote">"activemq:My.Queue"</span>).
  marshal().xstream().
  to(<span class="code-quote">"mqseries:Another.Queue"</span>);
</pre>
</div></div>

<h3><a name="XStream-XMLInputFactoryandXMLOutputFactory"></a>XMLInputFactory
and XMLOutputFactory </h3>
<p>The XStream library|http://xstream.codehaus.org/] uses the <tt>javax.xml.stream.XMLInputFactory</tt>
and <tt>javax.xml.stream.XMLOutputFactory</tt>,  you can control which implementation
of this factory should be used.</p>

<p>The Factory is discovered using this algorithm:<br/>
1. Use the <tt>javax.xml.stream.XMLInputFactory</tt> , <tt>javax.xml.stream.XMLOutputFactory</tt>
system property.<br/>
2. Use the <tt>lib/xml.stream.properties</tt> file in the <tt>JRE_HOME</tt>
directory.<br/>
3. Use the Services API, if available, to determine the classname by looking in the <tt>META-INF/services/javax.xml.stream.XMLInputFactory</tt>,
<tt>META-INF/services/javax.xml.stream.XMLOutputFactory</tt>  files in jars available
to the JRE.<br/>
4. Use the platform default XMLInputFactory,XMLOutputFactory instance.</p>

<h3><a name="XStream-HowtosettheXMLencodinginXstreamDataFormat%3F"></a>How
to set the XML encoding in Xstream DataFormat?</h3>
<p>From Camel 1.6.3 or Camel 2.2.0, you can set the encoding of XML in Xstream DataFormat
by setting the Exchange's property with the key <tt>Exchange.CHARSET_NAME</tt>,
or setting the encoding property on Xstream from DSL or Spring config.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  marshal().xstream(<span class="code-quote">"UTF-8"</span>).
  to(<span class="code-quote">"mqseries:Another.Queue"</span>);
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    
    <span class="code-tag"><span class="code-comment">&lt;!-- we define the
json xstream data formats to be used (xstream is default) --&gt;</span></span>
    <span class="code-tag">&lt;dataFormats&gt;</span>
        <span class="code-tag">&lt;xstream id=<span class="code-quote">"xstream-utf8"</span>
encoding=<span class="code-quote">"UTF-8"</span>/&gt;</span>
        <span class="code-tag">&lt;xstream id=<span class="code-quote">"xstream-default"</span>/&gt;</span>
    <span class="code-tag">&lt;/dataFormats&gt;</span>

    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in"</span>/&gt;</span>
        <span class="code-tag">&lt;marshal ref=<span class="code-quote">"xstream-default"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>

    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:in-UTF-8"</span>/&gt;</span>
        <span class="code-tag">&lt;marshal ref=<span class="code-quote">"xstream-utf8"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>

<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="XStream-Dependencies"></a>Dependencies</h3>

<p>To use XStream in your camel routes you need to add the a dependency on <b>camel-xstream</b>
which implements this data format. </p>

<p>If you use maven you could just add the following to your pom.xml, substituting the
version number for the latest &amp; greatest release (see <a href="/confluence/display/CAMEL/Download"
title="Download">the download page for the latest versions</a>).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-xstream&lt;/artifactId&gt;
  &lt;version&gt;1.5.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/XStream">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=69070&revisedVersion=7&originalVersion=6">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/XStream?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message