<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jonas Partner</title>
	<atom:link href="http://www.jonaspartner.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.jonaspartner.com</link>
	<description></description>
	<lastBuildDate>Wed, 24 Feb 2010 17:23:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring Integration: Whats going on in there? Part 1 Esper wire tap</title>
		<link>http://www.jonaspartner.com/?p=335</link>
		<comments>http://www.jonaspartner.com/?p=335#comments</comments>
		<pubDate>Wed, 24 Feb 2010 16:27:08 +0000</pubDate>
		<dc:creator>Jonas</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Spring Integration]]></category>
		<category><![CDATA[CEP]]></category>
		<category><![CDATA[EAI]]></category>
		<category><![CDATA[OpenCredo]]></category>

		<guid isPermaLink="false">http://www.jonaspartner.com/?p=335</guid>
		<description><![CDATA[Earlier this week Russ Miles announced  the release of the OpenCredo Esper extension project (read it here).  This project is something we created primarily to make using Esper, the open source Complex Event Processing framework, in conjunction with Spring Integration really easy.  At OpenCredo we have been using Esper to help solve the problem [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week Russ Miles announced  the release of the <a href="http://www.opencredo.com/technologies/opencredo-esper" target="_blank">OpenCredo Esper extension project</a> (<a href="http://www.russmiles.com/home/2010/2/21/opencredo-esper-is-go.html" target="_blank">read it here</a>).  This project is something we created primarily to make using <a title="Esper" href="http://esper.codehaus.org/" target="_blank">Esper</a>, the open source Complex Event Processing framework, in conjunction with Spring Integration really easy.  At OpenCredo we have been using Esper to help solve the problem of comprehending and monitoring the state of messaging applications for a while now.  Understanding the state of an application is one of the issues we repeatedly see with clients looking to adopt an Event Driven Architecture based on Spring Integration.  Esper allows us to create views of the data as it passes through our asynchronous event based application which helps to eliminate some of the complexity created by breaking our application into a series of loosely coupled components.</p>
<p>In the first post on this topic I will be walking you through a simple example that takes an existing Spring Integration application and shows how to use the Esper wire tap to send messages passing over a Spring Integration channel into Esper. <br />
<span id="more-335"></span><br />
In the next post in the series I will show how you can hook Spring Integration into Esper to have events trigger the creation of Spring Integration messages.</p>
<h2>Sample Application</h2>
<p>Our sample application consists of a Spring Integration message pipeline that is connected to a HR system.  Whenever the HR process successfully hires a new employee at our fictitious company the HR system creates a notification message that allows other systems to take appropriate actions to deal with the new hire.</p>
<p>To hide the fact that we are using Spring Integration from the HR system we use a Spring Integration gateway which is injected into the HR system.  The SI gateway creates a proxy implementation of the configured interface, shown below, which is then injected into HR System.</p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> EmployeeConfirmationNotifier <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> employementConfirmed<span style="color: #009900;">&#40;</span>EmployeeConfirmation confirmation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>For testing purposes we expose the HR system as a JMX bean with the two methods we use to instruct HR to hire new developers or lawyers exposed as managed operations.</p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">@ManagedResource<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HrSystem <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> AtomicLong employeeNumber <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AtomicLong<span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> EmployeeConfirmationNotifier confirmationNotifier<span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> HrSystem<span style="color: #009900;">&#40;</span>EmployeeConfirmationNotifier confirmationNotifier<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">confirmationNotifier</span> <span style="color: #339933;">=</span> confirmationNotifier<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @ManagedOperation<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addMoreLawyers<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> 0 <span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> count <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//do some hiring</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">confirmationNotifier</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<span style="color: #006633;">employementConfirmed</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> EmployeeConfirmation<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">employeeNumber</span>.<span style="color: #006633;">getAndIncrement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Lawyer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
@ManagedOperation<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addMoreDevelopers<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> 0 <span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> count <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//do some hiring</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">confirmationNotifier</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<span style="color: #006633;">employementConfirmed</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> EmployeeConfirmation<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">employeeNumber</span>.<span style="color: #006633;">getAndIncrement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Developer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Then simply add the MBean export to the configuration file.</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:mbean-export</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<h2>Adding in the wire tap</h2>
<p>The OpenCredo Esper Extension project provides a namespace for configuring the wire tap. All that is required is to use the wire-tap element from the si-esper namespace.  An example of the esper wire tap is shown below:</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;si-esper:wire-tap</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;defaultWireTap&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">template-ref</span>=<span style="color: #ff0000;">&quot;defaultEsperTemplate&quot;</span> <span style="color: #000066;">sourceId</span>=<span style="color: #ff0000;">&quot;hrSystem&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">post-send</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">send-context</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;si-esper:wire-tap-channels</span> <span style="color: #000066;">default-wire-tap</span>=<span style="color: #ff0000;">&quot;defaultWireTap&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;si-esper:channel</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;confirmedEmployeesChannel&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/si-esper:wire-tap-channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;esper:template</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;defaultEsperTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;esper:statements</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/esper:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Here we have configured a wire tap to publish an event to Esper each time a message is sent to the <strong>confirmedEmployeesChannel</strong> channel.  By setting <strong>send-context</strong> to false the published event will simply be the payload of the Spring Integration message, in this case an instance of <strong>EmployeeConfirmation</strong>.  If <strong>send-context</strong> is set to true, the default, then additional context such as the channel and the sourceId will be included in the event published to Esper. </p>
<p>That&#8217;s all that is required to make the data passing available through Spring Integration channels available to Esper.  </p>
<h2>Next time</h2>
<p>In the next post I will show how to then use Esper to query that flow of data allowing us to better understand what is happening at runtime and to alert us to interesting conditions in our application.  The next post will also include the runnable source code for the example.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonaspartner.com/?feed=rss2&amp;p=335</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quiet but not forgotten</title>
		<link>http://www.jonaspartner.com/?p=312</link>
		<comments>http://www.jonaspartner.com/?p=312#comments</comments>
		<pubDate>Sun, 25 Oct 2009 13:36:16 +0000</pubDate>
		<dc:creator>Jonas</dc:creator>
				<category><![CDATA[Spring Integration]]></category>
		<category><![CDATA[EAI]]></category>
		<category><![CDATA[EIP]]></category>
		<category><![CDATA[OpenCredo]]></category>

		<guid isPermaLink="false">http://www.jonaspartner.com/?p=312</guid>
		<description><![CDATA[
Little time to blog lately but hopefully I will be getting some more time as of mid November.  Having started OpenCredo in conjunction with Russ Miles and Gary Levy  earlier in the year we have seen fantastic growth in our first six months.  Thankfully things are now starting to settle down after the initial crazy [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-318 alignleft" title="fisher_cover150" src="http://www.jonaspartner.com/wp-content/uploads/2009/10/fisher_cover150.jpg" alt="Spring Integration in Action" width="150" height="187" /></p>
<p>Little time to blog lately but hopefully I will be getting some more time as of mid November.  Having started <a href="http://www.opencredo.com/" target="_blank">OpenCredo</a> in conjunction with <a href="http://www.russmiles.com/" target="_blank">Russ Miles</a> and Gary Levy  earlier in the year we have seen fantastic growth in our first six months.  Thankfully things are now starting to settle down after the initial crazy days.  Over the next few months we are expecting to find time to deliver some interesting open source projects which combine some of our main company interests of integration, messaging and cloud computing.  Watch this space.</p>
<p>In addition I have been working on the upcoming Spring Integration in Action with the other Spring Integration committers.  A first view of the book is now available through the Manning early access program <a href="http://www.manning.com/fisher/" target="_blank">here</a>.  Feedback through the Manning forum would be much appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonaspartner.com/?feed=rss2&amp;p=312</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with Maven and SpringSource dm Server</title>
		<link>http://www.jonaspartner.com/?p=185</link>
		<comments>http://www.jonaspartner.com/?p=185#comments</comments>
		<pubDate>Sun, 08 Mar 2009 22:07:16 +0000</pubDate>
		<dc:creator>Jonas</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[SpringSource dm Server]]></category>

		<guid isPermaLink="false">http://www.jonaspartner.com/?p=185</guid>
		<description><![CDATA[
Since I am a big Maven fan one of the things that pained me when starting to work with the dm Server was that the tooling for managing project dependencies was all based around Eclipse.  The STS 2.0 RC discussed by Christian Dupuis here now has support for a separate test classpath using a proprietary [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">
Since I am a big Maven fan one of the things that pained me when starting to work with the dm Server was that the tooling for managing project dependencies was all based around Eclipse.  The STS 2.0 RC discussed by Christian Dupuis <a href="http://blog.springsource.com/2009/03/05/osgi-development-tools-in-sts/">here</a> now has support for a separate test classpath using a proprietary TEST.MF.  To me this still poses a problem when you start thinking about Continous Integration testing.  Currently there is going to be duplication and you will need to keep the classpath understood by your build system and your IDE in synch manually.  It is however surprisingly easy to setup Maven and dm Server to play nice, so before posting the code for my recent Spring Integration with dm Server demo from the UK Spring User Group I thought I would walk through setting up dm Server with Maven.
</p>
<p style="text-align: left;">
The first thing you need to decide is where you are going to have your shared repository which will be populated by Maven and used by dm Server to resolve dependencies.  You can configure dm Server to use the default Maven repository under your home directory, however for reasons of clarity I prefer to maintain  a separate repository.  So, assuming you have <a href="http://www.springsource.com/products/suite/dmserver">downloaded</a> dm Server and unzipped it, the first thing you will need to do is modify the provisioning configuration in <em>DM_SERVER/config/server.config.</em> By default there is no section for provisioning here with convention being used, so after the osgiConsole section define a section as below.
</p>
<div class="codecolorer-container javascript geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3366CC;">&quot;osgiConsole&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;enabled&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;port&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">2401</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
<span style="color: #3366CC;">&quot;provisioning&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;searchPaths&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;repository/bundles/subsystems/{name}/{bundle}.jar&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;repository/bundles/ext/{bundle}&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;${user.home}/servers/dm-server-maven-repo/**/{bundle}.jar&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;repository/libraries/ext/{library}&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;repository/libraries/usr/{library}&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p style="text-align: left;">
To test this we will create a simple project which uses Apache Commons lang StrSubstitor class to print the simple message given as an example in the Javadoc for commons lang  <strong>&#8220;You are running with java.version = ${java.version} and os.name = ${os.name}.&#8221;)</strong></p>
<p>To create the sample Maven project we can use the Maven archetype plugin so go to the command prompt in the directory where you want to create the test project.</p>
<ol>
<li><strong>At the command prompt &#8220;mvn archetype:generate&#8221; </strong></li>
<li><strong>Then select the number relating to maven-archetype-quickstart , 15 by default but may vary according to your setup</strong></li>
<li><strong>Enter a groupId &#8220;org.jpartner&#8221; in my case</strong></li>
<li><strong>Enter an artifactId &#8220;mavenDmHello&#8221;</strong></li>
<li><strong>Hit enter to accept the default version &#8220;1.0-SNAPSHOT&#8221;</strong></li>
<li><strong>For package I used the same value as groupId so &#8220;org.jpartner&#8221; in my case</strong></li>
</ol>
<p style="text-align: left;">
Ok, so now we need to open up the pom.xml that has been created for use by the archetype plugin, so change directory to mavenDmHello and open pom.xml in your preferred text editor.  After the URL element and before the dependency element add in the below xml fragment to allow Maven to resolve dependencies from the SpringSource Enterprise Bundle Repository, which you can browse here <a href="http://www.springsource.com/repository">http://www.springsource.com/repository</a>.
</p>
<p><span id="more-185"></span></p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.springsource.repository.bundles.release<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SpringSource Bundle Releases<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://repository.springsource.com/maven/bundles/release<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.springsource.repository.bundles.external<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SpringSource External Bundle Releases<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://repository.springsource.com/maven/bundles/external<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
To declare the dependency on Apache Commons Lang we are adding the version from the SpringSource repository to ensure we get an OSGi compatible jar, hence the non-standard artifactId.
</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.commons<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.springsource.org.apache.commons.lang<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.4.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
In order to tell Maven to use the non-standard local repository location we could configure the location in our global settings.xml.  However, since this will effect all our maven projects, for the moment we will set up a separate settings.xml file.  In the root of the created project create a file called settings.xml with the content below.
</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;settings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;localRepository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${user.home}/servers/dm-server-maven-repo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/localRepository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/settings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
To tell Maven about our new settings.xml we pass the -s so running <strong>mvn -s./settings.xml install</strong> will download our dependency on Commons Lang into our new repository.  Maven will of course download a whole host of other things as well.
</p>
<p style="text-align: left;">
Next we will create a class in our project which makes use of StrSubstitor to make sure everything is working as expected.  So create a greeter class as below.
</p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.jpartner</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.lang.text.StrSubstitutor</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Greeter<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> Greeter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> replaced <span style="color: #339933;">=</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrSubstitutor.<span style="color: #006633;">replaceSystemProperties</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;You are running with java.version&quot;</span> <span style="color: #339933;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; = ${java.version} and os.name = ${os.name}.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>replaced<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p style="text-align: left;">
We can then use the standard mechanism to have an instance of our Greeter class created at runtime. So under <strong>src/main/resources</strong> create a directory structure <strong>META-INF/spring</strong> and inside the spring directory create a file called greeter.xml as below.
</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; <span style="color: #000066;">xsi:schemaLocation</span>=</span><br />
<span style="color: #009900;"> &nbsp; <span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans </span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp;http://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;greeter&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpartner.Greeter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
The next thing we need to do is provide an OSGi compatible manifest importing the <strong>org.apache.commons.lang.text.StrSubstitutor</strong>.  Because Maven will auto generate a manifest we also need to configure the maven-jar-plugin to use our provided manifest.  We do this by adding the build section as below to our pom.xml.
</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-jar-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifestFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;${basedir}/src/main/resources/META-INF/MANIFEST.MF<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifestFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Then create the <strong>MANIFEST.MF</strong> in the <strong>META-INF</strong> directory as below.  We declare our import of the commons lang package containing the <strong>StrSubstitutor</strong></p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Manifest-Version: 1.0<br />
Bundle-Name: Service_interfaces Bundle<br />
Bundle-ManifestVersion: 2<br />
Bundle-SymbolicName: mavenDmHello<br />
Bundle-Version: 1.0.0<br />
Import-Package: org.apache.commons.lang.text;version=&quot;[2.4.0,3.0.0)&quot;</div></div>
<p style="text-align: left;">Now start up the dm Server using the script under <strong>DM_SERVER/bin</strong>.  Run <strong>mvn install</strong> again to create a jar containing our new manifest.  Then simply copy the jar created in the maven target directory to the <strong>DM_SERVER/pickup</strong>.  You should see dm Server output as below.
</p>
<p><strong><br />
[2009-03-08 20:39:22.735] fs-watcher               <SPDE0048I> Processing &#8216;INITIAL&#8217; event for file &#8216;mavenDmHello-1.0-SNAPSHOT.jar&#8217;.<br />
[2009-03-08 20:39:23.504] fs-watcher               <SPDE0010I> Deployment of &#8216;mavenDmHello&#8217; version &#8216;1&#8242; completed.<br />
</strong></p>
<p>
A tail of the serviceability log <strong>DM_SERVER//serviceability/trace/mavenDmHello-1/trace.log</strong>  will show something similar to below, showing that we are successfully using Maven to populate the repository for use with dm Server.
</p>
<p><strong><br />
[2009-03-08 20:39:23.482] server-dm-4              amework.beans.factory.support.DefaultListableBeanFactory.unknown I Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@65d0e7e9: defining beans [greeter]; root of factory hierarchy<br />
[2009-03-08 20:39:23.493] server-dm-4                                                                    System.out I You are running with java.version = 1.6.0_07 and os.name = Mac OS X.<br />
</strong></p>
<p style="text-align: left;">
So now we have dependencies working with Maven however we are still creating the manifest by hand.  The SpringSource Maven bundlor plugin can be used to help with that and I will be posting an example using that soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonaspartner.com/?feed=rss2&amp;p=185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demo One from my UK Spring User Group talk: The simplicity of Spring Integration</title>
		<link>http://www.jonaspartner.com/?p=28</link>
		<comments>http://www.jonaspartner.com/?p=28#comments</comments>
		<pubDate>Sun, 22 Feb 2009 18:06:57 +0000</pubDate>
		<dc:creator>Jonas</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Spring Integration]]></category>
		<category><![CDATA[EAI]]></category>
		<category><![CDATA[EIP]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.jonaspartner.com/?p=28</guid>
		<description><![CDATA[I was asked to make the code available for the demos that were part of my talk for the UK Spring User Group at Skills Matter.  The video of which is here.  Today I am posting the code for the first demo which demonstrates just how easy it is to get up and running [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">I was asked to make the code available for the demos that were part of my talk for the UK Spring User Group at Skills Matter.  The video of which is <a href="http://skillsmatter.com/podcast/java-jee/spring-integration">here</a>.  Today I am posting the code for the first demo which demonstrates just how easy it is to get up and running with Spring Integration.  The demo shows a simple  application which takes requests from JMS, routes according to business logic and calls through to a Java service to process the message.  The projects used in this demo can be downloaded here <a href="drops/febSugDemo1.zip">febSugDemo1.zip</a>.  The zip contains three Eclipse projects along with Maven poms so Eclipse is not a must.  </p>
<ol>
<li>Application Generator: This project is there for testing and when run will create random <em>LoanApplication</em> instances and send them for processing over JMS.  This can be started using <em>LoanApplicationGenerator</em> in <em>src/main/java</em></li>
<li>Demo 1 Quotes:  Contains the Spring Integration configuration and simple service implementations used to process applications.  Can  be started from <em>LoanQuoteStarter</em> under <em>src/test/java</em></li>
<li>Loan Quote Domain: The LoanApplication and Quote types used by both previous proejcts</li>
</ol>
<p style="text-align: left;">The example is that of a simple message flow which first receives a LoanApplication from a JMS queue.  The loan application is then routed based on simple business rules to either a quote generating service or to a rejection queue for processing later.  I will start off with a detailed walk through of the example application so if you just want to get the code up and running you can skip through to the getting it running section towards the bottom.</p>
<p style="text-align: left;">
<p><strong>Loan application message flow</strong></p>
<p style="text-align: left;"><a href="http://www.jonaspartner.com/wp-content/uploads/2009/02/loanquoteflow.jpg"><img class="alignnone size-full wp-image-36" title="loanquoteflow" src="http://www.jonaspartner.com/wp-content/uploads/2009/02/loanquoteflow.jpg" alt="loanquoteflow" width="600" height="226" /></a></p>
<p style="text-align: left;"><span id="more-28"></span></p>
<h2>Walk through</h2>
<p style="text-align: left;">The configuration for the demo1 project can be found under <em>src/main/resources</em>.  The <em>loanquote-context.xml</em> first defines an inbound JMS channel adapter.  The fact that we are using a JMS channel adapter rather than a JMS gateway indicates that we are doing one way communication.  If we were participating in a request response scenario we would want to use one of the provided gateways instead.  The inbound adapter means we are receiving from JMS and placing an instance of  <em>org.springframework.integration.core.Message</em> on the configured channel.  Spring Integration also provides an outbound gateway to take a Spring Integration message from a Spring Integration channel and send that to a JMS destination.  JMS gateways also come in both inbound and outbound versions.</p>
<p style="text-align: left;">
<p><strong>JMS Inbound channel adapter</strong></p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jms:inbound-channel-adapter</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">connection-factory</span>=<span style="color: #ff0000;">&quot;connectionFactory&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">destination-name</span>=<span style="color: #ff0000;">&quot;newApplications&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;requests&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jms:inbound-channel-adapter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;requests&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p style="text-align: left;">
The JMS inbound adapter is configured very simply in this case with a reference to a JMS connection factory, the name of a JMS destination and the name of the Spring Integration channel on which received messages will be placed.  Our connection factory is  a Spring bean defined elsewhere.  In this case we are using the ActiveMQ configuration below.
</p>
<p><strong>ActiveMQ connection factory</strong></p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;connectionFactory&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.spring.ActiveMQConnectionFactory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brokerURL&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;tcp://localhost:61616&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
The next step in our flow is to route according to the credit rating which is already available in the <em>LoanApplication</em>.  To do that we use a simple router implementation as below.  Note that rather than accepting an instance of <em>org.springframework.integration.core.Message</em> the router accepts an instance of <em>LoanApplication</em> which is the payload of the message.  This makes the router easier to unit test by decoupling it from messaging.  The router in this case is simply returning a <em>String</em> channel name which will then be resolved to a channel instance by the framework.  The default strategy, which will be used here, is to look for a Spring bean in the application context with an id matching the String returned by the router.  This strategy is as with most things in Spring Integration pluggable if required.
</p>
<p><strong>Credit Checking Router</strong></p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CreditCheckingRouter <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> route<span style="color: #009900;">&#40;</span>LoanApplication loanApplication<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>loanApplication.<span style="color: #006633;">getApplicant</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">creditBetterThan</span><span style="color: #009900;">&#40;</span>CreditRating.<span style="color: #006633;">AVERAGE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;quote&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;reject&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></div>
<p style="text-align: left;">
In order to connect the router into our integration application we simply declare the POJO router as a Spring bean and reference this from our router element.  Our router element requires a reference to the channel from which messages will be received, a reference to the POJO router bean and the name of the method to invoke when a message is received.  We also need to declare the two channels which our router will route to.  Here the quote channel will be of the default DirectChannel type.  This means that a call to send on this channel will dispatch the message to any consumer(s).  In the case of rejected applications we are going to queue those up and process them later so we declare a queue element as a child of channel.  This means that the <em>reject</em> channel will be an instance of QueueChannel and calls to send will not result in any message dispatch.  The consumer responsible for processing rejections will need to come looking for our rejected loan applications by polling the queue.
</p>
<p><strong>Router configuration</strong></p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;creditCheckRouter&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpartner.CreditCheckingRouter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;router</span> <span style="color: #000066;">input-channel</span>=<span style="color: #ff0000;">&quot;requests&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;creditCheckRouter&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;route&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;quote&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;reject&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;queue</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p style="text-align: left;">
Our quote service is very simple in this case.  If you have the good or great credit rating to get past our router then we are simply going to quote our standard fixed rate of 20% APR, sign of the times I&#8217;m afraid.  Our service activator is again very testable and decoupled from the messaging framework, the LoanApplication is the payload of the message received from the input channel and the returned Quote becomes the payload of the message sent to our output channel.
</p>
<p><strong>Quote Service</strong></p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> QuoteService <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Quote createQuote<span style="color: #009900;">&#40;</span>LoanApplication loanApplication<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Quote<span style="color: #009900;">&#40;</span>20,loanApplication<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p style="text-align: left;">
Hooking our quote service in is then just a case of declaring a service activator with a ref to the bean, the input and output channels.  For the purposes of the demo we are then simply printing our quotes to standard out using a provided stream channel adapter.
</p>
<p><strong>Loan Quote Service Activator</strong></p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;quoteService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jpartner.QuoteService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service-activator</span> <span style="color: #000066;">input-channel</span>=<span style="color: #ff0000;">&quot;quote&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">output-channel</span>=<span style="color: #ff0000;">&quot;createdQuotes&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;quoteService&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;createQuote&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;createdQuotes&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stream:stdout-channel-adapter</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;stdout&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;createdQuotes&quot;</span> <span style="color: #000066;">append-newline</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<h2>IDE Setup</h2>
<p style="text-align: left;">
Since the projects are using Maven, if you don&#8217;t have a Maven plugin already installed in Eclipse I would recommend installing Q4E from <a href="http://code.google.com/p/q4e/">here</a>.<br />
You can then import the projects from the zip using <strong>File-> Import -> General -> Import existing projects into workspace</strong> and navigate to the archive.
</p>
<h2>Running it</h2>
<p style="text-align: left;">
We sometimes get questions on the Spring Integration forum about starting up and deploying a Spring Integration application.  The short answer is that all you need is a JRE, since Spring Integration is designed to be lightweight and it does not require an application server to run.  In the case of the demo the application is started using a main method.  In this case however since we are using JMS you will need a broker.  I used ActiveMQ 5.2 which you can download <a href="http://activemq.apache.org/download.html">here</a>.  Simply unzip it and run  <strong>activemq-admin start </strong> from the bin directory.  You should then be able to browse to http://localhost:8161/admin/queueGraph.jsp and see a number of example destinations.  Start the <em>LoanApplicationGenerator</em> by running the main method.  So <strong>Run As-> Java Application</strong> if you are using Eclipse.  Refreshing the ActiveMQ console should now show you that we have a build up of loan applications on our newApplication JMS queue.  To start our loan quote application simply run the <em>LoanQuoteStarter</em> class in the demo project, the code of which is shown below.  This creates our Spring application context and since our beans are lifecycle aware the application will immediately start processing loan applications.
</p>
<p><strong>Startup class for loan processing application</strong></p>
<div class="codecolorer-container java geshi" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoanQuoteStarter <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> ClassPathXmlApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;loanquote-context.xml&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LoanQuoteStarter.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>You should now see console output as below.</p>
<blockquote><p>
Applicant name:Sue rating: GOOD amount:79053.0 years:8 quoted rate : 20.0<br />
Applicant name:Greg rating: GOOD amount:47561.0 years:1 quoted rate : 20.0<br />
Applicant name:Simon rating: GREAT amount:41472.0 years:7 quoted rate : 20.0<br />
Applicant name:John rating: GOOD amount:19438.0 years:1 quoted rate : 20.0<br />
Applicant name:Emma rating: GREAT amount:66612.0 years:3 quoted rate : 20.0<br />
Applicant name:Bob rating: GOOD amount:80851.0 years:0 quoted rate : 20.0<br />
Applicant name:Greg rating: GOOD amount:19175.0 years:9 quoted rate : 20.0<br />
Applicant name:John rating: GOOD amount:18578.0 years:2 quoted rate : 20.0<br />
Applicant name:Simon rating: GOOD amount:64692.0 years:4 quoted rate : 20.0
</p></blockquote>
<p>The next post will be based on demo number two from my talk which will show how we can break up an application such as the example loan quote application into OSGi bundles, and in doing so we will create a more modular, testable and flexible application. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonaspartner.com/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Welcome to my new online home</title>
		<link>http://www.jonaspartner.com/?p=12</link>
		<comments>http://www.jonaspartner.com/?p=12#comments</comments>
		<pubDate>Sat, 21 Feb 2009 04:00:07 +0000</pubDate>
		<dc:creator>Jonas</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jonaspartner.com/?p=12</guid>
		<description><![CDATA[Welcome to my new online home.  I am currently in the process of establishing a new company with a number of like minded individuals but until we have the new site up and running I have decided to resurrect www.jonaspartner.com.  The new company will be offering consultancy and development services primarily around Open [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to my new online home.  I am currently in the process of establishing a new company with a number of like minded individuals but until we have the new site up and running I have decided to resurrect www.jonaspartner.com.  The new company will be offering consultancy and development services primarily around Open Source whilst at the same time expending a lot of our time contributing to Open Source projects which we think are exciting.   We will be looking to pioneer some new ways of collaborating with clients to drastically reduce the risks, both technical and financial, associated with many IT projects.   We see this as the key to persuading people that technology projects can be a good investment in the current times.  More on that soon.</p>
<p>Over the next few months I will also be putting out a number of blogs on topics I have been meaning to write something on for some time.  Most of these will probably relate to Spring Integration since that is definitely what I am most excited about right now although the ability of Grails to make web development with Java exciting and fast paced is also up there for me.</p>
<p>Certainly the first few blogs will be follow-ups to the well received London Spring User Group talk on Spring Integration I delivered  on the 12th of February at Skills Matter.  The video of that talk can be found on the Skills Matter website <a href="http://skillsmatter.com/podcast/java-jee/spring-integration">here</a>.  Thanks to Skills Matter for hosting yet another great community event and to Cake Solutions for providing the organisation and the generous post-talk beer for everyone at the Crown.  In the next few days I will be putting up the code from the samples in that talk along with a walk through of the unsuccessful Spring Integration with OSGi demo running on the SpringSource dm Server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonaspartner.com/?feed=rss2&amp;p=12</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
