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 Fri, 07 Sep 2012 19:49:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/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/Validation">Validation</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~muellerc">Christian
Mueller</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >|| Option || Default || Description
|| <br>| {{resourceResolver}} | {{null}} | *Camel 2.9:* Reference to a {{org.w3c.dom.ls.LSResourceResolver}}
in the [Registry]. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{useDom}} | {{false}} | <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">*Camel
2.0:*</span> Whether {{DOMSource}}/{{DOMResult}} or {{SaxSource}}/{{SaxResult}} should
be used by the validator. | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{useSharedSchema}} | {{true}} |
*Camel 2.3:* Whether the {{Schema}} instance should be shared or not. This option is introduced
to work around a [JDK 1.6.x bug|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6773084].
Xerces should not have this issue. | <br>{div} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <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" class="external-link" 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" class="external-link"
rel="nofollow">RelaxNG Compact Syntax</a></li>
	<li><a href="http://relaxng.org/" class="external-link" 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/" class="external-link" 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" class="external-link" rel="nofollow">file:../foo/bar.xsd</a></tt></li>
	<li><tt>msv:<a href="http://acme.com/cheese.xsd" class="external-link" rel="nofollow">http://acme.com/cheese.xsd</a></tt></li>
	<li><tt>validator:com/mypackage/myschema.xsd</tt></li>
</ul>


<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component when using <b>Camel 2.8</b> or older:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-spring<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>From Camel 2.9 onwards the <a href="/confluence/display/CAMEL/Validation" title="Validation">Validation</a>
component is provided directly in the camel-core.</p>

<h3><a name="Validation-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<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>resourceResolver</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Reference to a <tt>org.w3c.dom.ls.LSResourceResolver</tt>
in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>useDom</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> 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"
class="external-link" rel="nofollow">JDK 1.6.x bug</a>. Xerces should not have this
issue. </td>
</tr>
</tbody></table>
</div>
</div>

<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"
class="external-link" 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="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Validation">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=63294&revisedVersion=12&originalVersion=11">View
Changes</a>
                |
        <a href="https://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