<?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>redstream &#187; Mule</title>
	<atom:link href="http://www.redstream.nl/tag/mule/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redstream.nl</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 27 Jan 2012 19:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New products from Mulesoft</title>
		<link>http://www.redstream.nl/2011/06/16/new-products-from-mulesoft/</link>
		<comments>http://www.redstream.nl/2011/06/16/new-products-from-mulesoft/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 06:56:33 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[cloud]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Mule3]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Mule]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2738</guid>
		<description><![CDATA[Mulesoft recently released some new products, totally different from each other but both very welcome. The first one is MuleStudio. Mule Studio is an Eclipse-based developer tool, that allows to graphically create and test Mule ESB Flows. It is currently &#8230; <a href="http://www.redstream.nl/2011/06/16/new-products-from-mulesoft/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F06%2F16%2Fnew-products-from-mulesoft%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F06%2F16%2Fnew-products-from-mulesoft%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.mulesoft.com/">Mulesoft</a> recently released some new products, totally different from each other but both very welcome.<br />
The first one is <a href="http://www.mulesoft.org/documentation/display/MULESTUDIO/Home">MuleStudio</a>. Mule Studio is an Eclipse-based developer tool, that allows to graphically create and test Mule ESB Flows. It is currently in beta but I think it might be a good reason to go back to Eclipse. Last few years I have been using Netbeans for my Mule/Java development because I liked the combination between Netbeans and Maven better.</p>
<p>The other &#8216;product&#8217; that is released is <a href="http://www.mulesoft.com/how-does-it-work">Mule iON</a>. I think a graphical development tool is nice to have but this iON thing is something that can really become big. It makes you use the cloud as the platform for your integration software. They call it the iPAAS (Integration Platform as a Service).</p>
<p>The coming days I will have a look at both and posts my findings here so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/06/16/new-products-from-mulesoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Citrus testcase example: CSV File Inbound -&gt; Xml Http Outbound</title>
		<link>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/</link>
		<comments>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 06:51:01 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Citrus]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Spring Integration]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2679</guid>
		<description><![CDATA[As promised I&#8217;m going to show a test case for which I have used Citrus to implement it. The case is like this: In a predefined folder on a machine a character-separated file is placed. This file is picked up &#8230; <a href="http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F04%2F30%2Fcitrus-testcase-example-csv-file-inbound-xml-http-outbound%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F04%2F30%2Fcitrus-testcase-example-csv-file-inbound-xml-http-outbound%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As <a href="http://www.redstream.nl/2011/04/15/setup-citrus-for-testing-mule-esb/">promised</a> I&#8217;m going to show a test case for which I have used <a href="http://www.citrusframework.org/">Citrus</a> to implement it. The case is like this:<br />
In a predefined folder on a machine a character-separated file is placed. This file is picked up by our <a href="http://www.mulesoft.org/what-mule-esb">Mule ESB</a> application. The content is transformed to XML and this XML document is posted to another application over HTTP. This application responds with XML document telling the document was processed correctly.<br />
To test this interface with Citrus we have to perform the following steps:</p>
<ol>
<li>Copy the input test-file to the predefined folder so it is picked up by the test instance of our Mule ESB</li>
<p>Our Mule ESB will poll a directory each second to check if there is placed a new file to process. Our test case starts by having Citrus putting a test file in the directory .</p>
<li>Have Citrus listen on a predefined HTTP port to receive the XML message over HTTP</li>
<p>Inside our Mule ESB the file is transformed to XML message and posted on a HTTP port to be processed by the &#8216;ORDER&#8217; system. We have configured Citrus to listen on this specific HTTP port to pick up the XML message.</p>
<li>Reply to the received message with a predefined XML message</li>
<p>This steps mimics the &#8216;ORDER&#8217; system as it would normally process the incoming XML message and respond with another XML message. In this case Citrus will send back a predefined XML message as response.
</ol>
<p><span id="more-2679"></span><br />
The citrus-config.xml for this test case can be found <a href="http://www.redstream.nl/wp-content/uploads/2011/04/citrus-context.xml">here</a>. I will explain the content of the config file next:</p>

<div class="wp_codebox"><table><tr id="p267910"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p2679code10"><pre class="xml" style="font-family:monospace;"><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;citrusJMSConnectionFactory&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brokerURL&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;vm://localhost:61616&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This part defines a &#8216;in-memory&#8217; JMS provider to be used by Citrus. We will see later how we use it to check the incoming HTTP request (as described <a href="http://www.citrusframework.org/reference/html/index.html#http-message-handler-jms">here</a> in the Citrus reference guide).</p>

<div class="wp_codebox"><table><tr id="p267911"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code11"><pre class="xml" style="font-family:monospace;"><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;namespaceContextBuilder&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.xml.namespace.NamespaceContextBuilder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;namespaceMappings&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;ns1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>http://www.redstream.nl/invoice<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Here we define the namespaces that are used in the xml messages in our test. We will use this namespace in the test to check values of certain XML elements.</p>

<div class="wp_codebox"><table><tr id="p267912"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p2679code12"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;redstreamIntegrationTests&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.TestSuite&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tasksBefore&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.actions.ExecuteSQLAction&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;rsDataSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;statements&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DELETE FROM RS_LOGS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With this part I have Citrus clean up my log table in the database of my Mule ESB. We log all incoming and outgoing messages in our ESB to the database.</p>

<div class="wp_codebox"><table><tr id="p267913"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p2679code13"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- manadatory if XML files are used in a test --&gt;</span>
<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;xmlMessageValidator&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.validation.xml.DomXmlMessageValidator&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <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;schemaRepository&quot;</span></span>
<span style="color: #009900;">           <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.xml.XsdSchemaRepository&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;schemas&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.xml.xsd.SimpleXsdSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xsd&quot;</span></span>
<span style="color: #009900;">                               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;classpath:schemas/rs_invoice_0.3.xsd&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>When you want to work with XML messages in your test (and that is very likely nowadays) you will need to define an &#8216;xmlMessageValidator&#8217;. And to be able to validate the message against an XML schema you will need to define the schemas in the &#8216;schemaRepository&#8217; as I have done here.</p>

<div class="wp_codebox"><table><tr id="p267914"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code14"><pre class="xml" style="font-family:monospace;"><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;rsDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@test-vm:1521:XE&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;user&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;oracle.jdbc.xa.client.OracleXADataSource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;removeAbandoned&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This is the datasource that Citrus can use to access the database that is used by our Mule ESB application. We use this datasource to clean up the logtable and can use it to perform validations after messages have been processed.</p>

<div class="wp_codebox"><table><tr id="p267915"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2679code15"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:message-channel-sender</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;invoiceFileSender&quot;</span> <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file:outbound-channel-adapter</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;invoice-files-out&quot;</span> <span style="color: #000066;">channel</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;file://Volumes/staging/invoice&quot;</span> <span style="color: #000066;">filename-generator</span>=<span style="color: #ff0000;">&quot;test-filename-generator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<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;test-filename-generator&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;nl.redstream.citrus.TestFileNameGenerator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;si:channel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fileOutboundChannel&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>This is a mix of Citrus with spring-integration configuration. With this configuration I am able to send files to my test VM with Citrus. It also shows how easy it is to mix Citrus with spring-integration.</p>

<div class="wp_codebox"><table><tr id="p267916"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2679code16"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- receive Invoice HTTP request --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus-http:server</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderHttpServer&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;8060&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;/services/post-invoice&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">deamon</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">message-handler</span>=<span style="color: #ff0000;">&quot;jmsForwardingMessageHandler&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">auto-start</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>Definition of the HTTP Server in Citrus which listens on port 8060 for a request of our Mule ESB.</p>

<div class="wp_codebox"><table><tr id="p267917"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p2679code17"><pre class="xml" style="font-family:monospace;"> <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;jmsForwardingMessageHandler&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.consol.citrus.adapter.handler.JmsConnectingMessageHandler&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;destinationName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Citrus.order-response&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;replyTimeout&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;6000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Process all received requests --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:jms-sync-message-receiver</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">destination-name</span>=<span style="color: #ff0000;">&quot;Citrus.order-response&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">connection-factory</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;citrus:jms-reply-message-sender</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;orderResponseSender&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">reply-destination-holder</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">connection-factory</span>=<span style="color: #ff0000;">&quot;citrusJMSConnectionFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>THis part forwards the incoming HTTP request to a JMS endpoint. In our test we can perform tests on this incoming JMS message and check if it is valid.</p>
<p>Next thing I want to explain is the test-config.xml itself. I think it is quite self-explainatory:</p>

<div class="wp_codebox"><table><tr id="p267918"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code" id="p2679code18"><pre class="xml" style="font-family:monospace;"><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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.citrusframework.org/schema/testcase&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:ws</span>=<span style="color: #ff0000;">&quot;http://www.citrusframework.org/schema/ws/testcase&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:spring</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/ws/testcase</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/ws/testcase/citrus-ws-testcase.xsd</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/testcase</span>
<span style="color: #009900;">                  http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;testcase</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Testcase001Test&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta-info<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Redstream Development Team<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2011-04-24<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DRAFT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/meta-info<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tests Testcase001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;send</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;invoiceFileSender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;classpath:data/testcase001.txt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/send<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;receive</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;orderRequestReceiver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">schema-validation</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;validate</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;//ns1:post-invoice/ns1:CompanyCode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;validate</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;string:count(//ns1:post-invoice/ns1:InvoiceLine/ns1:DocID)&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;rs_address&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;order-purchase-invoice-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extract<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;count(//ns1:post-invoice/ns1:InvoiceLine/ns1:DocID)&quot;</span> <span style="color: #000066;">variable</span>=<span style="color: #ff0000;">&quot;${nrOfInvoiceLines}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extract<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/receive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${nrOfInvoiceLines}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;send</span> <span style="color: #000066;">with</span>=<span style="color: #ff0000;">&quot;orderResponseSender&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;classpath:data/response-testcase001.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/send<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/testcase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The first action that is done is sending a file to my Mule ESB. The next step is that I wait for the response from my ESB. When I received that I check the contents of XML message at some points and check if it is valid against the schema.<br />
Then after echoing the number of invoice lines I have Citrus return the HTTP request with a fixed XML response so the Mule ESB ends this action successfully.<br />
That completes this example of how to use Citrus to test your ESB implemention. I hope it is more clear now how you can use Citrus  for your (automated) integration tests with this real life example.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/04/30/citrus-testcase-example-csv-file-inbound-xml-http-outbound/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using parameters with XSLT in Mule</title>
		<link>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/</link>
		<comments>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 11:31:18 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MapForce]]></category>
		<category><![CDATA[Mule2]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2564</guid>
		<description><![CDATA[Recently I got into a situation where I had to put &#8216;metadata&#8217; values (which were part of the Mule Message) into the XML result of an XSLT transformer. Let me explain the situation with an example. Imagine you have an &#8230; <a href="http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F04%2Fusing-parameters-with-xslt-in-mule%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F04%2Fusing-parameters-with-xslt-in-mule%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently I got into a situation where I had to put &#8216;metadata&#8217; values (which were part of the Mule Message) into the XML result of an XSLT transformer. Let me explain the situation with an example. Imagine you have an &#8216;order&#8217; xml that needs to be translated into an &#8216;invoice&#8217; xml. Here is a simple &#8216;order.xsd&#8217;:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/order-xsd.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/order-xsd.png" alt="" title="order-xsd" width="355" height="126" class="aligncenter size-full wp-image-2568" /></a></p>
<p>Here is the &#8216;invoice.xsd&#8217;:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/invoice-xsd.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/invoice-xsd-300x106.png" alt="" title="invoice-xsd" class="aligncenter size-medium wp-image-2569" /></a></p>
<p>The mapping for the transformation looks like this in MapForce:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-without-param.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-without-param-300x133.png" alt="" title="mapping-without-param" class="aligncenter size-medium wp-image-2570" /></a><span id="more-2564"></span></p>
<p>Now the invoice number that is used in the invoice should be the MuleMessage correlationID&#8230;. (I know, weird situation, but it is only an example). The first thing that came to mind was to create a new transformer that would run after the XSLT transformer. This new transformer would add the element &#8216;invoicenr&#8217;  with the correlationID as value to the payload of the MuleMessage. But it can be done much easier! Here is the modified mapping that I created with MapForce:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-with-param.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-with-param-300x288.png" alt="" title="mapping-with-param" class="aligncenter size-medium wp-image-2571" /></a><br />
In MapForce you can add extra input parameters for the XSL mapping as shown above. Now generate the XSLT and use that as basis for your Mule XSLT Transformer. In the Mule config you add the context-property to your XSL Transformer configuration to tell Mule with which value the parameter in the XSLT file should be filled:</p>

<div class="wp_codebox"><table><tr id="p256420"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p2564code20"><pre class="xml" style="font-family:monospace;"><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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mule</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000066;">xmlns:xm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/xml/2.2&quot;</span></span>
<span style="color: #009900;">     ...</span>
<span style="color: #009900;">     <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd</span>
<span style="color: #009900;">     ...</span>
<span style="color: #009900;">     &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:xslt-transformer</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;orderToInvoiceTransformer&quot;</span> <span style="color: #000066;">xsl-file</span>=<span style="color: #ff0000;">&quot;xsl/order-to-invoice.xsl&quot;</span> <span style="color: #000066;">outputEncoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:context-property</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;invoiceNr&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#[message:correlationId]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ship:xslt-transformer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This makes it a very clean and powerful way to add metadata to your payload might you ever need this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Mule EE Retry Policies</title>
		<link>http://www.redstream.nl/2011/01/07/using-mule-ee-retry-policies/</link>
		<comments>http://www.redstream.nl/2011/01/07/using-mule-ee-retry-policies/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 13:31:06 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule2]]></category>
		<category><![CDATA[Mule]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2343</guid>
		<description><![CDATA[At a project for one of our customers we migrated from Mule CE to Mule EE edition (version 2.2.7). The customer had various good reasons to do this and it offered us new functionalities in Mule ESB to use. One &#8230; <a href="http://www.redstream.nl/2011/01/07/using-mule-ee-retry-policies/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F01%2F07%2Fusing-mule-ee-retry-policies%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F01%2F07%2Fusing-mule-ee-retry-policies%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>At a project for one of our customers we migrated from <a href="http://www.mulesoft.org/download-mule-esb-community-edition">Mule CE</a> to <a href="http://www.mulesoft.com/mule-esb-enterprise-trial-download-form">Mule EE edition</a> (version 2.2.7). The customer had <a href="http://www.mulesoft.org/mule-community-vs-mule-enterprise">various good reasons</a> to do this and it offered us new functionalities in Mule ESB to use. One of those &#8216;new&#8217; things is RetryPolicy for some of the Mule Connectors. I quoted &#8216;new&#8217; because there is also <a href="http://www.mulesoft.org/documentation/display/COMMONRETRYPOLICIES/Home">an open source variant</a> that you can use in the community edition but since the customer paid for it I wanted to use this version that comes with Mule EE out-of-the-box.<span id="more-2343"></span><br />
To make use of this EE version I performed the normal steps that you would do when you add a new module to you (Maven) Mule project (as I described <a href="http://www.redstream.nl/2009/07/10/using-a-new-transport-in-your-mule-application/">here</a>). So in short:</p>
<ul>
<li>
<strong>Add the namespace to the Mule config:</strong></p>

<div class="wp_codebox"><table><tr id="p234325"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2343code25"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mule</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">xmlns:ee</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/ee/core/2.2&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd</span>
<span style="color: #009900;">       http://www.mulesource.org/schema/mule/ee/core/2.2 http://www.mulesource.org/schema/mule/ee/core/2.2/mule-ee.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

</li>
<li>
<strong>Add the dependencies to the pom.xml:</strong></p>

<div class="wp_codebox"><table><tr id="p234326"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p2343code26"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mulesource.muleesb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mule-core-ee<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <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.2.7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mulesource.muleesb.modules<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mule-module-retry-ee<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <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.2.7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>
<strong>Add  the retry-element to the connector:</strong></p>

<div class="wp_codebox"><table><tr id="p234327"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p2343code27"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jms:activemq-connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JMSConnector&quot;</span> <span style="color: #000066;">specification</span>=<span style="color: #ff0000;">&quot;1.1&quot;</span> <span style="color: #000066;">dynamicNotification</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">brokerURL</span>=<span style="color: #ff0000;">&quot;failover:(${jms.jndiProviderUrl})&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">acknowledgementMode</span>=<span style="color: #ff0000;">&quot;AUTO_ACKNOWLEDGE&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">maxRedelivery</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">disableTemporaryReplyToDestinations</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;${jms.activeMQUser}&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${jms.activeMQPassword}&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">persistentDelivery</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ee:retry-forever-policy</span> <span style="color: #000066;">frequency</span>=<span style="color: #ff0000;">&quot;30000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jms:activemq-connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
</ul>
<p>Unfortunately, this seemed not enough since I was getting the following stacktrace:</p>
<blockquote><p>
ERROR 2010-12-22 11:55:34,467 [main] org.mule.config.spring.SpringXmlConfigurationBuilder: Configuration with &#8220;org.mule.config.spring.SpringXmlConfigurationBuilder&#8221; failed.<br />
org.mule.api.lifecycle.InitialisationException: Initialisation Failure: Configuration problem: Failed to import bean definitions from URL location [classpath:config/rs-global-config.xml]<br />
Offending resource: URL [jar:file:/Users/pascal/.m2/repository/nl/redstream/framework/rs-test-unit/2.3-SNAPSHOT/rs-test-unit-2.3-SNAPSHOT.jar!/config/rs-core-test-config.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 70 in XML document from class path resource [config/rs-global-config.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element &#8216;ee:retry-forever-policy&#8217;. One of &#8216;{&#8220;http://www.mulesource.org/schema/mule/core/2.2&#8243;:abstract-retry-policy, &#8220;http://www.mulesource.org/schema/mule/core/2.2&#8243;:service-overrides}&#8217; is expected.<br />
        at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:76)<br />
        at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:110)<br />
        at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73)<br />
        at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:39)<br />
        at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)<br />
        at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:79)<br />
        at org.mule.tck.AbstractMuleTestCase.createMuleContext(AbstractMuleTestCase.java:474)<br />
        at org.mule.tck.AbstractMuleTestCase.setUp(AbstractMuleTestCase.java:443)<br />
        at junit.framework.TestCase.runBare(TestCase.java:132)<br />
        at org.mule.tck.AbstractMuleTestCase.runBare(AbstractMuleTestCase.java:295)<br />
        at junit.framework.TestResult$1.protect(TestResult.java:110)<br />
        at junit.framework.TestResult.runProtected(TestResult.java:128)<br />
        at junit.framework.TestResult.run(TestResult.java:113)<br />
        at junit.framework.TestCase.run(TestCase.java:124)<br />
        at org.mule.tck.AbstractMuleTestCase.run(AbstractMuleTestCase.java:274)<br />
        at junit.framework.TestSuite.runTest(TestSuite.java:232)<br />
        at junit.framework.TestSuite.run(TestSuite.java:227)<br />
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)<br />
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)<br />
        at &#8230;.. (much much more)<br />
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.401 sec <<< FAILURE!
</p></blockquote>
<p>After some investigation it seemed I missed a dependency:</p>

<div class="wp_codebox"><table><tr id="p234328"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2343code28"><pre class="xml" style="font-family:monospace;">            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.mulesource.muleesb.modules<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mule-module-spring-config-ee<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <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.2.7<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The problem was that this was not documented (at least not in <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Configuring+Retry+Policies">the places I looked</a> ;-)). Luckily we solved it and is working fine now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/01/07/using-mule-ee-retry-policies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About Mule, content-based routing and namespaces</title>
		<link>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/</link>
		<comments>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 11:49:12 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule2]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1955</guid>
		<description><![CDATA[Some of our Mule ESB applications make use of content-based routing when processing a message. To implement this in Mule we use a filtering-router with a jaxen-filter. The most simple example looks like this: 1 2 3 4 5 6 &#8230; <a href="http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F21%2Fabout-mule-content-based-routing-and-namespaces%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F21%2Fabout-mule-content-based-routing-and-namespaces%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Some of our <a href="http://www.mulesoft.org/">Mule ESB</a> applications make use of <a href="http://www.eaipatterns.com/ContentBasedRouter.html">content-based routing</a> when processing a message. To implement this in Mule we use a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Outbound+Routers#OutboundRouters-FilteringRouter">filtering-router</a> with a jaxen-filter. The most simple example looks like this:</p>

<div class="wp_codebox"><table><tr id="p195532"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code32"><pre class="xml" style="font-family:monospace;">...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;//firstname&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Pascal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p>You can also use a XPath function in your jaxen-filter like this (if you want to check a certain element is in an XML message regardless the value of the element):</p>

<div class="wp_codebox"><table><tr id="p195533"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code33"><pre class="xml" style="font-family:monospace;">...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;local-name(//Relations)&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Relations&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p><span id="more-1955"></span><br />
The problem starts if you have to declare namespaces in your XPath expression. You can use namespaces in your XPath expression by declaring a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Expressions+Configuration+Reference#ExpressionsConfigurationReference-NamespacesforXPathExpressions">namespace-manager</a> in your mule-config, like this:</p>

<div class="wp_codebox"><table><tr id="p195534"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1955code34"><pre class="xml" style="font-family:monospace;">...
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace-manager</span> <span style="color: #000066;">includeConfigNamespaces</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;ns1&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://www.redstream.nl/relations/v1_1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xm:namespace-manager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;local-name(//ns1:Relations)&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Relations&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p>But if you run this example you will get the following exception:</p>
<blockquote><p>org.jaxen.UnresolvableException: No Such Function {http://www.mulesource.org/schema/mule/core/2.2}:local-name<br />
        at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:127)<br />
        at org.jaxen.ContextSupport.getFunction(ContextSupport.java:242)<br />
        at org.jaxen.Context.getFunction(Context.java:216)<br />
        at org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:172)<br />
        at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)<br />
        at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)<br />
        at org.jaxen.BaseXPath.selectSingleNodeForContext(BaseXPath.java:698)<br />
        at org.jaxen.BaseXPath.stringValueOf(BaseXPath.java:279)<br />
        at org.jaxen.BaseXPath.valueOf(BaseXPath.java:254)<br />
        at org.mule.module.xml.filters.JaxenFilter.accept(JaxenFilter.java:184)<br />
        at org.mule.module.xml.filters.JaxenFilter.accept(JaxenFilter.java:118)<br />
        at org.mule.routing.outbound.FilteringOutboundRouter.isMatch(FilteringOutboundRouter.java:119)<br />
        at org.mule.routing.outbound.DefaultOutboundRouterCollection. route(DefaultOutboundRouterCollection.java:72)<br />
        at org.mule.service.AbstractService.dispatchToOutboundRouter(AbstractService.java:867)<br />
        at org.mule.model.seda.SedaService.dispatchToOutboundRouter(SedaService.java:561)<br />
        at org.mule.model.seda.SedaService$ComponentStageWorker.doRun(SedaService.java:583)<br />
        at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:41)<br />
        at org.mule.work.WorkerContext.run(WorkerContext.java:310)<br />
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor. runWorker(ThreadPoolExecutor.java:1061)<br />
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker. run(ThreadPoolExecutor.java:575)<br />
        at java.lang.Thread.run(Thread.java:637)
</p></blockquote>
<p>Although it is logged as warning it makes the filter to return no matching values and the XML message is discarded (although I use the jaxen-filter here this also goes for the <a href="http://www.mulesoft.org/documentation/display/MULE2USER/XML+Module#XMLModule-Filters">jxpath-filter and the xpath-filter</a>).</p>
<p>The solution for this is quite simple: just give the XPath function a unique prefix (one that is not mapped to a namespace). So if you modify the last example and make the jaxen-filter like:<br />
<code>&lt;xm:jaxen-filter pattern="fn:local-name(//ns1:Relations)"  expectedValue="Relations"/&gt;</code><br />
or<br />
<code>&lt;xm:jaxen-filter pattern="abc:local-name(//ns1:Relations)" expectedValue="Relations"/&gt;</code><br />
it will work.<br />
You just have to make sure the prefix you use isn&#8217;t used in the declared <em>namespace-manager</em> because then the function is looked up (and not found) in the supplied XML document.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On multicasting, chaining routers and the matchAll attribute</title>
		<link>http://www.redstream.nl/2010/08/10/on-multicasting-chaining-routers-and-the-matchall-attribute/</link>
		<comments>http://www.redstream.nl/2010/08/10/on-multicasting-chaining-routers-and-the-matchall-attribute/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:46:23 +0000</pubDate>
		<dc:creator>Pascal Prins</dc:creator>
				<category><![CDATA[Mule]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1895</guid>
		<description><![CDATA[Last week I had to implement an interface for a customer in which an XML file had to be loaded into the database. But &#8230; the database table needed to be truncated first. At first, I thought that a chaining &#8230; <a href="http://www.redstream.nl/2010/08/10/on-multicasting-chaining-routers-and-the-matchall-attribute/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F10%2Fon-multicasting-chaining-routers-and-the-matchall-attribute%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F10%2Fon-multicasting-chaining-routers-and-the-matchall-attribute%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I had to implement an interface for a customer in which an XML file had to be loaded into the database. But &#8230; the database table needed to be truncated first. At first, I thought that a chaining router would suffice. I soon found out that the behaviour of this router was not desirable at all.<br />
<span id="more-1895"></span><br />
Mule ESB contains <code>multicasting</code> and <code>chaining</code> routers to join a set of outbound endpoints. They differ in behaviour. When using a <code>multicasting-router</code> a message is send to multiple endpoints in a parallel way. So, you&#8217;re not sure if endpoint A has processed the message when endpoint B is about to start.</p>
<p>The <code>chaining-router</code> sends the message to the outbound endpoint collection in a sequential way, but the outcome of endpoint A will be send to endpoint B as payload. In other words, the endpoint will not process the same MuleMessage.</p>
<p>So, what to use if both types are not suitable?</p>
<p>Mule allows you to setup multiple routers (inbound as well as outbound). Class <code>org.mule.routing.outbound.DefaultOutboundRouterCollection</code> represents the collection of outbound routers in your Mule configuration. By using the (optional) <code>matchAll</code> attribute on the outbound router collection, the MuleMessage will be copied sent to *all* outbound routers (look at the <code>public MuleMessage route(final MuleMessage message, final MuleSession session)</code> method).</p>
<p>The following code snippet shows hows this should be implemented. It&#8217;s not a complete config .. but you&#8217;ll get the point. Notice the <code>matchAll</code> attribute!</p>

<div class="wp_codebox"><table><tr id="p189537"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p1895code37"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;foobar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:inbound-endpoint</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;do.it&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound</span> <span style="color: #000066;">matchAll</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pass-through-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:outbound-endpoint</span> <span style="color: #000066;">queryKey</span>=<span style="color: #ff0000;">&quot;truncateCustomers&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pass-through-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expression-splitter-router</span> <span style="color: #000066;">evaluator</span>=<span style="color: #ff0000;">&quot;xpath&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;//Customer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:outbound-endpoint</span> <span style="color: #000066;">queryKey</span>=<span style="color: #ff0000;">&quot;insertCustomer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expression-splitter-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Suppose an XML document containing Customers is offered to the inbound endpoint. What happens is that the Customers database table is truncated first and next the XML document is split up using the xpath expression. The end result is that the Customer table is replaced with the contents of the XML document.</p>
<p>In short: there are numerous situations where you would like to offer the MuleMessage to the complete outbound router collection. Use the <code>matchAll</code> attribute in these situation.</p>
<p>Happy Mule&#8217;ing !!</p>
<p><strong>UPDATE</strong>: seems that there&#8217;s an even simpler solution to the problem that I&#8217;ve overlooked. (although my described solution works as advertised).</p>
<p>Using the following code snippet will do the trick as well:</p>

<div class="wp_codebox"><table><tr id="p189538"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p1895code38"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>service name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">&gt;</span>
...
<span style="color: #339933;">&lt;</span>outbound<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>multicasting<span style="color: #339933;">-</span>router<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>jdbc<span style="color: #339933;">:</span>outbound<span style="color: #339933;">-</span>endpoint queryKey<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;truncateCustomers&quot;</span> synchronous<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>vm<span style="color: #339933;">:</span>outbound<span style="color: #339933;">-</span>endpoint path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;processCustomers&quot;</span> synchronous<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;/</span>multicasting<span style="color: #339933;">-</span>router<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>outbound<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>service<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>service name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>inbound<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>vm<span style="color: #339933;">:</span>inbound<span style="color: #339933;">-</span>endpoint path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;processCustomers&quot;</span><span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;/</span>inbound<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>outbound<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>expression<span style="color: #339933;">-</span>splitter<span style="color: #339933;">-</span>router evaluator<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;xpath&quot;</span> expression<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;//Customer&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>jdbc<span style="color: #339933;">:</span>outbound<span style="color: #339933;">-</span>endpoint queryKey<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;insertCustomer&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;/</span>expression<span style="color: #339933;">-</span>splitter<span style="color: #339933;">-</span>router<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>outbound<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>service<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Notice that the <code>matchAll</code> attribute has been replaced with <code>synchronous</code>. This last attribute results in the fact that the incoming message will *not* move on to the next outbound router in the collection until it has been consumed by a previous one.</p>
<p>With the introduction of Mule 3, this will probably all <a href="http://blogs.mulesoft.org/goodbye-sync-hello-exchange-pattern/">change</a> (for the better).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/08/10/on-multicasting-chaining-routers-and-the-matchall-attribute/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mule and the &quot;Attempted read from closed stream&quot;-exception</title>
		<link>http://www.redstream.nl/2010/07/25/mule-and-the-attempted-read-from-closed-stream-exception/</link>
		<comments>http://www.redstream.nl/2010/07/25/mule-and-the-attempted-read-from-closed-stream-exception/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 12:57:17 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[CXF]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1916</guid>
		<description><![CDATA[When you are using a certain version of Mule ESB you are going to run into an existing bug sooner or later. That isn&#8217;t really a problem, I would call it inevitable (at least based on my own experience). The &#8230; <a href="http://www.redstream.nl/2010/07/25/mule-and-the-attempted-read-from-closed-stream-exception/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F07%2F25%2Fmule-and-the-attempted-read-from-closed-stream-exception%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F07%2F25%2Fmule-and-the-attempted-read-from-closed-stream-exception%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>When you are using a certain version of  <a href="http://www.mulesoft.org/">Mule ESB</a> you are going to run into an existing bug sooner or later. That isn&#8217;t really a problem, I would call it inevitable (at least based on my own experience). The big advantage of the open source idea is that you can dive into the source code and see where the problem is caused and fix it ( or at least work around it). I remember the time I was using Oracle Forms Developer to build applications. When you ran into a bug you had to wait until Oracle was ready to fix/patch it (or, of course, convince the client to not want that specific feature in their application).<br />
Although its true you can find all known bugs for Mule in <a href="http://www.mulesoft.org/jira/browse/">Jira</a>, you still have to discover yourself your application is having a problem with that known issue.  I recently implemented a new interface in our application and I started to make use of <a href="http://www.mulesoft.org/documentation/display/CXF/Home">the CXF transport</a> (until now it was mainly based on JMS and VM). The exception I got when processing a message was</p>
<blockquote><p>java.io.IOException: Attempted read from closed stream.</p></blockquote>
<p> The weird thing was, I didn&#8217;t get this exception when running my unit tests and it sometimes even worked in my deployed application.<br />
As I said we got this exception when we added the CXF endpoint, although we did it as described <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Building+a+CXF+Web+Service">in the manual</a>. Well, to make a long story short, it appeared we were running into <a href="http://www.mulesoft.org/jira/browse/MULE-4096">this</a> issue. In our deployed version we make use of the <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Mule+Server+Notifications">Mule Notifications</a>. We have extended the default Mule endpoints so they can indicate if a message they are processing should be logged. This logging is done by receiving the Notification and extracting the message from it. Then we log the payload of the MuleMessage as text in our database.<br />
This works great as long the payload of the message isn&#8217;t an InputStream! in case of an InputStream the  stream is read to make a String of it and since a InputStream can only be read once, the rest of the application cannot read it again (hence the &#8216;<em>Attempted read from closed stream</em>&#8216;). This behaviour is described in <a href="http://www.mulesoft.org/jira/browse/MULE-4096">Jira</a> but you can image that it took some time before we realized we were running into this. Especially because the stack trace isn&#8217;t of much use in this case since it is pointing to some deep down CXF code that tries to read the input stream.<br />
Next time someone has a similar issue and you are using Notification Handlers you might want to check these out and this way save yourself a lot of time looking for the cause of this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/07/25/mule-and-the-attempted-read-from-closed-stream-exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto Quickly Insert XML into a Database using Mule ESB</title>
		<link>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/</link>
		<comments>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 09:04:47 +0000</pubDate>
		<dc:creator>Pascal Prins</dc:creator>
				<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1880</guid>
		<description><![CDATA[Mule ESB is a versatile service bus that contains numerous usable components out-of-the-box. In this blog I&#8217;ll show you how to process an incoming XML document, break it up into multiple parts and insert them into the database without using &#8230; <a href="http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F12%2Fhowto-quickly-insert-xml-into-a-database-using-mule-esb%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F12%2Fhowto-quickly-insert-xml-into-a-database-using-mule-esb%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Mule ESB is a versatile service bus that contains numerous usable components out-of-the-box. In this blog I&#8217;ll show you how to process an incoming XML document, break it up into multiple parts and insert them into the database without using any custom Java classes.</p>
<p><span id="more-1880"></span></p>
<p>In this example we will be using this (simple) XML document as source input. The document contains a collection of Customers.</p>

<div class="wp_codebox"><table><tr id="p188044"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p1880code44"><pre class="xml" style="font-family:monospace;"><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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Steve<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jobs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1 Infinite Loop<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cupertino<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Bill<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gates<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1 Microsoft Way<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Washington<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>After breaking the XML up into multiple <code>Customer</code> entities, we will insert them into the following database structure:</p>

<div class="wp_codebox"><table><tr id="p188045"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1880code45"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">create</span> <span style="color: #993333; font-weight: bold;">table</span> CUSTOMERS <span style="color: #66cc66;">&#40;</span>
   first_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  last_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  street VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  city VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  country VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>To split the XML document into multiple <code>Customer</code> entities, we&#8217;ll use an outbound splitting router like this one:</p>

<div class="wp_codebox"><table><tr id="p188046"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1880code46"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expression-splitter-router</span> <span style="color: #000066;">evaluator</span>=<span style="color: #ff0000;">&quot;xpath&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;//Customer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stdio:outbound-enpdoint</span> <span style="color: #000066;">system</span>=<span style="color: #ff0000;">&quot;OUT&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expression-splitter-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>xpath</code> evaluator mentioned in the <code>expression-splitter-router</code> excepts both Dom and String objects. This means we can just use plain XML files (no need to create a <code>w3c.dom.Document</code> first. It&#8217;ll be parsed on-the-fly.</p>
<p>Once the message has been split, we want each Customer to be inserted into a database. The trick here is to use the<a href="http://www.mulesoft.org/documentation/display/MULE2USER/JDBC+Transport"> JDBC transport</a>. We&#8217;ll need to configure a <code>connector</code> in which<br />
&#8220;named queries&#8221; can be configured. A &#8220;named query&#8221; is a PODS (~Plain Old Dml Statement) identified by a key.</p>

<div class="wp_codebox"><table><tr id="p188047"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1880code47"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcConnector&quot;</span> <span style="color: #000066;">dataSource-ref</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:query</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;insertIntoFoobar&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;insert into FOOBAR (id, code, description) VALUES (#[map-payload:ID], #[map-payload:CODE], #[map-payload:DESCRIPTION])&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jdbc:connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In this example, a Map payload is expected from which the values are derived. When using XML, an XPATH expression evaluator seems more appropriate (see final solution).</p>
<p>PS: It might be nice to know that <a target="_blank" href="http://www.mulesoft.org/documentation/display/MULE2USER/JDBC+Transport#JDBCTransport-UnnamedQueries">unnamed queries</a> are also supported.</p>
<p>I&#8217;ve introduced the basics, now let&#8217;s have a look at the complete Mule configuration:</p>

<div class="wp_codebox"><table><tr id="p188048"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code" id="p1880code48"><pre class="xml" style="font-family:monospace;"><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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mule</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:spring</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:vm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/vm/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:xm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/xml/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:jdbc</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/jdbc/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:context</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/context&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd</span>
<span style="color: #009900;">      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/jdbc/2.2 http://www.mulesource.org/schema/mule/jdbc/2.2/mule-jdbc.xsd</span>
<span style="color: #009900;">      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:property-placeholder</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;classpath:my.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.standard.StandardDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;shutdown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.driverName}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.url}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcConnector&quot;</span> <span style="color: #000066;">dataSource-ref</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:query</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;insertCustomer&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;insert into CUSTOMERS (first_name, last_name, street, city, country) VALUES (#[xpath://Customer/FirstName],#[xpath://Customer/LastName],#[xpath://Customer/Address/Street],#[xpath://Customer/Address/City],#[xpath://Customer/Address/Country])&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jdbc:connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace-manager</span> <span style="color: #000066;">includeConfigNamespaces</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;cus&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://www.redstream.nl/schema/customer/1.0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xm:namespace-manager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;processCustomers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:inbound-endpoint</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;processCustomersService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expression-splitter-router</span> <span style="color: #000066;">evaluator</span>=<span style="color: #ff0000;">&quot;xpath&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;//Customer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:outbound-endpoint</span> <span style="color: #000066;">queryKey</span>=<span style="color: #ff0000;">&quot;insertCustomer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expression-splitter-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Et voila &#8230; using the above configuration, you will be able to process incoming XML and insert the contents in a database.</p>
<p>Some final notes:</p>
<ul>
<li>Use a <code>property-placeholder</code> to configure the database credentials.</li>
<li>When incoming XML contains namespaces, they could globally be configured using a <code>namespace-manager</code></li>
<li>Notice that the <code>jdbc:outbound-endpoint</code> refers to the named query by key</li>
<li>The named query will be &#8220;injected&#8221; with a single Customer entity, accessible by the XPATH expression evaluator</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Combining Mule with Altova MapForce</title>
		<link>http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/</link>
		<comments>http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 06:35:11 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[MapForce]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1753</guid>
		<description><![CDATA[As promised in our previous blog about Altova Mapforce we will show in this post how to combine the result of the generated code of Altova Mapforce with a Mule application. As we have shown before, the Java code that &#8230; <a href="http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F03%2Fcombining-mule-with-altova-mapforce%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F03%2Fcombining-mule-with-altova-mapforce%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As promised in our <a href="http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/">previous</a> blog about <a href="http://www.altova.com/mapforce.html">Altova Mapforce</a> we will show in this post how to combine the result of the generated code of Altova Mapforce with a <a href="http://www.mulesoft.org/">Mule</a> application. As we have shown before, the Java code that is generated by MapForce is divided in two parts:</p>
<ul>
<li>one is Altova generic, so will be reused for each mapping</li>
<li>one is mapping specific so is the actual part that changes with the mapping (this package name is configurable)</li>
</ul>
<p><span id="more-1753"></span></p>
<p>We first jarred the Altova generic code and added it to our Maven repository (<a href="http://www.jfrog.org/index.php">Artifactory</a>) so we can include this in our Mule project as dependency. We removed the generated mapping-specific Java code and used the included Ant build script to create the jar file. Here is a screenshot of how it looks in Artifactory:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-28-at-8.15.09-AM.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-28-at-8.15.09-AM-300x187.png" alt="" title="ArtifactoryScreenshot" width="300" height="187" class="alignnone size-medium wp-image-1803" /></a></p>
<p>Now if we want to use Mapforce generated code, we add the following dependency to the pom:</p>

<div class="wp_codebox"><table><tr id="p175351"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1753code51"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.altova<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mapforce-core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010R2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The next step is to add the generated mapping-specific code to the project. We do this by copying the generated mapping specific code to our Mule project (in MapForce you can configure the package name to be used for the generated code so that makes it easier fitting in<br />
with the rest of the code). Here is a screenshot of the code to copy in this case:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-01-at-8.16.56-AM.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-01-at-8.16.56-AM-300x176.png" alt="" title="Screen shot 2010-06-01 at 8.16.56 AM" width="300" height="176" class="alignnone size-medium wp-image-1856" /></a></p>
<p>Then we created a Transformer class in the Mule project that calls the generated mapping code and returns the result.<br />
Here is an example of a Transformer which uses the generated code:</p>

<div class="wp_codebox"><table><tr id="p175352"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code" id="p1753code52"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.transformers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StreamInput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StringInput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StringOutput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nl.redstream.mapping.MappingMapTocustomer2</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.api.transformer.TransformerException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.transformer.AbstractTransformer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author pascal
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomerCsvToXmlTransformer <span style="color: #000000; font-weight: bold;">extends</span> AbstractTransformer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> CustomerCsvToXmlTransformer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        registerSourceType<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        registerSourceType<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: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setReturnClass<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: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> doTransform<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> payload, <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> encoding<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> TransformerException <span style="color: #009900;">&#123;</span>
&nbsp;
        MappingMapTocustomer2 mappingToXml <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MappingMapTocustomer2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        StringOutput output <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringOutput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>payload <span style="color: #000000; font-weight: bold;">instanceof</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;">&#41;</span> <span style="color: #009900;">&#123;</span>
            StringInput input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringInput<span style="color: #009900;">&#40;</span><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;">&#41;</span> payload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                mappingToXml.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>input, output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> TransformerException<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>payload <span style="color: #000000; font-weight: bold;">instanceof</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            StreamInput sInput <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StreamInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a><span style="color: #009900;">&#41;</span> payload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                mappingToXml.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>sInput, output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> TransformerException<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> output.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it! Define the transformer as a &#8216;custom-transformer&#8217; in your Mule config and your done. You can now create and maintain all your mappings visually with MapForce.<br />
We are now looking into the capabilities that SPL (Spy Programming Language) offer, because it looks like we can generate the Mule Transformer straight from MapForce, that would even boost the producivity more!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Smooks+Mule to transform CSV file to XML one</title>
		<link>http://www.redstream.nl/2010/04/29/using-smooksmule-to-transform-csv-file-to-xml-one/</link>
		<comments>http://www.redstream.nl/2010/04/29/using-smooksmule-to-transform-csv-file-to-xml-one/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 19:44:08 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[Smooks]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1724</guid>
		<description><![CDATA[As I promised before here is an example of how to use Smooks in combination with Mule. In this example I transform a CSV file to a plain XML file. This XML file can then be transformed with an XSLT &#8230; <a href="http://www.redstream.nl/2010/04/29/using-smooksmule-to-transform-csv-file-to-xml-one/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F04%2F29%2Fusing-smooksmule-to-transform-csv-file-to-xml-one%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F04%2F29%2Fusing-smooksmule-to-transform-csv-file-to-xml-one%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As I promised <a href="http://www.redstream.nl/2010/04/23/combining-smooks-with-mule/">before</a> here is an example of how to use  <a href="http://www.smooks.org/mediawiki/">Smooks</a> in combination with <a href="http://www.mulesoft.org/display/COMMUNITY/Home">Mule</a>. In this example I transform a CSV file to a plain XML file. This XML file can then be transformed with an XSLT transformation to the desired XML format. <span id="more-1724"></span><br />
I start with the Smooks config file &#8216;smooks-csv-config.xml&#8217;:</p>

<div class="wp_codebox"><table><tr id="p172457"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1724code57"><pre class="xml" style="font-family:monospace;"><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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;smooks-resource-list</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.milyn.org/xsd/smooks-1.1.xsd&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">xmlns:csv</span>=<span style="color: #ff0000;">&quot;http://www.milyn.org/xsd/smooks/csv-1.2.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;csv:reader</span> <span style="color: #000066;">fields</span>=<span style="color: #ff0000;">&quot;order_no?trim,cust_no?trim,prod_no?trim,amount?trim&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">separator</span>=<span style="color: #ff0000;">&quot;|&quot;</span> <span style="color: #000066;">quote</span>=<span style="color: #ff0000;">&quot;'&quot;</span> <span style="color: #000066;">skipLines</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rootElementName</span>=<span style="color: #ff0000;">&quot;orders&quot;</span> <span style="color: #000066;">recordElementName</span>=<span style="color: #ff0000;">&quot;order&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-config</span> <span style="color: #000066;">selector</span>=<span style="color: #ff0000;">&quot;global-parameters&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stream.filter.type&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>SAX<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/smooks-resource-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The important part is in the &#8216;csv:reader fields&#8217; attribute. Here I define the fields that can be expected in my input CSV file. As you can see I apply &#8216;?trim&#8217; to the fields so additional spaces are removed.<br />
My Mule config file &#8216;smooks-csv-config&#8217; that is used for this test can be found <a href="http://www.redstream.nl/wp-content/uploads/2010/04/smooks-csv-config.xml">here</a>. The important part looks like:</p>

<div class="wp_codebox"><table><tr id="p172458"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1724code58"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;smooks:transformer</span></span>
<span style="color: #009900;">        <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;csvToXmlSmooksTransformer&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">configFile</span>=<span style="color: #ff0000;">&quot;/transforms/smooks-csv-config.xml&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">resultType</span>=<span style="color: #ff0000;">&quot;STRING&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">reportPath</span>=<span style="color: #ff0000;">&quot;target/smooks-report/report.html&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>In the transformer the Smooks config file to be used is defined, so in this case I refer to the one I showed in at the beginning of this post. The next step is to create the test class.:</p>

<div class="wp_codebox"><table><tr id="p172459"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code" id="p1724code59"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.mule.test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Locale</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.TimeZone</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.DefaultMuleMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.api.MuleMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.module.client.MuleClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.tck.FunctionalTestCase</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.util.IOUtils</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SmooksCsvTest <span style="color: #000000; font-weight: bold;">extends</span> FunctionalTestCase
<span style="color: #009900;">&#123;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</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> getConfigResources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;config/smooks-csv-config.xml&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Test
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testSmooks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a> in <span style="color: #339933;">=</span> IOUtils.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test-order.csv&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		MuleClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MuleClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		MuleMessage reply <span style="color: #339933;">=</span> client.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;vm://test-csv-to-xml&quot;</span>,<span style="color: #000000; font-weight: bold;">new</span> DefaultMuleMessage<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		assertNotNull<span style="color: #009900;">&#40;</span>reply<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertNotNull<span style="color: #009900;">&#40;</span>reply.<span style="color: #006633;">getPayload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> payload <span style="color: #339933;">=</span> reply.<span style="color: #006633;">getPayload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		assertTrue<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The message payload is not an instance of String&quot;</span>, payload <span style="color: #000000; font-weight: bold;">instanceof</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;">&#41;</span><span style="color: #339933;">;</span>
		assertTrue<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The report file wasn't created&quot;</span>, getReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> getReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;target/smooks-report/report.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> deleteReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		getReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Javadoc)
	 * @see org.mule.tck.AbstractMuleTestCase#doSetUp()
	 */</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doSetUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">doSetUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atimezone+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TimeZone</span></a>.<span style="color: #006633;">setDefault</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atimezone+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">TimeZone</span></a>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;EST&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alocale+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Locale</span></a>.<span style="color: #006633;">setDefault</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alocale+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Locale</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;en&quot;</span>,<span style="color: #0000ff;">&quot;IE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		deleteReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Javadoc)
	 * @see org.mule.tck.AbstractMuleTestCase#doTearDown()
	 */</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doTearDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">doTearDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		deleteReportFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the file I read the CSV file and put it on the inbound endpoint. The Smooks transformer is then applied to it and the result is passed to the STDIO outbound. So as a result I expect XML output in my console. The CSV file I used for testing looks like:</p>
<blockquote><p>1888852|      21625|02745011|31|<br />
1888853|      21625|02745011|71|<br />
1888854|      21625|02745011| 3|
</p></blockquote>
<p>And the result in my console contains:</p>

<div class="wp_codebox"><table><tr id="p172460"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p1724code60"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;orders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1888852<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21625<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>02745011<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>31<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1888853<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21625<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>02745011<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>71<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1888854<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>21625<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cust_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>02745011<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prod_no<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/amount<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/orders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Of course this generated XML is very basic but it can be the base for the next (XSLT) transformation step as I said earlier in this post to create a more advanced XML matching your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/04/29/using-smooksmule-to-transform-csv-file-to-xml-one/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

