<?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>The Carbon Emitter &#187; Java</title>
	<atom:link href="http://blog.carbonfive.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.carbonfive.com</link>
	<description>The blog of Carbon Five</description>
	<lastBuildDate>Mon, 23 Jan 2012 18:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Intro to Spring MVC Talk at SD Forum</title>
		<link>http://blog.carbonfive.com/2010/04/27/intro-to-spring-mvc-talk-at-sd-forum/</link>
		<comments>http://blog.carbonfive.com/2010/04/27/intro-to-spring-mvc-talk-at-sd-forum/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 22:12:18 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Speaking]]></category>
		<category><![CDATA[spring mvc]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=986</guid>
		<description><![CDATA[I&#8217;ll be speaking next Tuesday evening for SD Forum in Palo Atlo about Spring MVC. It&#8217;s mostly an introductory talk, but I&#8217;ll weave in some opinions and lessons learned from real projects. I&#8217;ll cover many of the MVC features, including &#8230; <a href="http://blog.carbonfive.com/2010/04/27/intro-to-spring-mvc-talk-at-sd-forum/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be speaking next Tuesday evening for SD Forum in Palo Atlo about Spring MVC.  It&#8217;s mostly an introductory talk, but I&#8217;ll weave in some opinions and lessons learned from real projects.  I&#8217;ll cover many of the MVC features, including those introduced in 3.0, by walking through code for a running application.</p>
<p><strong><a href="http://www.sdforum.org/index.cfm?fuseaction=Calendar.eventDetail&amp;eventID=13694">Event Page</a></strong></p>
<p>Networking (and pizza) starts at 6:30 and we&#8217;ll get down to business at 7:00.  The night starts with a short talk about Agile Java by Bjorn Freeman-Benson, of New Relic fame.</p>
<p>If you&#8217;re still doing Java and you&#8217;re curious about Spring MVC, come join in the fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2010/04/27/intro-to-spring-mvc-talk-at-sd-forum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screw.Unit JS Testing in Maven: javascript-test-maven-plugin</title>
		<link>http://blog.carbonfive.com/2010/02/24/screw-unit-js-testing-in-maven-javascript-test-maven-plugin/</link>
		<comments>http://blog.carbonfive.com/2010/02/24/screw-unit-js-testing-in-maven-javascript-test-maven-plugin/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 20:29:31 +0000</pubDate>
		<dc:creator>Alex Cruikshank</dc:creator>
				<category><![CDATA[Process]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript / AJAX]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=878</guid>
		<description><![CDATA[I&#8217;ve written a maven plugin to integrate Screw.Unit javascript tests into a maven build. The project is inspired by the Blue Ridge testing framework for Rails, but it&#8217;s a bit more light-weight by design. To use the plugin you should &#8230; <a href="http://blog.carbonfive.com/2010/02/24/screw-unit-js-testing-in-maven-javascript-test-maven-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a <a href="http://code.google.com/p/javascript-test-maven-plugin/">maven plugin</a> to integrate <a href="http://github.com/nkallen/screw-unit">Screw.Unit</a> javascript tests into a maven build.  The project is inspired by the <a href="http://blog.thinkrelevance.com/2009/5/12/blue-ridge-1-0-javascript-unit-testing-for-rails-scandalous">Blue Ridge</a> testing framework for Rails, but it&#8217;s a bit more light-weight by design.<br />
<span id="more-878"></span><br />
To use the plugin you should start by downloading Screw.Unit and implement your tests according to their instructions.  Once you have some tests implemented in html files, add the plugin to your maven pom file:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
&amp;lt;plugin&amp;gt;
    &amp;lt;executions&amp;gt;
        &amp;lt;execution&amp;gt;
            &amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;javascript-test&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;
        &amp;lt;/execution&amp;gt;
    &amp;lt;/executions&amp;gt;
    &amp;lt;groupId&amp;gt;com.carbonfive.javascript-test&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;javascript-test-maven-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-beta1&amp;lt;/version&amp;gt;
    &amp;lt;configuration&amp;gt;
        &amp;lt;includes&amp;gt;
            &amp;lt;include&amp;gt;src/test/javascript/suite*.html&amp;lt;/include&amp;gt;
        &amp;lt;/includes&amp;gt;
    &amp;lt;/configuration&amp;gt;
&amp;lt;/plugin&amp;gt;
</pre>
<p>You will probably also need to add Carbon Five&#8217;s public repository so that maven will know where to grab the plugin:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
&amp;lt;pluginRepositories&amp;gt;
    &amp;lt;pluginRepository&amp;gt;
        &amp;lt;id&amp;gt;c5-public-repository&amp;lt;/id&amp;gt;
        &amp;lt;name&amp;gt;Carbon Five Public Repository&amp;lt;/name&amp;gt;
        &amp;lt;url&amp;gt;http://mvn.carbonfive.com/public&amp;lt;/url&amp;gt;
    &amp;lt;/pluginRepository&amp;gt;
&amp;lt;/pluginRepositories&amp;gt;
</pre>
<p>The &lt;configuration&gt; section contains <a href="http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html">standard</a> maven &lt;include&gt; and &lt;exclude&gt; tags to allow you to specify any Screw.Unit test suite html files you would like to include in your build.</p>
<p>Now when maven executes its test phase, it will include your javascript tests as well. Any test that fails will halt the build. When the test phase is complete the target directory will contain a &#8216;screw-unit&#8217; directory that contains the test reports. There will be two files for every file included in the test execution The first is an XML file named TEST-dir1.dir2.dir3.filename.html.xml that contains the test results for that file in a reasonable approximation of JUnit&#8217;s xml format. The other file will be named dir1.dir2.dir3.filename.html and will contain a sort of snapshot of the test suite&#8217;s html at the time the tests completed (the javascript will be removed and the css will be baked in).</p>
<p>Like Blue Ridge, the javascript-test-maven-plugin relies on the excellent <a href="http://ejohn.org/blog/bringing-the-browser-to-the-server/">env.js</a> project and the less-excellent <a href="http://www.mozilla.org/rhino/">Rhino</a> project to emulate a browser in Java.   Unfortunately this combination creates the possibility of discrepancies between the browser and build results, and the probability of relatively slow test execution.  To keep the simulation as realistic as possible, javascript-test-maven-plugin recreates the test environment for each Screw.Unit html file, so the more tests you can cram into a single file the faster your builds will run.</p>
<p>There are a few directions for future work.  I&#8217;d like for the plugin to handle other browser-based javascript testing frameworks.  Screw.Unit is popular, but seems suboptimal in many respects.  The only limiting factor here is the plugin&#8217;s ability to interpret the results.  If env.js could run in javascript interpreters other than Rhino, I&#8217;d like to give the the plugin the capability to fork out to <a href="http://www.mozilla.org/js/spidermonkey/">spidermonkey</a> for better compatibility and performance.  Modifying the plugin would be relatively easy, but env.js appears to have some significant dependencies on Java.</p>
<p>Check it out if you have a need for this kind of thing and let us know if you have any problems or suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2010/02/24/screw-unit-js-testing-in-maven-javascript-test-maven-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Database Migrations: Fail when database is out of date</title>
		<link>http://blog.carbonfive.com/2010/01/20/database-migrations-fail-when-database-is-out-of-date/</link>
		<comments>http://blog.carbonfive.com/2010/01/20/database-migrations-fail-when-database-is-out-of-date/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 22:41:15 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=811</guid>
		<description><![CDATA[The latest release of the Carbon Five Database Migration maven plugin supports a new goal: check. The check goal fails the build if the database isn&#8217;t up to date. That is, if there are pending migrations the plugin produces a &#8230; <a href="http://blog.carbonfive.com/2010/01/20/database-migrations-fail-when-database-is-out-of-date/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The latest release of the <a href="http://code.google.com/p/c5-db-migration/">Carbon Five Database Migration maven plugin</a> supports a new goal: check.  The check goal fails the build if the database isn&#8217;t up to date.  That is, if there are pending migrations the plugin produces a clear message explaining that the database is out of date and lists the pending migrations.  Run <code>mvn test</code> and see something like this:</p>
<p>[INFO] &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
[INFO] Building Gearlist &#8211; Data Access<br />
[INFO]    task-segment: [test]<br />
[INFO] &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
[INFO] [db-migration:check {execution: default}]<br />
[INFO] Checking jdbc:mysql://localhost/gearlist_test using migrations at src/main/db/migrations/.<br />
[INFO] Loaded JDBC driver: com.mysql.jdbc.Driver<br />
[WARNING] There are 2 pending migrations:</p>
<p>    20100116010256_audit_tracking.sql<br />
    20100121052539_add_daily_reports.sql</p>
<p>    Execute db-migration:migrate to apply pending migrations.<br />
[INFO] &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
[ERROR] BUILD ERROR<br />
[INFO] &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
[INFO] There are 2 pending migrations, migrate your db and try again.</p>
<p>It&#8217;s very easy to include the check goal in your build lifecycle if you&#8217;re already using the db-migration-maven-plugin.</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
...
&amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
        &amp;lt;plugin&amp;gt;
            &amp;lt;groupId&amp;gt;com.carbonfive.db-support&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;db-migration-maven-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;0.9.9-m2&amp;lt;/version&amp;gt;
            &amp;lt;executions&amp;gt;
                &amp;lt;execution&amp;gt;
                    &amp;lt;phase&amp;gt;validate&amp;lt;/phase&amp;gt;
                    &amp;lt;goals&amp;gt;
                        &amp;lt;goal&amp;gt;check&amp;lt;/goal&amp;gt;
                    &amp;lt;/goals&amp;gt;
                &amp;lt;/execution&amp;gt;
            &amp;lt;/executions&amp;gt;
            &amp;lt;configuration&amp;gt;
                &amp;lt;url&amp;gt;jdbc:mysql://${db.host}/${db.name}&amp;lt;/url&amp;gt;
                &amp;lt;username&amp;gt;${db.username}&amp;lt;/username&amp;gt;
                &amp;lt;password&amp;gt;${db.password}&amp;lt;/password&amp;gt;
            &amp;lt;/configuration&amp;gt;
        &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
&amp;lt;/build&amp;gt;
</pre>
<p>Check out the <a href="http://code.google.com/p/c5-db-migration/">project home</a> for additional documentation and details.  There&#8217;s also a simple, complete <a href="http://svn.carbonfive.com/public/christian/migration-sample1/trunk/">example application</a> showing off this configuration.</p>
<p>Enjoy!<br />
Christian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2010/01/20/database-migrations-fail-when-database-is-out-of-date/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Secure Email with Spring&#8217;s JavaMailServer and Gmail</title>
		<link>http://blog.carbonfive.com/2009/11/12/secure-email-with-springs-javamailserver-and-gmail/</link>
		<comments>http://blog.carbonfive.com/2009/11/12/secure-email-with-springs-javamailserver-and-gmail/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 14:38:16 +0000</pubDate>
		<dc:creator>Alex Cruikshank</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=737</guid>
		<description><![CDATA[Both Carbon Five and my ISP have moved email management over to Gmail.  While this has been a net improvement for me as an end user, it&#8217;s made it a bit more difficult to configure my applications to send outgoing &#8230; <a href="http://blog.carbonfive.com/2009/11/12/secure-email-with-springs-javamailserver-and-gmail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Both Carbon Five and my ISP have moved email management over to <a href="http://gmail.com">Gmail</a>.  While this has been a net improvement for me as an end user, it&#8217;s made it a bit more difficult to configure my applications to send outgoing mail.  It isn&#8217;t hard to find <a href="http://www.codinglabs.com/blog/?p=4">examples</a> <a href="http://stackoverflow.com/questions/854493/problem-configuring-springs-mailsender-for-our-smtp-server-but-gmail-works">online</a> that explain how to configure Spring&#8217;s <a href="http://static.springsource.org/spring/docs/1.1.x/api/org/springframework/mail/javamail/JavaMailSender.html">JavaMailSender</a> to work with Gmail.  But none of the examples I&#8217;ve found provide a configuration that can be switched between Gmail and an open SMTP server with a few reasonable external properties (an important feature in an application that needs to be deployed in varied environments).  What&#8217;s worse, the configurations tend to differ with no rational provided for the necessary parameters.  So I spent some time with the source and a debugger and came up with a simplified solution:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
&amp;lt;bean id=&amp;quot;mailSender&amp;quot; class=&amp;quot;org.springframework.mail.javamail.JavaMailSenderImpl&amp;quot;&amp;gt;
  &amp;lt;property name=&amp;quot;defaultEncoding&amp;quot; value=&amp;quot;UTF-8&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;host&amp;quot; value=&amp;quot;${mail.host}&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;port&amp;quot; value=&amp;quot;${mail.port}&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;protocol&amp;quot; value=&amp;quot;${mail.protocol}&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;username&amp;quot; value=&amp;quot;${mail.username}&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;password&amp;quot; value=&amp;quot;${mail.password}&amp;quot;/&amp;gt;
  &amp;lt;property name=&amp;quot;javaMailProperties&amp;quot;&amp;gt;
    &amp;lt;props&amp;gt;
      &amp;lt;prop key=&amp;quot;mail.debug&amp;quot;&amp;gt;${mail.debug}&amp;lt;/prop&amp;gt;
      &amp;lt;prop key=&amp;quot;mail.${mail.protocol}.auth&amp;quot;&amp;gt;${mail.smtp-auth}&amp;lt;/prop&amp;gt;
    &amp;lt;/props&amp;gt;
  &amp;lt;/property&amp;gt;
&amp;lt;/bean&amp;gt;
</pre>
<p>The properties for an open server look something like this:</p>
<pre class="brush: plain; light: true; title: ; wrap-lines: false; notranslate">mail.host       = localhost
mail.port       = 25
mail.protocol   = smtp
mail.smtp-auth  = false
mail.username   =
mail.password   =
mail.debug      = false</pre>
<p>And the properties for gmail look something like this:</p>
<pre class="brush: plain; light: true; title: ; wrap-lines: false; notranslate">mail.host       = smtp.gmail.com
mail.port       = 465
mail.protocol   = smtps
mail.smtp-auth  = true
mail.username   = my.email@address.com
mail.password   = mypassword
mail.debug      = true</pre>
<p>The host, port, username, password and debug properties should be obvious.  The key is to change the protocol between &#8216;smtp&#8217; and &#8216;smpts&#8217;.  The only real difference between smtp and smtps is that the later causes JavaMail&#8217;s SMTPTransport object to open an SSL socket to the server.  Gmail only accepts SSL connections on port 465.  After figuring this out, I was glad to see that Gmail was accepting my connections, but immediately frustrated to find that JavaMail was no longer attempting to authenticate before sending mail.  The trick is that JavaMail checks its transport related parameters under &#8216;mail.[protocol].[parameter]&#8216;.  This appears to be an entirely <a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html">undocumented</a> feature of JavaMail.  Fortunately, we can substitute the protocol name into the parameter key as well, so our auth parameter still works with either &#8216;smtp&#8217; or &#8216;smtps&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/11/12/secure-email-with-springs-javamailserver-and-gmail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C5 Test Support new addition: FunctionalTestRunner</title>
		<link>http://blog.carbonfive.com/2009/10/28/c5-test-support-new-addition-functionaltestrunner/</link>
		<comments>http://blog.carbonfive.com/2009/10/28/c5-test-support-new-addition-functionaltestrunner/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 18:54:03 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=702</guid>
		<description><![CDATA[We&#8217;re always looking for new ways to test our applications and we&#8217;ve been trying a few new things on our projects. One of the recent additions is a JUnit test runner designed to help make writing and running functional tests &#8230; <a href="http://blog.carbonfive.com/2009/10/28/c5-test-support-new-addition-functionaltestrunner/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re always looking for new ways to test our applications and we&#8217;ve been trying a few new things on our projects.  One of the recent additions is a JUnit test runner designed to help make writing and running functional tests easier.  In Javaland, we use Selenium and/or HtmlUnit for our functional tests.  These are the tests that run against a deployed application over the wire using a real or simulated browser.  Most of our functional tests work the application in the same way a real user would, testing sequences of realistic activity and often touching a number of pages.  Since our functional tests use either a real browser or a simulated one, Javascript is executed and assertions made on the results.  This gives us greater confidence that our app is really working, end to end.</p>
<p>Here&#8217;s the high-level flow that the functional test runner provides:</p>
<ol>
<li>Load fixture data from a DBUnit dataset.</li>
<li>Download and install the application server (if necessary).</li>
<li>Start the application server (using Cargo).</li>
<li>Deploy the application, waiting until it&#8217;s completely started.</li>
<li>Run one or more functional tests (using your preferred testing framework &#8211; Selenium, HTMLUnit, etc)&#8230;<br />
If a test dirties the database in a manner that must be reset, the test class can be marked with the @DirtiesDatabase annotation.  This will reload the database fixture and optionally restart the application.</li>
<li>Shutdown the application server.</li>
</ol>
<p><span id="more-702"></span><br />
It&#8217;s easy to use&#8230;  First add the maven dependency:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
  ...
  &amp;lt;repositories&amp;gt;
      &amp;lt;repository&amp;gt;
          &amp;lt;id&amp;gt;c5-public-repository&amp;lt;/id&amp;gt;
          &amp;lt;name&amp;gt;Carbon Five Public Repository&amp;lt;/name&amp;gt;
          &amp;lt;url&amp;gt;http://mvn.carbonfive.com/public&amp;lt;/url&amp;gt;
       &amp;lt;/repository&amp;gt;
  &amp;lt;/repositories&amp;gt;
  ...
  &amp;lt;dependency&amp;gt;
      &amp;lt;groupId&amp;gt;com.carbonfive.test-support&amp;lt;/groupId&amp;gt;
      &amp;lt;artifactId&amp;gt;test-support&amp;lt;/artifactId&amp;gt;
      &amp;lt;version&amp;gt;0.9.2-m1&amp;lt;/version&amp;gt;
      &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
  &amp;lt;dependency&amp;gt;
  ...
</pre>
<p>And then write your first functional test:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
@RunWith(FunctionalTestRunner.class)
public class FunctionalTestRunnerTest
{
    // This field is automatically injected by the test runner and references
    // the functional test properties (see below).
    private Properties properties;

    @Test
    public void propertiesShouldBeSetByRunner()
    {
        assertThat(properties, not(nullValue()));
        assertThat(properties.size(), greaterThan(5));
    }

    @Test
    public void applicationShouldBeDeployed() throws Exception
    {
        // Test using your preferred framework... just using URL as an example.
        URL root = new URL(format(&amp;quot;http://localhost:%s/&amp;quot;, properties.getProperty(&amp;quot;appserver.port&amp;quot;)));
        String content = IOUtils.toString(root.openStream());
        assertThat(content, containsString(&amp;quot;Orange&amp;quot;));
    }
}
</pre>
<p>Lastly, create the  configuration file that goes along with it.  By default, it&#8217;s called functional-test.properties and lives at the root of the classpath (src/test/resources/ for maven users).  Here&#8217;s an example:</p>
<p># Application server<br />
appserver.container         = tomcat6x<br />
appserver.installer         = http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip<br />
appserver.port              = 8080<br />
appserver.logging           = false</p>
<p># Application configuration<br />
app.war                     = ./gearlist-webapp/target/gearlist-webapp-1.0-SNAPSHOT.war<br />
app.context                 = ROOT</p>
<p># Database fixtures<br />
fixture.restart_application = false<br />
fixture.file                = classpath:/database-fixture.xml</p>
<p># Application configuration (not used by the functional test runner)<br />
db.driver                   = com.mysql.jdbc.Driver<br />
db.host                     = localhost<br />
db.name                     = gearlist_func_test<br />
db.url                      = jdbc:mysql://${db.host}/${db.name}<br />
db.username                 = root<br />
db.password                 =</p>
<p>Property values can reference other properties (e.g. db.url) and they&#8217;re all set as system properties so it&#8217;s easy to override your application properties for functional testing.</p>
<p>Both the database fixture loading and the application server steps can be customized by plugging in a new <a href="http://code.google.com/p/c5-test-support/source/browse/trunk/src/main/java/com/carbonfive/test/functional/DatabaseFixtureLoader.java">DatabaseFixtureLoader</a> or <a href="http://code.google.com/p/c5-test-support/source/browse/trunk/src/main/java/com/carbonfive/test/functional/ApplicationServerManager.java">ApplicationServerManager</a>, respectively.</p>
<p>Since it&#8217;s a JUnit extension, functional tests run exactly the same whether they&#8217;re triggered from the IDE or the command line.  This approach is a response to how clunky it felt using Maven to launch the application server before running the tests.  Also, with only one master orchestrator, it&#8217;s easier to handle redeploying the application if necessary.</p>
<p>Want to see a real example?  I&#8217;ve written a sample application called &#8220;gearlist&#8221; that&#8217;s available via <a href="http://svn.carbonfive.com/public/christian/gearlist/trunk">public svn</a> (press cancel if asked for authentication credentials).  It includes several HtmlUnit and Selenium functional tests, as well as other types of tests using some of the other test utils I&#8217;ve written.  Look for the readme for details.</p>
<p><a href="http://code.google.com/p/c5-test-support/">Carbon Five Test Support</a> is hosted on google code, where you can read what documentation there is and peruse the source.</p>
<p>There are a few things to work on, including better exception handling during initialization and some flexibility around the Cargo configuration, however, it&#8217;s pretty stable and there&#8217;s no reason not to use it now.  Give it it try and give me your feedback.  The plan is to tighten it up and write some documentation for the 0.9.2 release.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/10/28/c5-test-support-new-addition-functionaltestrunner/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Application Testing @ SDForum October 6th</title>
		<link>http://blog.carbonfive.com/2009/09/26/web-application-testing-sdforum-october-6th/</link>
		<comments>http://blog.carbonfive.com/2009/09/26/web-application-testing-sdforum-october-6th/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 11:20:07 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=675</guid>
		<description><![CDATA[Updated: Added links to presentation and source code. I&#8217;ll be down in Palo Alto speaking about Automated Web Application Testing Tuesday October 6th. If you&#8217;re interest in getting a peek at the typical Carbon Five Java web architecture along with &#8230; <a href="http://blog.carbonfive.com/2009/09/26/web-application-testing-sdforum-october-6th/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Updated: Added links to presentation and source code.</strong></p>
<p>I&#8217;ll be down in Palo Alto speaking about Automated Web Application Testing Tuesday October 6th.  If you&#8217;re interest in getting a peek at the typical Carbon Five Java web architecture along with a variety of strategies and techniques for testing, c&#8217;mon down and join us.  The session will be primarily code-driven.  I&#8217;ll implement a few features along with unit, integration and functional tests and show off some of the techniques and custom tools that help keep things simple and easy during development.  Some of the topics include:</p>
<ul>
<li>Brief overview of our typical web architecture and tools stack</li>
<li>Differences between Unit, Integration and Functional Tests</li>
<li>Dealing with the database (schema and fixtures)</li>
<li>Where does test coverage pay off the most?</li>
<li>In-browser and out-of-browser functional testing</li>
<li>Carbon Five best practices, custom tools and techniques</li>
<li>And more&#8230;</li>
</ul>
<p>You can find the gritty details on the <a href="http://www.sdforum.org/index.cfm?fuseaction=Calendar.eventDetail&amp;eventID=13525">SDForum site</a>.</p>
<p>Doors at 6:30 and the show begins at 7:00.  Hope to see you there!</p>
<h3>Here are the artifacts from the presentation:</h3>
<ul>
<li><a href="http://svn.carbonfive.com/public/christian/gearlist/branches/sdforum/docs/Web%20Application%20Testing.pdf">Presentation (.pdf)</a></li>
<li><a href="http://svn.carbonfive.com/public/christian/gearlist/branches/sdforum/">Source Code (svn)</a></li>
<li><a href="http://svn.carbonfive.com/public/christian/gearlist/branches/sdforum/docs/readme.txt">Build and Run Instructions (readme.txt)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/09/26/web-application-testing-sdforum-october-6th/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SmartyCard Launches!</title>
		<link>http://blog.carbonfive.com/2009/03/18/smartycard-launches/</link>
		<comments>http://blog.carbonfive.com/2009/03/18/smartycard-launches/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 16:49:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Clients]]></category>
		<category><![CDATA[Flex/Flash]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=564</guid>
		<description><![CDATA[Our client SmartyCard launched in early March at the DEMO conference picking up the People&#8217;s Choice Award.  SmartyCard is a learning site that offers kids rewards for completing a variety of interactive learning games.  Kids are able to &#8216;learn, earn &#8230; <a href="http://blog.carbonfive.com/2009/03/18/smartycard-launches/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Our client <a href="http://www.smartycard.com" target="_blank">SmartyCard</a> launched in early March at the DEMO conference picking up the People&#8217;s Choice Award.  SmartyCard is a <a href="http://springwise.com/education/smartycard/" target="_blank">learning site that offers kids rewards for completing a variety of interactive learning games</a>.  Kids are able to &#8216;learn, earn and play&#8217; grade-appropriate games while earning real and virtual rewards.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/03/18/smartycard-launches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stripes: A Successful First Project</title>
		<link>http://blog.carbonfive.com/2009/02/26/stripes-a-succesful-first-project/</link>
		<comments>http://blog.carbonfive.com/2009/02/26/stripes-a-succesful-first-project/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 12:12:47 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[stripes]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=301</guid>
		<description><![CDATA[We&#8217;re wrapping up a project that I&#8217;ve been leading since September and I&#8217;ve been reflecting on some of my decisions. Some of this reflection might be interesting to other developers. There are a few things on my mind, but I&#8217;ll &#8230; <a href="http://blog.carbonfive.com/2009/02/26/stripes-a-succesful-first-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re wrapping up a project that I&#8217;ve been leading since September and I&#8217;ve been reflecting on some of my decisions.  Some of this reflection might be interesting to other developers.  There are a few things on my mind, but I&#8217;ll start off off with my decision to use <a href="http://stripesframework.org">Stripes</a> as our MVC instead of our usual, Spring MVC.</p>
<h3>Background</h3>
<p>I&#8217;ve never been completely satisfied with Spring MVC (note that it&#8217;s pretty hard to win me over completely).  We know it well and we&#8217;ve had many successful projects while using it.  We&#8217;ve also used many of the new features that came along with Spring 2.5 (@Controller, more convention over configuration, etc), but in the end I still wasn&#8217;t loving it.</p>
<p>I came across Stripes over a year ago, and noted that it had a small but fairly vibrant and excited community.  The projects goals definitely resonated with me:</p>
<ul>
<li>Make developing web applications in Java easy</li>
<li>Provide simple yet powerful solutions to common problems</li>
<li>Make the Stripes ramp up time for a new developer less than 30 minutes</li>
<li>Make it really easy to extend Stripes, without making you configure every last thing</li>
</ul>
<p>So I decided to give it a try on a real project.  Switching from something we know inside and out to something that none of us had production experience with was arguably risky, so we decided to give it a try for a week with the intention that we&#8217;d go back to Spring MVC if anything took too long or felt awkward.  Thankfully, that never happened.</p>
<p>Some of this article may read a bit like a Stripes versus Spring MVC comparison.  That&#8217;s not really my  intention, but it&#8217;s somewhat inevitable as much of my experience has been with Spring MVC.  This isn&#8217;t intended to be a Stripes tutorial (there are great ones out there), so the code snippets and technical details will be sparse.</p>
<h3>Controller Lifecycle, Binding, and the Model</h3>
<p>Stripes controllers are called &#8220;Actions&#8221; or &#8220;ActionBeans&#8221; and each incoming HTTP request is routed to one primary Action (like Spring MVC).  Stripes creates a new Action instance for each incoming request; Spring Controllers are singletons in comparison.  Stripes binds parameters into the fields on the Action where Spring MVC passes them as method parameters.  The Stripes Action is not only the &#8220;Controller&#8221; in the MVC, but it also serves as the root of the &#8220;Model&#8221; as well.  The Action is made available to the View and all properties with getters can be queried using JSP-EL.  Spring&#8217;s model is separate, necessitated by the Singleton nature of the Controller.</p>
<p>Let&#8217;s look at a simple example:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
// URI and embedded parameters defined using CleanURLs
@UrlBinding(&amp;quot;/status/{orderId}/{$event}&amp;quot;)
public class OrderStatusAction extends AbstractActionBean
{
    // Spring managed service to be dependency injected (see &amp;quot;Worth Mentioning&amp;quot; below)
    @Autowired OrderService orderService;

    // Required incoming parameter bound in the URI with {orderId}
    @Validate(required = true, minvalue = 1) long orderId;

    // OrderStatus to be accessible from the view for rendering
    OrderStatus orderStatus;

    // public setter tells stripes to allow binding
    public void setOrderId(long orderId) { this.orderId = orderId; }

    // public getter tell stripes to allow access from the view
    public OrderStatus getOrderStatus() { return orderStatus; }

    public Resolution view()
    {
        orderStatus = orderService.getOrderStatus(orderId);
        if (orderStatus == null) return new ErrorResolution(404);
        return new ForwardResolution(&amp;quot;/WEB-INF/jsp/order-status.jsp&amp;quot;);
    }
}
</pre>
<p>In our view we can access the Action / Model:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
...
&amp;lt;jsp:useBean id=&amp;quot;actionBean&amp;quot; scope=&amp;quot;request&amp;quot; type=&amp;quot;eg.OrderStatusBean&amp;quot;/&amp;gt;
...
&amp;lt;li&amp;gt;Order Number: ${actionBean.orderStatus.order.id}&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;Status: ${actionBean.orderStatus.status}&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;Tracking Number: ${actionBean.orderStatus.trackingNumber}&amp;lt;/li&amp;gt;
...
</pre>
<p>This example binds to a long, which is pretty simple.  Stripes can bind into graphs of objects, instantiating them along the way if necessary.  Collections are fully supported as well.  We haven&#8217;t yet found an example of something we couldn&#8217;t bind into right out of the box.</p>
<p>While I first was resistant to the Stripes lifecycle and combination of Controller and Model, I soon warmed up to it and now I find it quite natural, a bit better from a code readability standpoint, and more aesthetic.  It&#8217;s just the right amount of abstraction and encapsulation to make for speedy development while being easy to maintain.  I really like the fact that new instances of actions are created for each request, because the alternative is to pass all of your state into a handler method, which can easily lead hard-to-read code, especially with the annotations required to describe which request parameter maps to which method parameter.</p>
<p>If you can&#8217;t bind directly into your value objects and entities, the Action gives you a great place to bind into first, allowing you to manually instantiate your domain objects plugging in values from the Action.  This is quite useful when your domain model isn&#8217;t direct-binding friendly because of invariant enforcing, immutable value objects, and other practices encouraged by <a href="http://domaindrivendesign.org/">Domain Driven Design</a>.</p>
<p>We keep our Actions simple and lightweight, deferring all non-display logic to transactional, spring-managed services.  I&#8217;ve seen examples where Actions are directly interacting with the database, a pattern I discourage.</p>
<p>If you want to know more about how Stripes works, check out the references section at the end of this article.</p>
<h3>Generating URIs in Views</h3>
<p>I can&#8217;t tell you how many times I&#8217;ve run into regressions after making changes to URIs where a page would link to a controller at the wrong URI.  With Stripes, your URIs are defined once and only once, so when you change where an Action lives, pages will link to it correctly at its new location.  Stripes tags take a <code>beanclass</code> argument so that it can determine the correct URI at runtime rather than hard-coding it in the view.</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">
&amp;lt;stripes:link beanclass=&amp;quot;eg.OrderStatusAction&amp;quot; event=&amp;quot;view&amp;quot;&amp;gt;
  &amp;lt;stripes:param name=&amp;quot;orderId&amp;quot; value=&amp;quot;65432&amp;quot;/&amp;gt;
  View Order Status
&amp;lt;/stripes:link&amp;gt;
</pre>
<p>Renders: &lt;a href=&quot;http://example.com/status/65432/view&quot;&gt;View Order Status&lt;/a&gt;</p>
<p>The &lt;stripes:url &#8230;/&gt; and &lt;stripes:form &#8230;/&gt; tags work the same way.  To round it out, Actions can forward or redirect to other Actions without embedding URIs:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
return new ForwardResolution(OrderHistoryAction.class, &amp;quot;view&amp;quot;).
return new RedirectResolution(OrderHistoryAction.class, &amp;quot;view&amp;quot;).
</pre>
<p>The net result is that there&#8217;s a single definition of each URI in our system and it lives on the Action which handles that URI, realizing the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">Don&#8217;t Repeat Yourself (DRY)</a> principle.  We&#8217;ve been able able to change our URIs easily without fear of breaking views, which has been helpful as the project grows.</p>
<h3>Configuration</h3>
<p>Stripes only needs a few lines of configuration in your web.xml.  That&#8217;s it (really).  Stripes was built with convention over configuration in mind from day one.  Actions and Extensions (Converters, Formatters, Interceptors, etc) are auto-discovered via classpath scanning.  We never found ourselves needing to configure something differently than how it was out of the box.</p>
<p>While you can configure Spring MVC to be convention based (it&#8217;s okay to chuckle at this too), it&#8217;s not that way out of the box.  Perhaps Spring 3.0 will change this, but I have the sense that no matter what, there will always be some evidence of the fact that Spring MVC&#8217;s internals allow a wide range of configuration.</p>
<h3>Converters and Formatters</h3>
<p>In other frameworks, these concepts are often conflated into a single class.  Stripes converters do one thing: convert from strings to objects (e.g. phone numbers, zip codes, etc).  Whenever you need to turn an incoming request parameters into something more than a string, the converter is there to help.</p>
<p>Formatters work the other way, formatting objects into something that looks right on the screen as text.  Formatters can support multiple format types, so that you can support displaying objects differently when necessary (e.g. phone with extension, zip code with a plus 4, etc).</p>
<p>These helpers are simple to write and test.  All of the stripes tags will use them if they&#8217;re present, so it&#8217;s easy to affect how something &#8212; phone numbers for example &#8212; are displayed across the entire application.</p>
<h3>Testing</h3>
<p>There&#8217;s no reference to the servlet API in your Action classes, so it&#8217;s easy to write tests against the Java code within.  Tests fall into two categories: very lightweight unit tests which only test what&#8217;s happening in your handler and slightly more heavy-weight tests which involve more of the stack (but not the servlet container).</p>
<p>The outline for a unit test goes something like this:</p>
<ol>
<li>Instantiate your Action</li>
<li>Inject service stubs/mocks</li>
<li>Use the public setters to specify values to necessary fields</li>
<li>Invoke the handler</li>
<li>Assert on the Resolution and the state of the Action (optionally your Stub)</li>
</ol>
<p>Note that all of our Action tests fall into this category, even though you can test more of the stack (URL binding and validation).</p>
<p>What you can&#8217;t do &#8212; I haven&#8217;t seen any Java MVC provide this though &#8212; is write tests against the rendered markup of your views (a la Rails) without bringing up the servlet container.</p>
<p>Read more about <a href="http://stripesframework.org/display/stripes/Unit+Testing">testing with Stripes here</a>.</p>
<h3>Documentation and Community</h3>
<p>The Stripes documentation is definitely not very complete or polished.  Some of the documentation is out of date or non-existent (e.g. CleanURLs).  The same goes for the examples.  There is a decent book from Pragmatic Programmers press however, which I recommend if you&#8217;re interested in Stripes.</p>
<p>The good news is that despite all of this, it&#8217;s easy enough to find or figure out what you need without too much fuss.  Piecing together examples, tutorials, bogs, documentation, etc ultimately gives you what you need.  The <a href="http://stripes.svn.sourceforge.net/viewvc/stripes/">Stripes source</a> is small enough that you can rummage through to see how things work easily.  It&#8217;s not as configurable as Spring MVC so the code is less abstract and a little easier to grok (though it&#8217;s not as elegant).</p>
<p>There is an active mailing list where the developers and other users help out with questions.</p>
<h3>Conclusion</h3>
<p>I think working with Stripes is a lot of fun and that we made the right decision to use it.  I&#8217;d go as far as saying that we were at least as productive with it as we would have been with Spring MVC, and it&#8217;s likely we were more productive.  I&#8217;d say that the authors have largely delivered on their goals.  One of our front-end developers quickly dove right into building Actions without much help from other developers.  While we had the occasional &#8220;Huh?!&#8221; moment while trying to figure out why something wasn&#8217;t working, they were few and far between.</p>
<p>In comparing it to Spring MVC, I think there&#8217;s a simplicity and elegance to Stripes that comes from it being just an MVC and it not having the same legacy as Spring.  While Spring MVC has certainly evolved, it&#8217;s brought some of its crufty parts along with it.  I&#8217;ll be keeping an eye on Spring MVC to see what&#8217;s in store with 3.0, and I hope to be proven wrong.</p>
<p>There&#8217;s no doubt that Stripes is in a niche as compared to many of the other web frameworks.  The community is much smaller, and the development cycle much longer (last release was August 2008 and the one before that May 2007), which sometimes makes me wonder what Stripes future holds.</p>
<p>I&#8217;d say that one downside to Stripes, or any other framework that has a single backing Action per URI, is that there isn&#8217;t a great story for dealing with pages that aggregate a number of features and those features also show up on other pages.  The problem is that we can&#8217;t rely on the Action to provide all of the reference data, so we have to rely on other mechanisms for fetching it (filters, interceptors, tags, etc).  It&#8217;s not an issue with Stripes specifically, but all framework with the same approach.</p>
<p>For projects where this single primary controller per URI limitation isn&#8217;t a problem, I would definitely use Stripes again and I think it&#8217;s a framework Java developers should look into if they aren&#8217;t completely happy with whatever they&#8217;re using.</p>
<h3>Also Worth Mentioning&#8230;</h3>
<p>There are lots of other neat features in Stripes too: validation annotations and helper methods, <a href="http://stripesframework.org/display/stripes/Layout+Reuse">stripes layout</a>, <a href="http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/FlashScope.html">flash scope</a>, wizard forms, encrypted parameters, a <a href="http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/ajax/JavaScriptResolution.html">JavaScriptResolution</a> for serializing Java objects to JavaScript, etc.  Open up the Stripes jar and start looking around.</p>
<p>Our application is using Spring as an IoC container for everything behind our Actions; to get handles to your Spring managed services we use a <a href="http://blog.carbonfive.com/2008/03/java/injecting-spring-25-beans-into-stripes-actions">simple Stripes Interceptor which injects dependencies into Actions</a>.</p>
<p>When using CleanURLs, you&#8217;ll want to use the <a href="http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/DynamicMappingFilter.html">DynamicMappingFilter</a>, though there&#8217;s not much mention of it in the documentation.  CleanURLs in Stripes 1.5.1 should be even more flexible (see <a href="http://www.stripesframework.org/jira/browse/STS-617">STS-617</a>).</p>
<p>We used Spring Security on our application found that Stripes and Spring Security play nicely together.</p>
<p>Spring 3.0 will include a few new features that are similar to features I really like in Stripes, including RESTy URLs, and tags for generating the URIs to controllers.  The downside is that it&#8217;s still using the singleton model, which equates to controller handler methods with potentially lots of annotated parameters.</p>
<h3>References</h3>
<ul>
<li><a href="http://stripesframework.org">Stripes Homepage</a></li>
<li><a href="http://www.amazon.com/Stripes-development-Pragmatic-Programmers/dp/1934356212">Stripes by Federick Daoud</a></li>
<li><a href="http://stripesframework.org/display/stripes/2008/08/18/Stripes+1.5+Release+Available">Summary of Stripes 1.5 New Features</a></li>
<li><a href="http://greggbolinger.blogspot.com/2008/01/stripes-15-feature-clean-urls.html">CleanURLs Features</a></li>
<li><a href="http://www.devx.com/Java/Article/39199">Stripes in Black and White</a></li>
<li><a href="http://www.gridshore.nl/2008/12/13/using-stripes-as-a-webmvc-framework-without-that-thing-called-xml/">Using Stripes as a webmvc framework without that thing called xml</a></li>
<li><a href="http://plugins.intellij.net/plugin/?id=1528">IntelliStripes &#8211; IntelliJ IDEA Plugin</a></li>
<li><a href="http://github.com/knifhen/javarebel-stripes-plugin/tree/master">Stripes JavaRebel Plugin</a></li>
<li><a href="http://blog.springsource.com/2008/12/05/spring-framework-30-m1-released/">Spring 3.0 M1 Features</a> and <a href="http://blog.springsource.com/2009/02/25/spring-framework-30-m2-released/">Spring 3.0 M2 Features</a></li>
<li><a href="http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/">Spring 3.0 MVC Features</a></li>
</ul>
<p>Updates: added reference to recently published Spring 3.0 MVC blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/02/26/stripes-a-succesful-first-project/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>More fun with Java Concurrency: BlockingQueue</title>
		<link>http://blog.carbonfive.com/2009/02/23/more-fun-with-java-concurrency-blockingqueue/</link>
		<comments>http://blog.carbonfive.com/2009/02/23/more-fun-with-java-concurrency-blockingqueue/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 10:35:59 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=308</guid>
		<description><![CDATA[I&#8217;ve written about Java 5 concurrency in the past and I&#8217;ve recently had the opportunity to make use of another one of the concurrency constructs: the BlockingQueue. The Problem There&#8217;s a problem we&#8217;ve seen a few times in the last &#8230; <a href="http://blog.carbonfive.com/2009/02/23/more-fun-with-java-concurrency-blockingqueue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written about Java 5 concurrency <a href="http://blog.carbonfive.com/2008/05/testing/multithreaded-testing">in the past</a> and I&#8217;ve recently had the opportunity to make use of another one of the concurrency constructs: the <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html">BlockingQueue</a>.</p>
<h3>The Problem</h3>
<p>There&#8217;s a problem we&#8217;ve seen a few times in the last few years.  From time to time, applications must import data from external systems and massage it into a form that is useful.  Sometimes these feeds are streamed over the net while other times they&#8217;re in the form of massive text files.  My current project has two such feeds that are imported on a weekly basis, the larger of the two rings in at around 10M entities.</p>
<p>Loading the data is pretty straightforward: entities are parsed from the source, a transient entity object is instantiated and the parsed values plugged in, entities are batched up and then persisted as a batch.</p>
<h3>The Collaborators</h3>
<p>The Parser is responsible for loading records one at a time from the source.</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
public interface Parser
{
    boolean hasNextRecord();
    T nextRecord();
    void close();
}
</pre>
<p>The Persister is responsible for saving batches of entities.</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
public interface Persister
{
    void initializeFeed();
    void insertBatch(List entities);
    void finalizeFeed();
}
</pre>
<p>And the FeedLoader is the glue that pulls it all together, it coordinates parsing records into a batch and then triggering persisting the batches when they&#8217;re ready.  It&#8217;s used like this, where 1000 is the batch size:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
Parser parser = new WombatParser(inputStream);
Persister persister = new WombatPersister(dataSource);
FeedStats stats = new FeedLoader(parser, persister, 1000).loadData();
</pre>
<p>Now that the stage is set and we&#8217;ve covered the parts, we can get into what happens behind loadData().</p>
<h3>Synchronous Parsing and Persistence</h3>
<p>Our first cut of loadData() was a simple synchronous implementation:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
public class FeedLoader
{
    private Parser parser;
    private Persister persister;
    private int batchSize;

    public FeedLoader(Parser parser, Persister persister, int batchSize)
    {
        Validate.isTrue(batchSize &amp;gt; 0);
        this.parser = parser;
        this.persister = persister;
        this.batchSize = batchSize;
    }

    public FeedStats loadData()
    {
        persister.initializeFeed();
        List entities = new ArrayList(batchSize);

        while (parser.hasNextRecord())
        {
            entities.add(parser.nextRecord());
            if (entities.size() &amp;gt;= batchSize)
            {
                persister.insertBatch(entities);
                entities.clear();
            }
        }

        // Save the stragglers that didn't make it into the last batch.
        if (!entities.isEmpty())
        {
            persister.insertBatch(entities);
        }

        parser.close();
        persister.finalizeFeed();
        return new FeedStats(...);
    }
}
</pre>
<p>This worked well&#8230; we were able to process records at a throughput of about 3125 per second.  After a bit of research I realized we were spending nearly as much time parsing records as we were persisting them.  I also noticed that the load on the machine was pretty low during the import process.  While there is a relationship between parsing and persisting, it seemed like there should be an easy way split the processes across multiple threads while keeping the code simple and readable.</p>
<h3>Asynchronous processing with BlockingQueue and ExecutorService</h3>
<p>Digging through java.util.concurrent, I came across BlockingQueue which is described as &#8220;A Queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.&#8221;  Sounds like a great construct to bridge the gap between our Parser and Persister threads.  The parser can add entities to the queue while the persister is pulling them off into batches.  Let&#8217;s see what it looks like:</p>
<pre class="brush: java; light: true; title: ; wrap-lines: false; notranslate">
public class FeedLoader
{
    private Parser parser;
    private Persister persister;
    private int batchSize;
    private boolean done = false;

    public FeedLoader(Parser parser, Persister persister, int batchSize)
    {
        Validate.isTrue(batchSize &amp;gt; 0);
        this.parser = parser;
        this.persister = persister;
        this.batchSize = batchSize;
    }

    public FeedStats loadData()
    {
        persister.initializeFeed();

        BlockingQueue blockingQueue = new ArrayBlockingQueue(batchSize * 2);
        try
        {
            ExecutorService executorService = Executors.newFixedThreadPool(2);
            // invokeAll() blocks until both tasks have completed
            executorService.invokeAll(
                asList(new ParserTask(parser, blockingQueue),
                       new PersisterTask(persister, blockingQueue)));
            executorService.shutdown();
        }
        catch (InterruptedException e)
        {
            log.error(&quot;Failed to load feed.&quot;, e);
            throw new RuntimeException(&quot;Failed to load feed.&quot;, e);
        }

        persister.finalizeFeed();
        return new FeedStats(...);
    }

    class ParserTask implements Callable
    {
        Parser parser;
        BlockingQueue queue;

        ParserTask(Parser parser, BlockingQueue queue)
        {
            this.parser = parser;
            this.queue = queue;
        }

        public Object call()
        {
            while (parser.hasNextRecord())
            {
                try
                {
                    queue.put(parser.nextRecord());
                }
                catch (InterruptedException e)
                {
                    log.error(&quot;Failed to load feed.&quot;, e);
                    throw new RuntimeException(&quot;Failed to load feed.&quot;, e);
                }
            }
            parser.close();
            done = true; // Indicates that the parser is done.
            return null;
        }
    }

    class PersisterTask implements Callable
    {
        Persister persister;
        BlockingQueue queue;

        PersisterTask(Persister persister, BlockingQueue queue)
        {
            this.persister = persister;
            this.queue = queue;
        }

        public Object call()
        {
            List entities = new ArrayList(batchSize);

            // &quot;done&quot; is set to false when the parser is done, at which point
            // all remaining entities will be in the queue.
            while (!done || !queue.isEmpty())
            {
                try
                {
                    entities.add(queue.take());
                    if (entities.size() &amp;gt;= batchSize)
                    {
                        persister.insertBatch(entities);
                        entities.clear();
                    }
                }
                catch (InterruptedException e)
                {
                    log.error(&quot;Failed to load feed.&quot;, e);
                    throw new RuntimeException(&quot;Failed to load feed.&quot;, e);
                }
            }
            if (!entities.isEmpty())
            {
                persister.insertBatch(entities);
            }
            return null;
        }
    }
}
</pre>
<p>By allowing the parser and persister to run concurrently using two threads, the feed loaded with a throughput of 4608 entities per second, nearly a 50% improvement over the single threaded version.</p>
<p>There are two caveats to the code as written above: creating an ExecutorService for each loadData() isn&#8217;t ideal; it&#8217;s best to configure one for the application and resuse it, and also is must be shutdown before the application quits.  I&#8217;ve skimped on error handling, which is fine if the Parser and Persister implementations don&#8217;t throw exceptions.</p>
<h3>Conclusion</h3>
<p>The ExecutorService and BlockingQueue provide the tools to make this improvement easy while keeping the code pretty readable.  As always, we should be striving for readability, so adding unnecessary concurrency is never a good idea.  And your mileage may vary depending on many things, including the hardware, network, data, server load&#8230; so do some testing to measure the real improvement in production.</p>
<p>Even if you don&#8217;t end up using it, it&#8217;s fun to experiment with and learn about concurrency issues.  There are scenarios where the smart application of concurrency constructs can yield fantastic benefits.  Check our Greg Luck&#8217;s <a href="http://gregluck.com/blog/archives/2009/02/i_have_been_wai.html">recent blog on Ehcache performance</a> for an example.</p>
<p><em>Updates: added caveats and call to ExecutorService.shutdown().  Fixed a typo in the PersisterTask.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2009/02/23/more-fun-with-java-concurrency-blockingqueue/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Make the things you do often fast and easy</title>
		<link>http://blog.carbonfive.com/2008/09/10/make-the-things-you-do-often-fast-and-easy/</link>
		<comments>http://blog.carbonfive.com/2008/09/10/make-the-things-you-do-often-fast-and-easy/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 08:31:59 +0000</pubDate>
		<dc:creator>Christian Nelson</dc:creator>
				<category><![CDATA[Process]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rescue Mission]]></category>

		<guid isPermaLink="false">http://blog.carbonfive.com/?p=151</guid>
		<description><![CDATA[Many of our projects are &#8216;greenfield&#8217; and we have the opportunity to do things the way we like. By working on new projects every few months, as opposed to one project over the course of years, we have lots of &#8230; <a href="http://blog.carbonfive.com/2008/09/10/make-the-things-you-do-often-fast-and-easy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Many of our projects are &#8216;greenfield&#8217; and we have the opportunity to do things the way we like.  By working on new projects every few months, as opposed to one project over the course of years, we have lots of opportunity to easily tweak and tune the way we do things.  Not all of our projects are from scratch though (see Alon&#8217;s post about <a href="http://blog.carbonfive.com/2008/09/testing/rewrite-or-rescue">Rewrite or Rescue</a>), so we sometimes end up dealing with years worth of history and crufty code.  It&#8217;s safe to say that each time we roll onto one of these projects, there&#8217;s going to be some level of bewilderment regarding what developers deal with on a daily basis.</p>
<p>Maybe it&#8217;s because we have a special opportunity to optimize the hell out of our development process, or the fact that we&#8217;re all productivity junkies; regardless of the reason, we religiously embrace the tenant &#8220;Make the things you do often fast and easy&#8221;.  It&#8217;s almost embarrassing to suggest that others don&#8217;t also subscribe to this simple notion, but &#8212; brace yourself &#8212; many do not.  On a project that has history, not everyone has been there for every decision.  In fact, many developers are at least relatively new and it&#8217;s somewhat customary to have a &#8220;it must be this way for a reason&#8221; attitude.  After all, who would deliberately make something cumbersome without good reason?</p>
<p>When we start working on one of these projects, we dedicate time to do some serious spring cleaning and tackle the things that will cost us the most in terms of pain and productivity.  The whole development team gets psyched about where we end up as it&#8217;s a significant improvement.  Projects with a history usually have a fair bit of low-hanging fruit.  Let&#8217;s discuss some of the things we see regularly.</p>
<h2>Build Systems</h2>
<p>Apparently few people like working on build scripts and when they do they have a habit of lowering their standards for quality of work.  That&#8217;s obviously not literally true, but sometimes it seems that way.  We&#8217;ve seen a number of beastly build systems that are slow because they&#8217;re doing things that aren&#8217;t necessary (extraneous jaring, copying, code generating, etc), they&#8217;re brittle and expensive to maintain, and full of dead code and duplicate target definitions&#8230; and they&#8217;re run many times every single work day.  It&#8217;s true that most developers may be compiling code from their IDE and thus bypassing the command-line build, but it&#8217;s still run on the build server, by ops folks, and even by developers when they&#8217;re debugging why something works from the IDE but busts on the build server.</p>
<h3>Guidelines for simplifying the build</h3>
<ul>
<li>Distill the build process down to the fastest, simplest steps that are necessary.</li>
<li>Eliminate duplicate and no-longer used dependencies; these files are being copied around and bundled for no reason (I&#8217;ve seen over 15 megs of unnecessary dependencies before).</li>
<li>When a project is split into multiple modules (and it should if it&#8217;s more than a few thousand lines), modules should be built in a consistent fashion using targets that are shared across modules.</li>
<li>Look for exceptions.  When you see something special happening for a particular file type, file name, or modules, ask yourself why.  Ask again.  Strive to eliminate these special cases when possible, even if they seem trivial.</li>
<li>Build a single deployable (or deployables) for all environments by eliminating environment-specific build code and externalizing application configuration. (Use Spring?  Check out this <a href="http://blog.carbonfive.com/2008/04/java/configuring-applications-with-spring">post on externalizing configuration with Spring</a>.)</li>
<li>Look for unnecessary code generation steps; if generated code changes once a year then check it in and make regenerating a manual step.</li>
<li>If you generate code coverage data, make sure that it&#8217;s only created when it&#8217;s needed (e.g. a nightly build on the build server), not on every build.</li>
</ul>
<p>So, we use <a href="http://maven.apache.org/">Maven 2</a> for all of our Java projects.  For sure, it has its share of rough edges (most of which are being fixed at a reasonable rate).  But it recommends some very sound conventions and doesn&#8217;t provide any scripting functionality, so it&#8217;s harder to hack it to do anything too unorthodox (please don&#8217;t use the antrun plugin unless as an incremental step when moving from Ant to Maven).  When you play ball by the Maven rules you&#8217;ll find your build much simpler and easier to maintain.  It&#8217;s likely you&#8217;ll notice other emergent benefits to boot.  For example, once you migrate to Maven you eliminate duplicate build configuration (both your command line build tool and IDE know how to compile your app &#8212; remember the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a>).  <a href="http://www.jetbrains.com/idea/features/ant_maven.html">IDEA</a>, Eclipse (via <a href="http://m2eclipse.codehaus.org/">m2eclipse</a>), and NetBeans all support importing from and synchronize with Maven.</p>
<p>Some people use <a href="http://incubator.apache.org/buildr/">Buildr</a> or Ant + <a>Ivy</a>, but either they don&#8217;t have the breadth of use (Buildr) or are more susceptible to writing nasty, unmaintainable build code (Ant).  That&#8217;s why we use Maven.</p>
<h2>Compile &gt; Deploy &gt; Make Changes &gt; Deploy Development Cycle</h2>
<p>Possibly more important than a simple and easy build, developers must be able to go through the compile, deploy, make changes, deploy cycle <em>FAST</em> (note that the compile, run tests, make changes, run tests cycle is also <em>very</em> important).</p>
<p>I remember working on an embedded system in 1998: a complex radio communications routing application written in C++ and deployed to custom hardware running the real-time operating system <a href="http://en.wikipedia.org/wiki/PSOS">PSOS</a>.  The build and deploy cycle took about 30 minutes and there were only 10 hardware instances for 60 engineers; you had to sign up for time slot on real hardware.  It was the epitome of unproductive as far as development environments go (and don&#8217;t even ask about debugging!).  You&#8217;d think such things were completely in the past (luckily they mostly are), but they&#8217;re not completely.  In the last 2 years I&#8217;ve seen applications that take 15 minutes to deploy.</p>
<p>It&#8217;s a drag when developers have to wait for these things to happen and it can totally destroy one&#8217;s rhythm, keeping developers from getting into the zone.  What&#8217;s worse, it&#8217;s completely unnecessary with modern tools.</p>
<h3>General Suggestions</h3>
<ul>
<li>Don&#8217;t drop down to the command-line; compile and deploy from your IDE (the IDE is your friend &#8211; master it).</li>
<li>Minimize steps for deploying changes to a running app:
<ul>
<li>Your IDE may support building on frame deactivation (IDEA does); check it out.</li>
<li>Look into the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin">maven-jetty-plugin</a> if you use Maven.</li>
<li>Run in debug mode so that code can be hot-swapped or invest in <a href="http://www.zeroturnaround.com/javarebel/">JavaRebel</a>, which allows all sorts of code changes to take place without redeploying your application.</li>
<li>Deploy your application in exploded form; bundling a war or ear incurs unnecessary IO overhead.</li>
</ul>
</li>
<li>Host your database either locally on your workstation or on a beefy database server on the same LAN.  Remote databases are generally many times slower due to latency, even over fast connections.</li>
<li>Use JBoss?  Consider migrating to Jetty or Tomcat.  If that&#8217;s impossible, use the most stripped down profile (minimal, default, or all) that has what you need, or better yet, create a custom one which includes <em>only</em> what you need.</li>
<li>Minimize the amount of data needed in the database to run the application.  The same goes for running tests: do whatever it takes to run your tests against an empty (or very close to) schema. Check out the <a href="http://code.google.com/p/c5-db-migration/">Carbon Five DB Migration Project</a>.</li>
<li>Don&#8217;t skimp on developer hardware.  Buying the very fastest CPU isn&#8217;t going to be worth it, so aim for one or two models down from the fastest.  Buy the fastest hard disk you can since development is generally IO bound (WD Raptor and the new VelociRaptor are awesome, consider SSDs if your coffers run deep).  Avoid older CPU architectures (Pentium D), even when the clock speed (GHz) is faster.  Lastly, don&#8217;t be shy with memory; 4GB isn&#8217;t too much for a developer machine.</li>
</ul>
<p>In addition to these general recommendations, each individual application will have its own specific sources of inefficiency.  Many real world applications depend on services provided by application servers and/or a commercial products: message queues (JMS, ActiveMQ, etc), distributed caches (memcached, coherence, etc), enterprise service buses, job schedulers, work flow engines, etc.  It&#8217;s important that these services don&#8217;t get in the way of developing <em>fast</em>.  Some of them can be run in a light-weight development mode.  If you need to use one of these potentially heavyweight solutions, invest the time to minimize or eliminate any adverse effects to the development cycle.</p>
<h2>What Else?</h2>
<p>Some of the best improvements have nothing to do with the technical side of software development.  Take a step back and look at what else is happening (or not happening) each day.  There may be meetings which can be time boxed, consolidated, or eliminated all together.  Take a look at collaboration between engineers, product managers, testers, support and operations.  How long are developers waiting to have requirements-clarifying questions answered?  Ask your whole team where they think things can be improved.  Ask for feedback on a regular basis and allow it to help drive these improvements.</p>
<h3>Survey of other activities that should be fast and easy</h3>
<ul>
<li>Running the automated test suite &#8211; &lt; 10 minutes</li>
<li>Getting build results from continuous integration server &#8211; &lt; 10 minutes</li>
<li>Pushing a build to staging/acceptance server &#8211; One click build and deploy</li>
<li>Create a new instance of a minimal database instance &#8211; <a href="http://code.google.com/p/c5-db-migration/">Carbon Five DB Migration Project</a></li>
<li>Recreate production state in development for debugging</li>
<li>Story approval/acceptance &#8211; Continuous acceptance</li>
<li>Meetings &#8211; Timebox, Consolidate, Eliminate</li>
<li>Configure a new developer machine &#8211; Strive for zero configuration</li>
</ul>
<h2>Value Simplicity</h2>
<blockquote><p>Any intelligent fool can make things bigger, more complex and more violent.  It takes a touch of genius and a lot of courage to move in the opposite direction. -Albert Einstein</p></blockquote>
<p>There&#8217;s a theme underlying most of the solutions to these problems: simplicity.  Complex  systems don&#8217;t become complex and crufty overnight, they get that way one small step at a time.  With each change to a system it&#8217;s important to recognize that the change will either add complexity or remove it.  Complexity has a cost and it&#8217;s not to be taken lightly; make sure the benefit to each of the decisions that add complexity is worth that cost.</p>
<h2>Conclusion</h2>
<p>Making the things that people do often fast and easy can pay off geometrically as all developers benefit and regain a little more of their day (and sanity).  In the end, it&#8217;s not <em>just</em> about shaving off seconds or minutes, though that&#8217;s a huge part of it; it&#8217;s about creating a development environment that lets the team do what&#8217;s really important: write awesome code to solve real problems.  When the team dynamics, technical environment, and process are tuned just right, the overall benefit is greater than the sum of its parts.</p>
<p>Where have you seen changes in infrastructure, software, or process that&#8217;s resulted in a significant productivity bump?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.carbonfive.com/2008/09/10/make-the-things-you-do-often-fast-and-easy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

