camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Validation
Date Thu, 18 Mar 2010 07:54: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/Validation">Validation</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="Validation-ValidationComponent"></a>Validation Component</h2>

<p>The Validation component performs XML validation of the message body using the JAXP
Validation API and based on any of the supported XML schema languages, which defaults to <a
href="http://www.w3.org/XML/Schema" rel="nofollow">XML Schema</a> </p>

<p>Note that the <a href="/confluence/display/CAMEL/Jing" title="Jing">Jing</a>
component also supports the following useful schema languages:</p>

<ul>
	<li><a href="http://relaxng.org/compact-tutorial-20030326.html" rel="nofollow">RelaxNG
Compact Syntax</a></li>
	<li><a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a></li>
</ul>


<p>The <a href="/confluence/display/CAMEL/MSV" title="MSV">MSV</a> component
also supports <a href="http://relaxng.org/" rel="nofollow">RelaxNG XML Syntax</a>.</p>

<h3><a name="Validation-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
validator:someLocalOrRemoteResource
</pre>
</div></div>

<p>Where <b>someLocalOrRemoteResource</b> is some URL to a local resource
on the classpath or a full URL to a remote resource or resource on the file system which contains
the XSD to validate against. For example:</p>

<ul>
	<li><tt>msv:org/foo/bar.xsd</tt></li>
	<li><tt>msv:<a href="file:../foo/bar.xsd" rel="nofollow">file:../foo/bar.xsd</a></tt></li>
	<li><tt>msv:<a href="http://acme.com/cheese.xsd" rel="nofollow">http://acme.com/cheese.xsd</a></tt></li>
	<li><tt>validator:com/mypackage/myschema.xsd</tt></li>
</ul>


<h3><a name="Validation-Options"></a>Options</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>useDom</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Whether <tt>DOMSource</tt>/<tt>DOMResult</tt>
or <tt>SaxSource</tt>/<tt>SaxResult</tt> should be used by the validator.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useSharedSchema</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Whether the <tt>Schema</tt>
instance should be shared or not. This option is introduced to work around a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6773084"
rel="nofollow">JDK 1.6.x bug</a>. Xerces should not have this issue. </td>
</tr>
</tbody></table>

<h3><a name="Validation-Example"></a>Example</h3>

<p>The following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/validator/camelContext.xml"
rel="nofollow">example</a> shows how to configure a route from endpoint <b>direct:start</b>
which then goes to one of two endpoints, either <b>mock:valid</b> or <b>mock:invalid</b>
based on whether or not the XML matches the given schema (which is supplied on the classpath).</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span
class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;doTry&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"validator:org/apache/camel/component/validator/schema.xsd"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:valid"</span>/&gt;</span>
            <span class="code-tag">&lt;doCatch&gt;</span>
                <span class="code-tag">&lt;exception&gt;</span>org.apache.camel.ValidationException<span
class="code-tag">&lt;/exception&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:invalid"</span>/&gt;</span>
            <span class="code-tag">&lt;/doCatch&gt;</span>
            <span class="code-tag">&lt;doFinally&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:finally"</span>/&gt;</span>
            <span class="code-tag">&lt;/doFinally&gt;</span>
        <span class="code-tag">&lt;/doTry&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="Validation-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

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

Mime
View raw message