camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Console Example
Date Tue, 10 Apr 2012 06:50: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/Console+Example">Console
Example</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>And then open the org.apache.camel.example.console.CamelConsoleMain
class, and right click: Run As -&gt; Java Application. <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO:
screenshot <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip}
<br>Click on the screenshot below, to make it bigger. <br>{tip} <br>!run-as.png|thumbnail!
<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="ConsoleExample-ConsoleExample"></a>Console Example</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>This example is located in the <a href="/confluence/display/CAMEL/Download" title="Download">Camel
distribution</a> at <tt>examples/camel-example-console</tt>.</p>

<p>This is a beginner example that demonstrates how to get started with Apache Camel.</p>

<p>In this example we integrate with the console using the <a href="/confluence/display/CAMEL/Stream"
title="Stream">Stream</a> component. The example is an interactive example that reads
input from the console, and then transforms the input to upper case and print it back on the
console. </p>

<p>This is implemented in a Camel route, in a Spring XML file as shown below.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!--
camelContext is the Camel runtime, where we can host Camel routes --&gt;</span></span>
<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"><span class="code-comment">&lt;!-- read input from
the console using the stream component --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"stream:in?promptMessage=Enter
something: "</span>/&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- transform the
input to upper case using the simple language --&gt;</span></span>
    <span class="code-tag"><span class="code-comment">&lt;!-- you can also
use other languages such as groovy, ognl, mvel, javascript etc. --&gt;</span></span>
    <span class="code-tag">&lt;transform&gt;</span>
      <span class="code-tag">&lt;simple&gt;</span>${body.toUpperCase()}<span
class="code-tag">&lt;/simple&gt;</span>
    <span class="code-tag">&lt;/transform&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- and then print
to the console --&gt;</span></span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"stream:out"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>This example can be run from the command line using Maven with the following command:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn compile exec:java
</pre>
</div></div>

<p>In the console you can enter a message and press ENTER. And then Camel responds with
the message in upper case, as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
[onsole.CamelConsoleMain.main()] SpringCamelContext             INFO  Apache Camel 2.10 (CamelContext:
camel-1) started in 0.455 seconds
Enter something: camel rocks
CAMEL ROCKS
Enter something: and we have fun
AND WE HAVE FUN
Enter something: 
</pre>
</div></div>

<p>To stop the example hit ctrl + c</p>

<p>You can also run this example from your editor. For example from Eclipse you can
import this project using: File -&gt; Import ... -&gt; Existing Maven Project -&gt;
select the pom.xml from the examples\camel-example-console directory.</p>

<p>And then open the org.apache.camel.example.console.CamelConsoleMain class, and right
click: Run As -&gt; Java Application.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>Click on the screenshot below,
to make it bigger.</td></tr></table></div>
<p><span class="image-wrap" style=""><a class="confluence-thumbnail-link 1151x739"
href='https://cwiki.apache.org/confluence/download/attachments/27843710/run-as.png'><img
src="/confluence/download/thumbnails/27843710/run-as.png" style="border: 0px solid black"
/></a></span></p>


<h3><a name="ConsoleExample-Seealso"></a>See also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Stream" title="Stream">Stream</a></li>
	<li><a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a></li>
	<li><a href="/confluence/display/CAMEL/Tutorials" title="Tutorials">Tutorials</a></li>
	<li><a href="/confluence/display/CAMEL/User+Guide" title="User Guide">User Guide</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/Console+Example">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27843710&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Console+Example?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message