camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Tutorial-Example-ReportIncident-Part6
Date Sun, 27 Jan 2013 11:14: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/Tutorial-Example-ReportIncident-Part6">Tutorial-Example-ReportIncident-Part6</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</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" > <br>The XML code below is included
in the example in {{camel-example-report-incident}} in the directory {{src/main/resources/META-INF/spring/}}.
The file is named {{camel-context.xml}} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{snippet:id=e1|lang=xml|title=camel-config.xml|url=camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml}
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO:
link to source code with xml example <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. After 5 years we are at the end
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Tutorial-Example-ReportIncident-Part6-Part6"></a>Part
6</h2>

<h3><a name="Tutorial-Example-ReportIncident-Part6-...ContinuedfromPart5"></a>...
Continued from Part 5</h3>
<p>We continue from part 5 where we ended up with a complete solution using routes defined
in Java code. In this last part of this tutorial we will define the route in XML instead.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Sidebar</b><br
/>As I am writing this, its been 4.5 years since I wrote the first 5 parts of this tutorial.
Recently an user on stackoverflow praised this tutorial said it helped him get onboard Camel.
Though he was looking for part 6 with the routes in XML. Frankly I have forgot all about adding
this part. So lets close the book and get this part into the Camel docs.</td></tr></table></div>

<p>The XML code below is included in the example in <tt>camel-example-report-incident</tt>
in the directory <tt>src/main/resources/META-INF/spring/</tt>. The file is named
<tt>camel-context.xml</tt></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>camel-config.xml</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag"><span class="code-comment">&lt;!-- here we have Spring
XML file with all the namespaces here in the top of the XML file --&gt;</span></span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel</span>=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>
       <span class="code-keyword">xmlns:cxf</span>=<span class="code-quote">"http://camel.apache.org/schema/cxf"</span>
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
         http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd"&gt;

  <span class="code-tag"><span class="code-comment">&lt;!-- this is Spring
XML example of the Camel route in the ReportIncidentRoutes class --&gt;</span></span>
  <span class="code-tag"><span class="code-comment">&lt;!-- this is for demonstration
purpose, to show how you can use Camel with XML DSL --&gt;</span></span>

   &lt;!-- here we define the CXF endpoint, where {{port}} refers to a placeholder so
we can define the port number
           in an external .properties file --&gt;
  &lt;cxf:cxfEndpoint id=<span class="code-quote">"reportIncident"</span>
                   address=<span class="code-quote">"http://localhost:{{port}}/camel-example-reportincident/webservices/incident"</span>
                   wsdlURL=<span class="code-quote">"etc/report_incident.wsdl"</span>
                   serviceClass=<span class="code-quote">"org.apache.camel.example.reportincident.ReportIncidentEndpoint"</span>/&gt;

   <span class="code-tag"><span class="code-comment">&lt;!-- We use a bean
to make the response bean that CXF expects --&gt;</span></span>
  <span class="code-tag">&lt;bean id=<span class="code-quote">"responseBean"</span>
class=<span class="code-quote">"org.apache.camel.example.reportincident.MyBean"</span>/&gt;</span>

   <span class="code-tag"><span class="code-comment">&lt;!-- this is the bean
we use to generate the dynamic file name --&gt;</span></span>
  <span class="code-tag">&lt;bean id=<span class="code-quote">"filenameGenerator"</span>
class=<span class="code-quote">"org.apache.camel.example.reportincident.FilenameGenerator"</span>/&gt;</span>

  &lt;!-- this CamelContext contains the equivalent route from the Java DSL, but in XML
       so end users can see how to implement the route in both Java and XML --&gt;
  <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;!-- property which
contains port number --&gt;</span></span>
    <span class="code-tag"><span class="code-comment">&lt;!-- we have file:target/custom.properties
which can be optional and override existing values, we use this for testing purpose --&gt;</span></span>
    <span class="code-tag">&lt;camel:propertyPlaceholder id=<span class="code-quote">"properties"</span>
location=<span class="code-quote">"classpath:incident.properties,file:target/custom.properties"</span>/&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- this is the
first route that uses CXF as web service --&gt;</span></span>
    <span class="code-tag">&lt;route&gt;</span>
      <span class="code-tag">&lt;from uri=<span class="code-quote">"cxf:bean:reportIncident"</span>/&gt;</span>
      <span class="code-tag">&lt;convertBodyTo type=<span class="code-quote">"org.apache.camel.example.reportincident.InputReportIncident"</span>/&gt;</span>
      <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"CamelFileName"</span>&gt;</span>
        <span class="code-tag">&lt;method bean=<span class="code-quote">"filenameGenerator"</span>
method=<span class="code-quote">"generateFilename"</span>/&gt;</span>
      <span class="code-tag">&lt;/setHeader&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"velocity:etc/MailBody.vm"</span>/&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"file://target/subfolder"</span>/&gt;</span>
      <span class="code-tag">&lt;transform&gt;</span>
        <span class="code-tag">&lt;method bean=<span class="code-quote">"responseBean"</span>
method=<span class="code-quote">"getOK"</span>/&gt;</span>
      <span class="code-tag">&lt;/transform&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- this is the
2nd route that pickup files and send them as emails --&gt;</span></span>
    <span class="code-tag">&lt;route&gt;</span>
      <span class="code-tag">&lt;from uri=<span class="code-quote">"file://target/subfolder"</span>/&gt;</span>
      <span class="code-tag">&lt;setHeader headerName=<span class="code-quote">"subject"</span>&gt;</span>
        <span class="code-tag">&lt;constant&gt;</span>new incident reported<span
class="code-tag">&lt;/constant&gt;</span>
      <span class="code-tag">&lt;/setHeader&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"smtp://someone@localhost?password=secret&amp;amp;to=incident@mycompany.com"</span>/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>

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

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

<h3><a name="Tutorial-Example-ReportIncident-Part6-After5yearsweareattheend"></a>After
5 years we are at the end</h3>

<p>So finally we managed to add part 6 to this tutorial. Yes we have used a lot of time
to write this tutorial, so we hope that it helps you ride the Camel.</p>

<h2><a name="Tutorial-Example-ReportIncident-Part6-Links"></a>Links</h2>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident" title="Tutorial-Example-ReportIncident">Introduction</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part1" title="Tutorial-Example-ReportIncident-Part1">Part
1</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part2" title="Tutorial-Example-ReportIncident-Part2">Part
2</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part3" title="Tutorial-Example-ReportIncident-Part3">Part
3</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part4" title="Tutorial-Example-ReportIncident-Part4">Part
4</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part5" title="Tutorial-Example-ReportIncident-Part5">Part
5</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part6" title="Tutorial-Example-ReportIncident-Part6">Part
6</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/Tutorial-Example-ReportIncident-Part6">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30750840&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Tutorial-Example-ReportIncident-Part6?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message