camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > jibx
Date Wed, 05 Jan 2011 17:08:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/jibx">jibx</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~hekonsek">Henryk
Konsek</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="jibx-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/" class="external-link"
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="jibx-XMLInputFactoryandXMLOutputFactory"></a>XMLInputFactory
and XMLOutputFactory </h3>
<p><a href="http://xstream.codehaus.org/" class="external-link" rel="nofollow">The
XStream library</a> 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="jibx-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="jibx-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="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/jibx">View Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/jibx?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message