<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>alexcuesta</title>
	<atom:link href="http://alexcuesta.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexcuesta.wordpress.com</link>
	<description>My tech blog</description>
	<lastBuildDate>Fri, 12 Aug 2011 10:33:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='alexcuesta.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>alexcuesta</title>
		<link>http://alexcuesta.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://alexcuesta.wordpress.com/osd.xml" title="alexcuesta" />
	<atom:link rel='hub' href='http://alexcuesta.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Constructor Injection vs Setter Injection</title>
		<link>http://alexcuesta.wordpress.com/2011/07/28/constructor-injection-vs-setter-injection/</link>
		<comments>http://alexcuesta.wordpress.com/2011/07/28/constructor-injection-vs-setter-injection/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:59:18 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=208</guid>
		<description><![CDATA[My opinion is that we should initialize an object by passing all collaborators in the constructor. That&#8217;s the Java natural way to initialize an object correctly. Other mechanisms such as Spring annotations (@Required) are artificial ways to achieve the same goal. Why? Constructor-injection automatically enforces the order and completeness of the instantiated.In other words, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=208&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My opinion is that we should initialize an object by passing all collaborators in the constructor. That&#8217;s the Java natural way to initialize an object correctly. Other mechanisms such as Spring annotations (@Required) are artificial ways to achieve the same goal.</p>
<p><strong>Why?</strong></p>
<ul>
<li>Constructor-injection automatically enforces the order and completeness of the instantiated.In other words, it prevents the object to work with ‘null’ collaborators.</li>
<li>Enforces the order of initialization and prevents <a href="http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/">circular dependencies</a></li>
</ul>
<p><strong>Are you insane? My constructor has lots of arguments!</strong></p>
<p>If you have many collaborators in the constructor, that means your class may have too many responsabilities. That&#8217;s not a good practice. Remember the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsability Principle</a>. More than three is too many! Your tests will get complicated because you&#8217;ll have lots of different combinations to setup each scenario.</p>
<p>That doesn&#8217;t mean that in some situations we need to use setters (Legacy code and no time for refactoring?). In this case, use the @Required annotation to ensure Spring initializes all dependencies.</p>
<p>Information about this:</p>
<p>Spring Blog:</p>
<p><a href="http://blog.springsource.com/2007/07/11/setter-injection-versus-constructor-injection-and-the-use-of-required/">http://blog.springsource.com/2007/07/11/setter-injection-versus-constructor-injection-and-the-use-of-required/</a></p>
<p>Minsko Hevery, Agile Coach at Google:</p>
<p><a href="http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/">http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/</a></p>
<p>Richard Paul about testing these objects:</p>
<p><a href="http://www.rapaul.com/2011/07/10/constructor-injection-unit-tests/">http://www.rapaul.com/2011/07/10/constructor-injection-unit-tests/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=208&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/07/28/constructor-injection-vs-setter-injection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Git and Subversion</title>
		<link>http://alexcuesta.wordpress.com/2011/06/18/using-git-and-subversion/</link>
		<comments>http://alexcuesta.wordpress.com/2011/06/18/using-git-and-subversion/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 11:16:20 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Git/Svn]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=197</guid>
		<description><![CDATA[After reading Richard Paul&#8217;s about using git on a subversion repository, I always wanted to give it a try. I don&#8217;t regret so far. Git handles branches and merging very well and I haven&#8217;t seen any weird thing such &#8220;obstruction&#8221; or &#8220;tree conflicts&#8221;. This is my recipe to use git on a subversion repository from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=197&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://www.rapaul.com/2010/01/13/my-git-svn-workflow/">Richard Paul&#8217;s about using git on a subversion repository</a>, I always wanted to give it a try. I don&#8217;t regret so far. <a href="http://git-scm.com/">Git</a> handles branches and merging very well and I haven&#8217;t seen any weird thing such &#8220;obstruction&#8221; or &#8220;tree conflicts&#8221;. </p>
<p>This is my recipe to use git on a subversion repository from bash, also inspired on this very good article &#8220;<a href="http://www.viget.com/extend/effectively-using-git-with-subversion/">Effectively using Git with Subversion</a>&#8221; and completed by reading a lot.</p>
<p><strong>How to use git on subversion</strong></p>
<p><strong>1.- Clone Subversion repository on your local computer using git</strong></p>
<p>Git is a distributed version control system. Distributed means that every machine has a copy of the repository. In order to use Git on a Subversion repository you need to clone the svn repository on your machine: trunk, branches and tags.</p>
<p><code>git-svn clone -s http://example.com/my_subversion_repo local_dir</code></p>
<p>Notice that you should point to the root of the subversion repository, not to trunk. This was one of my problems in the begining.</p>
<p>The option -s means &#8220;I have the standard svn layout&#8221;, trunk, branches and tags.</p>
<p>You might want to add your svn ignore files:</p>
<p><code>git-svn show-ignore &gt; .gitignore</code></p>
<p><strong>2.- Create a story branch and use it</strong></p>
<p>Once you have your git repository cloned from subversion you can start working. I normally create a &#8220;story branch&#8221; like this:</p>
<p><code>git checkout -b story_branch</code></p>
<p>You can see git branches using this command:</p>
<p><code>git branch</code></p>
<p>Or all git and subversion branches:</p>
<p><code>git branch -a</code></p>
<p>If you only want to work on a svn branch, just checkout the remote branch like this:</p>
<p><code>git checkout remote/svnbranch</code></p>
<p>This does not mean you are working on the remote repo, you are still working on your local copy. Once you finish your work, you have to send your changes to subversion. Keep reading.</p>
<p><strong>3.- Staging and committing changes</strong></p>
<p>Before committing your changes you need to &#8220;stage&#8221; them. Git has an intermediate area called &#8220;stage&#8221; and only commits files stored in the stage. Think about it as a mail outbox.</p>
<p>Before staging files you might need to know which ones have been changed. This command will tell you which files have been changed or created but untracked:</p>
<p><code>git status</code></p>
<p>In order to &#8220;stage&#8221; the files you want to commit, run this command:</p>
<p><code>git add path/to/file</code></p>
<p>If you just want to stage all modified files just run:</p>
<p><code>git add .</code></p>
<p>Run git status again to verify that all the files you want to commit are in the stage area and then commit:</p>
<p><code>git commit</code></p>
<p>This will start your editor (vi for example) so you can enter a commit message. Remember that <a href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html#_discussion">a good commit message</a> should have:</p>
<ul>
<li>A title summarizing what&#8217;s been done, ideally containing the issue number from your project tracking application (Jira for example)</li>
<li>A blank line</li>
<li>A thorough description if necessary</li>
</ul>
<p>If you want to skip the editor just run:</p>
<p><code>git commit -m "message"</code></p>
<p><strong>4.- Get other developer changes into your branch (update)</strong></p>
<p>Many times, other developers commit changes before you finish your task. If you want to incorporate other developers changes, first commit your changes, then rebase:</p>
<p><code>git svn rebase</code></p>
<p>This command is awesome! It just merges down changes from the original branch into your local branch. In other words, if someone modifies the remote &#8216;subversion trunk&#8217; and your &#8216;git story branch&#8217; was forked from your &#8216;git master branch&#8217; (which is a copy of trunk), git will fetch those changes from svn trunk and will merge them into your &#8216;git story branch&#8217;. The documentation explains this command very well.</p>
<p><strong>Updating without having to commit</strong></p>
<p>Sometimes it isn’t reasonable since your changes are not yet ready to be committed (you haven’t finished/tested/improved your work). But don’t worry, git has a native solution also for this problem, just follow these steps:</p>
<ul>
<li>put aside your changes using the command: git-stash</li>
<li>update your working copy using: git-svn rebase as usual</li>
<li>take back your changes typing: git-stash apply</li>
<li>clear “the stash” typing: git-stash clear</li>
</ul>
<p><strong>5.- Reverting uncommitted changes</strong></p>
<p>In git this is called &#8220;reset&#8221;.</p>
<p><code>git reset --hard HEAD</code></p>
<p>I don&#8217;t understand completely how this command works yet but as far as I understand it moves the index of changes to the previous state.</p>
<p><strong>6.- Reverting committed changes</strong></p>
<p><code>git revert HEAD</code></p>
<p>This will create a new commit which undoes the change in HEAD</p>
<p><strong>7.- Merging branch</strong></p>
<p>Once you finish your task on your local &#8216;story branch&#8217;, you&#8217;ll probably want to merge it up into &#8216;master&#8217;. Change to the branch master first:</p>
<p><code>git checkout master</code></p>
<p>Rebase possible changes made on subversion trunk:</p>
<p><code>git svn rebase</code></p>
<p>Merge:</p>
<p><code>git merge story_branch</code></p>
<p>This will try to run a &#8220;fast forward&#8221; merge by default, in other words, it will incorporate each commit on the &#8216;story branch&#8217; and master will look as if no branch had existed before. I don&#8217;t like this because if you want to check the history you don&#8217;t have a way of knowing in which the branch was merged down into master.</p>
<p>My preferred option is &#8220;no fast forward&#8221;:</p>
<p><code>git merge --no-ff -m "commit message"</code></p>
<p>This does exactly the same as fast forward but it also generates an empty commit message so you can see in which commit the branch was merged. Besides, when you send your changes to svn you will see only one commit which looks very clean.</p>
<p><strong>8.- Solving conflicts</strong></p>
<p>This is just a question of editing the conflict, add it to the stage area and commit.</p>
<p>I usually edit changes  with a normal editor or with the plugin <a href="http://eclipse.org/jgit/">JGit</a>/<a href="http://www.eclipse.org/egit/">EGit</a> for Eclipse. There is a built-in tool on git called &#8220;<a href="http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html">git-mergetool</a>&#8221; but I&#8217;ve never used it.</p>
<p><strong>9.- Send your changes to subversion</strong></p>
<p><code>git svn dcommit</code></p>
<p><strong>10.- Amending commit messages</strong></p>
<p>I had problems sending my changes to svn the first time because we are using pre-commit hooks and I forgot to include my issue number in the commit message. In order to modify commit messages, first I need to know the commit hash id:</p>
<p><code>git log</code></p>
<p>And then I run the following command:</p>
<p><code>git rebase --interactive $parent_of_flawed_commit</code></p>
<p>Be aware you have to use the commit parent hash id.</p>
<p>An editor will come up, with a list of all commits since the one you gave.</p>
<ul>
<li>Change pick to reword (or on old versions of Git, to edit) in front of any commits you want to fix.</li>
<li>Once you save, git will replay the listed commits.</li>
</ul>
<p>Git will drop back you into your editor for every commit you said you want to reword, and into the shell for every commit you wanted to edit. If you’re in the shell:</p>
<ul>
<li>Change the commit in any way you like.</li>
<li>git commit &#8211;amend</li>
<li>git rebase &#8211;continue</li>
</ul>
<p><strong>11.- Get new branches from subversion</strong></p>
<p>If you need to update your cloned version of subversion repository, just run:</p>
<p><code>git svn fetch</code></p>
<p><strong>Final step: convince all your colleagues to use git and move to it! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=197&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/06/18/using-git-and-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Turning off HtmlUnit driver logging messages</title>
		<link>http://alexcuesta.wordpress.com/2011/05/11/turning-off-htmlunit-driver-logging-messages/</link>
		<comments>http://alexcuesta.wordpress.com/2011/05/11/turning-off-htmlunit-driver-logging-messages/#comments</comments>
		<pubDate>Wed, 11 May 2011 16:56:43 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Cucumber/Cuke4Duke]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=193</guid>
		<description><![CDATA[HtmlUnit was throwing lots of log messages while using cuke4duke (cucumber) to test our website from maven and I wanted to turn them off temporary but I struggled a bit. This is the solution I found on Stack Overflow: I created the commons-logging.properties file under /src/main/resources and I specify that my logging framework is log4j [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=193&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>HtmlUnit was throwing lots of log messages while using cuke4duke (cucumber) to test our website from maven and I wanted to turn them off temporary but I struggled a bit. <a href="http://stackoverflow.com/questions/5188118/cant-turn-off-htmlunit-logging-messages">This is the solution I found on Stack Overflow</a>:</p>
<p>I created the commons-logging.properties file under /src/main/resources and I specify that my logging framework is log4j (commons is just a wrapper):</p>
<pre class="brush: plain;">

# JDK Logging
#org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
# Log4j logging (also required log4j.jar to be in classpath)
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
</pre>
<p>I created the log4j.xml file in the same folder /src/main/resources: </p>
<pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;&gt;

&lt;log4j:configuration xmlns:log4j=&quot;http://jakarta.apache.org/log4j/&quot;&gt;

    &lt;appender name=&quot;out&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt;
        &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
            &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{yyyy-MM-dd, HH:mm:ss} %p - %m%n&quot; /&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;

    &lt;root&gt;
        &lt;priority value=&quot;error&quot; /&gt;
        &lt;appender-ref ref=&quot;out&quot; /&gt;
    &lt;/root&gt;
&lt;/log4j:configuration&gt;
</pre>
<p>and I added the missing dependency to log4j in the pom.xml file:</p>
<pre class="brush: xml;">

&lt;dependency&gt;
	&lt;groupId&gt;log4j&lt;/groupId&gt;
	&lt;artifactId&gt;log4j&lt;/artifactId&gt;
	&lt;version&gt;1.2.12&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/193/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=193&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/05/11/turning-off-htmlunit-driver-logging-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Error handling and HTTP status codes with Spring MVC</title>
		<link>http://alexcuesta.wordpress.com/2011/05/11/error-handling-and-http-status-codes-with-spring-mvc/</link>
		<comments>http://alexcuesta.wordpress.com/2011/05/11/error-handling-and-http-status-codes-with-spring-mvc/#comments</comments>
		<pubDate>Wed, 11 May 2011 11:09:31 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=189</guid>
		<description><![CDATA[The best way of handling errors in Spring MVC is implementing HandlerExceptionResolver interface or using the annotation @ExceptionHandler. Here you have an example using DefaultHandlerExceptionResolver, the default implementation of HandlerExceptionResolver. This resolver is defined in the applicationContext.xml: And the corresponding JSP is declared in web.xml:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=189&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The best way of <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-exceptionhandlers">handling errors in Spring MVC</a> is implementing <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/HandlerExceptionResolver.html">HandlerExceptionResolver</a> interface or using the annotation @ExceptionHandler.</p>
<p>Here you have an example using <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.html">DefaultHandlerExceptionResolver</a>, the default implementation of HandlerExceptionResolver.</p>
<pre class="brush: java;">
public class MyExceptionResolver extends DefaultHandlerExceptionResolver {

	@Override
	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response,
			Object handler,
			Exception ex) {

		try {
			if (ex instanceof PossibleSpamException) {
				return handlePossibleSpamException((PossibleSpamException) ex, request, response);
			}
		}
		catch (Exception handlerException) {
			logger.warn(&quot;Handling of [&quot; + ex.getClass().getName() + &quot;] resulted in Exception&quot;, handlerException);
		}

		return super.doResolveException(request, response, handler, ex);
	}

	private ModelAndView handlePossibleSpamException(PossibleSpamException ex,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);  // HTTP Status code 503
		return new ModelAndView();
	}

}
</pre>
<p>This resolver is defined in the applicationContext.xml:</p>
<pre class="brush: xml;">
&lt;bean id=&quot;exceptionResolver&quot; class=&quot;domain.MyExceptionResolver&quot; /&gt;
</pre>
<p>And the corresponding JSP is declared in web.xml:</p>
<pre class="brush: xml;">
&lt;error-page&gt;
	&lt;error-code&gt;503&lt;/error-code&gt;
	&lt;location&gt;/WEB-INF/views/errors/503.jsp&lt;/location&gt;
&lt;/error-page&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=189&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/05/11/error-handling-and-http-status-codes-with-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Mixing instances in a Cucumber World</title>
		<link>http://alexcuesta.wordpress.com/2011/04/15/mixing-instances-in-a-cucumber-world/</link>
		<comments>http://alexcuesta.wordpress.com/2011/04/15/mixing-instances-in-a-cucumber-world/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 11:19:35 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Cucumber/Cuke4Duke]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=183</guid>
		<description><![CDATA[I recently had the problem of calling a step from another step definition in cucumber using groovy (cuke4duke). Example: to be called from another step: It&#8217;s possible to do this using Ruby (the cucumber native language), Java or Scala; but apparently it is not currently possible on groovy. After posting my question on Cukes Groups [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=183&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had the problem of calling a step from another step definition in <a href="https://github.com/aslakhellesoy/cuke4duke/wiki/Groovy">cucumber using groovy (cuke4duke)</a>. Example:</p>
<pre class="brush: groovy;">
Given (~/I look for &quot;(.*)&quot; in &quot;(.*)&quot;/) { what, where -&gt;
      // groovy code

}
</pre>
<p>to be called from another step:</p>
<pre class="brush: groovy;">
When (~/I perform more than (.*) searches per minute/) { int number -&gt;
        (1..number).each {
                Given('I look for &quot;John Smith &quot; in &quot;London&quot;')
        }

}
</pre>
<p>It&#8217;s <a href="https://github.com/aslakhellesoy/cucumber/wiki/calling-steps-from-step-definitions">possible to do this using Ruby</a> (the cucumber native language), <a href="https://github.com/aslakhellesoy/cuke4duke/wiki/calling-steps-from-stepdefinitions">Java or Scala</a>; but apparently it is not currently possible on groovy.</p>
<p>After posting <a href="http://groups.google.com/group/cukes/browse_thread/thread/7a9787cd17134c4d">my question on Cukes Groups</a> I came up with this solution:</p>
<p>HomeSteps.groovy</p>
<pre class="brush: groovy;">
Given (~/I look for &quot;(.*)&quot; in &quot;(.*)&quot;/) { what, where -&gt;
	lookFor(what, where)
}
</pre>
<p>ErrorsSteps.groovy</p>
<pre class="brush: groovy;">
When (~/I perform more than (.*) searches per minute/) { int number -&gt;
	(1..number).each {
		lookFor(&quot;John Smith&quot;,&quot;London&quot;)
	}
}
</pre>
<p>env.groovy</p>
<pre class="brush: groovy;">
import geb.Browser
import org.openqa.selenium.firefox.FirefoxDriver

this.metaClass.mixin(cuke4duke.GroovyDsl)

class Searcher {
	def lookFor(what, where) {
		go('/')
		$('form')[0].looking_for = what
		$('form')[0].location = where
		$('input', value: &quot;Search&quot;)[0].click()
	}
}

World() {
  def world = new Browser(&quot;http://localhost:8080/myApp&quot;)  // mixing an instance of Browser
  world.metaClass.mixin Searcher
  return world
}

After() {
	clearCookies()
}
</pre>
<p>Notice that <a href="http://www.rapaul.com/2010/05/03/cucumber-world-with-groovy/">I am not mixing an Object as Richard Paul suggested</a>. In my case, I need to get an specific instance of Browser to be used across steps.</p>
<p>Anyway, I am posting this solution for people who might need something like this. In my case, <strong>I found out that my problem is in the way the step definitions are organized</strong>. Most of the times this kind of problem is caused by wrong organization of concepts so I recommend you think twice or even three times if you are placing your step in the right place before using a solution like the one I suggested here.</p>
<p>Hope this helps!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/183/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/183/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/183/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=183&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/04/15/mixing-instances-in-a-cucumber-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Handling form errors on Grails</title>
		<link>http://alexcuesta.wordpress.com/2011/02/22/handling-form-errors-on-grails/</link>
		<comments>http://alexcuesta.wordpress.com/2011/02/22/handling-form-errors-on-grails/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 15:51:12 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Groovy/Grails]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=173</guid>
		<description><![CDATA[I have not found clear information about how to deal with form errors on Grails so I made my own investigation. How to deal with form field errors We need to bear in mind that each field might have more than one error. E.g.: Imagine a age field and we enter &#8220;abcde&#8221;. Having the right [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=173&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have not found clear information about how to deal with form errors on Grails so I made my own investigation.</p>
<p><strong>How to deal with form field errors</strong></p>
<p>We need to bear in mind that each field might have more than one error.</p>
<p>E.g.: Imagine a age field and we enter &#8220;abcde&#8221;. Having the right constraints, we&#8217;d display two error messages: &#8220;maximum 3 digits&#8221;, &#8220;only numbers please&#8221;.</p>
<p>In order to do this, Grails provide the following tags: <a href="http://grails.org/doc/latest/ref/Tags/renderErrors.html">renderErrors</a>, <a href="http://grails.org/doc/latest/ref/Tags/hasErrors.html"> hasErrors </a>and <a href="http://grails.org/doc/latest/ref/Tags/eachError.html">eachError</a>. This is well <a href="http://grails.org/doc/latest/guide/7.%20Validation.html#7.3%20Validation%20on%20the%20Client">explained in the user guide</a>.</p>
<p><strong>How to print the list of messages using different formats</strong></p>
<p>What if I don&#8217;t want to use the standard <em>as=&#8221;list&#8221;</em> which generates output?</p>
<p>This is an example of how to print error messages in a paragraph separated by&lt;br/&gt;</p>
<pre class="brush: xml;">
&lt;g:hasErrors bean=&quot;${customer}&quot; field=&quot;email&quot;&gt;
      &lt;p&gt;
            &lt;g:eachError bean=&quot;${customer}&quot; field=&quot;email&quot;&gt;
                  &lt;g:message error=&quot;${it}&quot; /&gt;&lt;br/&gt;
            &lt;/g:eachError&gt;
      &lt;/p&gt;
&lt;/g:hasErrors&gt;
</pre>
<p><strong>How to print global errors</strong></p>
<p>I could not find a better way of doing this than through the standard <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/validation/Errors.html">Spring Errors interface</a>:</p>
<p>Having a customer bean, in the controller:</p>
<pre class="brush: groovy;">
customer.errors.reject(&quot;registration.data.access.error&quot;)
error()
</pre>
<p>And in the view:</p>
<pre class="brush: xml;">
&lt;g:each var=&quot;error&quot; in=&quot;${customer.errors.globalErrors}&quot;&gt;
	&lt;g:message error=&quot;${error}&quot; /&gt;
&lt;/g:each&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=173&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/02/22/handling-form-errors-on-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Grails 1.3.6 &amp; JNDI on Tomcat</title>
		<link>http://alexcuesta.wordpress.com/2011/02/12/grails-1-3-6-jndi-on-tomcat/</link>
		<comments>http://alexcuesta.wordpress.com/2011/02/12/grails-1-3-6-jndi-on-tomcat/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 18:54:27 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Groovy/Grails]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=167</guid>
		<description><![CDATA[We&#8217;ve been struggling for a couple of days to configure grails to pick up JNDI resources using the embedded tomcat plugin (run-app). After some googling I found an article which solved my problem. At least for now. You will find the link to the article at the end of this post. For completeness, I&#8217;ve added [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=167&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been struggling for a couple of days to configure grails to pick up JNDI resources using the embedded tomcat plugin (run-app). After some googling I found an article which solved my problem. At least for now. You will find the link to the article at the end of this post. For completeness, I&#8217;ve added a few comments in this blog post + the steps for how to get this working.</p>
<p>Before we start. Some notes about Tomcat and JNDI.</p>
<p>Tomcat support a number of different JNDI resource types (normally configured in Tomcat&#8217;s context xml file).</p>
<p>These are:</p>
<p>&lt;Environment&gt;<br />
&lt;Resource&gt;<br />
&lt;ResourceLink&gt;<br />
&lt;Transaction&gt;</p>
<p>On a side note, also Jetty support at least the first three resource types but additional configuration is needed which is beyond the scope of this post.</p>
<p>The &lt;Environment&gt; type is mainly used to configure environmental properties within an application while &lt;Resource&gt; and &lt;ResourceLink&gt; types link to external resources such as JDBC, JMS or LDAP. I won&#8217;t elaborate on &lt;Transaction&gt; since I&#8217;m unfamiliar with this type.</p>
<p>When it comes to configuring the embedded tomcat plugin (1.2-M2) with JNDI it took a little while to get this right.</p>
<p>If you are only using &lt;Resource&gt; types you won&#8217;t have any problems \:) The problem you will encounter is with applications using the &lt;Environment&gt; type. As of version 1.2-M2 the tomcat plugin doesn&#8217;t support &lt;Environment&gt; JNDI types. On the other hand, the Jetty plugin support both of them. The very quick solution is to switch to Jetty obviously. Hopefully next version of the tomcat plugin will have better JNDI support. In the meantime we have to fall back on the following hack.</p>
<p>There is an easy way to get the Tomcat plugin to accept other types of JNDI resources and this is what the following article is about [<a href="http://6by9.wordpress.com/2010/12/10/grails-1-3-5-tomcat-plugin-and-jndi-environment-variables/" target="_blank">http://6by9.wordpress.com/2010/12/10/grails-1-3-5-tomcat-plugin-and-jndi-environment-variables/</a>]</p>
<p>I&#8217;ve also provided the steps here but please read the article before following the steps below.</p>
<p>Do the following:</p>
<ul>
<li>Locate the following file TomcatServer.groovy. Mine was located under:C:\Documents and Settings\alejandro.cuesta\.grails\1.3.6\projects\trace\plugins\tomcat-1.3.6\src\groovy\org\grails\tomcat</li>
<li>Replace the private preStart() method with the following methods</li>
</ul>
<pre class="brush: groovy;">

private preStart() {
  eventListener?.event(&quot;ConfigureTomcat&quot;, [tomcat])
  def jndiEntries = grailsConfig?.grails?.naming?.entries

  if(jndiEntries instanceof Map) {
    def envs = jndiEntries.remove('environments')
    if (envs instanceof Map) {
      envs.each { name, cfg -&gt;
        if (cfg) {
          addEnvironment(name, cfg)
        }
      }
    }
    def ress = jndiEntries.remove('resources')
    if (ress instanceof Map) {
      ress.each { name, cfg -&gt;
        if (cfg) {
          addResource(name, cfg)
        }
      }
    }
    jndiEntries.each { name, cfg -&gt;
      if(cfg) {
        addResource(name, cfg)
      }
    }
  }
}

private addEnvironment(name, envCfg) {
  if (!envCfg[&quot;type&quot;]) {
    throw new IllegalArgumentException(&quot;Must supply a environment type for JNDI configuration&quot;)
  }
  def env = loadInstance('org.apache.catalina.deploy.ContextEnvironment')
  env.name = name
  env.type = envCfg.type
  env.description = envCfg.description
  env.override = envCfg.override as boolean
  env.value = envCfg.value

  context.namingResources.addEnvironment env
}

private addResource(name, resCfg) {
  if (!resCfg[&quot;type&quot;]) {
    throw new IllegalArgumentException(&quot;Must supply a resource type for JNDI configuration&quot;)
  }
  def res = loadInstance('org.apache.catalina.deploy.ContextResource')
  res.name = name
  res.auth = resCfg.remove(&quot;auth&quot;)
  res.scope = resCfg.remove(&quot;scope&quot;)
  res.type = resCfg.remove(&quot;type&quot;)
  res.description = resCfg.remove(&quot;description&quot;)
  // now it's only the custom properties left in the Map...
  resCfg.each {key, value -&gt;
    res.setProperty (key, value)
  }

  context.namingResources.addResource res
}
</pre>
<ul>
<li>The tomcat plugin has now been configured to also read environment resource types</li>
<li>You should now be able to define your resources in Config.groovy. Such as</li>
</ul>
<pre class="brush: groovy;">
grails.naming.entries = [

  &quot;resources&quot; : [

    &quot;jms/bananas&quot;: [
      type: &quot;org.apache.activemq.command.ActiveMQTopic&quot;,
      description: &quot;Fruit salad&quot;,
      factory: &quot;org.apache.activemq.jndi.JNDIReferenceFactory&quot;,
      physicalName: &quot;bananas&quot;
    ]
  ],

  &quot;environments&quot; : [
    &quot;/app/config/db.mysql.username&quot;: [
      type: &quot;java.lang.String&quot;,
      value: &quot;MYUSERNAME&quot;,
      override: &quot;true&quot;
    ],

    &quot;/app/config/db.mysql.password&quot;: [
      type: &quot;java.lang.String&quot;,
      value: &quot;MYPASSWORD&quot;,
      override: &quot;true&quot;
    ]
  ]

]
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=167&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/02/12/grails-1-3-6-jndi-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Using snapshots stored in your maven repository with Grails</title>
		<link>http://alexcuesta.wordpress.com/2011/01/26/using-snapshots-stored-in-your-maven-repository-with-grails/</link>
		<comments>http://alexcuesta.wordpress.com/2011/01/26/using-snapshots-stored-in-your-maven-repository-with-grails/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 17:06:04 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Groovy/Grails]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=158</guid>
		<description><![CDATA[In my current project, we are developing a core domain library to be shared across different web applications of different companies. We are also developing the new website of one of those companies in Grails. Therefore, we need to declare a Grails dependency on the core domain library which is stored on a Maven repository. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=158&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my current project, we are developing a core domain library to be shared across different web applications of different companies. We are also developing the new website of one of those companies in <a href="http://grails.org/">Grails</a>. Therefore, we need to declare a Grails dependency on the core domain library which is stored on a <a href="http://maven.apache.org/">Maven</a> repository.</p>
<p>Grails, by default, uses <a href="http://ant.apache.org/">Ant</a> to build the project and <a href="http://ant.apache.org/ivy/">Ivy</a> to resolve dependencies. Using maven as a repository is very easy: you only need to declare it on the &#8220;BuildConfig.groovy&#8221; file.</p>
<p>The problem is that this simple approach does not pick up changes on snapshots. The way I solved this was using &#8220;useOrigin true&#8221; in the same file.</p>
<p>Here you have the BuildConfig.groovy file:</p>
<pre class="brush: groovy;">
grails.project.dependency.resolution = {

	useOrigin true

	...

	repositories {
		...
        mavenLocal()
        mavenCentral()
		...
	}
	...
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=158&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2011/01/26/using-snapshots-stored-in-your-maven-repository-with-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Gradle on Grails</title>
		<link>http://alexcuesta.wordpress.com/2010/12/21/gradle-on-grails/</link>
		<comments>http://alexcuesta.wordpress.com/2010/12/21/gradle-on-grails/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 14:27:13 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Groovy/Grails]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=142</guid>
		<description><![CDATA[I am taking my first steps on grails on a real project after playing around with it for a while. The first problem I came across was: how to deal with dependencies? In my project, we have some dependencies on libraries stored in our internal maven repository. You have three options here: Use Ivy which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=142&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am taking my first steps on <a href="http://grails.org/">grails</a> on a real project after playing around with it for a while.</p>
<p>The first problem I came across was: how to deal with dependencies? In my project, we have some dependencies on libraries stored in our internal maven repository.</p>
<p>You have three options here:</p>
<ol>
<li>Use <a href="http://ant.apache.org/ivy/">Ivy</a> which comes out-of-the-box in Grails. Ivy is just a dependency manager for ant. I have never used it and looks old-fashioned,  so I went to the next step.</li>
<li><a href="http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html#4.5%20Ant%20and%20Maven">Mavenize your project</a>.</li>
<li>Use <a href="http://gradle.org/">gradle</a>, which is the latest cool builder. A mix of Ant and Maven with the power of the <a href="http://groovy.codehaus.org/">Groovy</a> language.</li>
</ol>
<p>As I said, I ignored Ivy.</p>
<p>My first successful attempt was Maven. It is quite easy following the steps in the documentation.</p>
<p>Anyway, I really wanted to use Gradle because it looks really easy to read, so I gave it a go. My starting point was this <a href="http://www.cacoethes.co.uk/blog/groovyandgrails/building-a-grails-project-with-gradle">article by Peter Ledbrook</a> but it was confusing because the build script contains errors. So after reading the comments, I went to the <a href="https://github.com/grails/grails-gradle-plugin">grails-gradle-plugin project</a> instead.</p>
<p>After a couple of hours, I ended up with this solution:</p>
<ol>
<li> Create an empty folder for your project</li>
<li>Go to root of your new project folder and store the build.gradle script  below.</li>
<li>Run &#8216;gradle init&#8217; to create the grails layout</li>
<li>Use the normal grails commands using the &#8220;grails-&#8221; prefix.
<pre>$ gradle grails-run-app</pre>
</li>
</ol>
<p>This is the <em>build.gradle</em> script</p>
<pre class="brush: groovy;">
buildscript {
    repositories {
        mavenCentral()
        mavenRepo urls: &quot;http://repository.jboss.org/maven2/&quot;
    }

    dependencies {
        classpath &quot;org.grails:grails-gradle-plugin:1.0&quot;,
                      &quot;org.grails:grails-bootstrap:1.3.6&quot;
    }
}

apply plugin: &quot;grails&quot;

version = '1.0-SNAPSHOT'

// this is your local maven repository
def localMavenRepository = new File( System.getProperty(&quot;user.home&quot; ), &quot;.m2/repository&quot; ).toURL().toString()

repositories {
    mavenCentral()
    mavenRepo urls: &quot;http://repository.jboss.org/maven2/&quot;
	mavenRepo urls: &quot;http://download.java.net/maven/2/&quot;
	mavenRepo name:'localMavenRepo', urls: localMavenRepository
}

configurations {
    compile.exclude module: &quot;xml-apis&quot;
}

dependencies {
    compile &quot;org.grails:grails-crud:1.3.6&quot;,
               &quot;org.grails:grails-gorm:1.3.6&quot;

    runtime &quot;org.slf4j:slf4j-log4j12:1.5.5&quot;,
	      &quot;hsqldb:hsqldb:1.8.0.5&quot;,
	      &quot;jstl:jstl:1.1.2&quot;

}
</pre>
<p>You may need to add or remove dependencies. This depends on your project.</p>
<p>Hope this saves you some time.</p>
<p><strong>UPDATE 4 JAN 2011</strong></p>
<p>The example above was done using gradle 0.9. The new <a href="http://docs.codehaus.org/display/GRADLE/Gradle+0.9.1+Release+Notes">version 0.9.1 supports mavenLocal()</a> so you can remove the localMavenRepository definition and replace the last mavenRepo with mavenLocal()</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=142&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2010/12/21/gradle-on-grails/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
		<item>
		<title>Groovy &amp; Grails eXchange 2010</title>
		<link>http://alexcuesta.wordpress.com/2010/12/17/groovy-grails-exchange-2010/</link>
		<comments>http://alexcuesta.wordpress.com/2010/12/17/groovy-grails-exchange-2010/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 20:48:50 +0000</pubDate>
		<dc:creator>alexcuesta</dc:creator>
				<category><![CDATA[Groovy/Grails]]></category>

		<guid isPermaLink="false">http://alexcuesta.wordpress.com/?p=132</guid>
		<description><![CDATA[I&#8217;ve just come from the Groovy &#38; Grails eXchange 2010. I am not an expert on Groovy or Grails but I must admit that I have learned lots of things and I can&#8217;t wait to start using this technology on my next project. My highlights of these two days of talks: I really loved Tomas [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=132&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just come from the <a href="http://www.grails-exchange.com/">Groovy &amp; Grails eXchange 2010</a>. I am not an expert on Groovy or Grails but I must admit that I have learned lots of things and I can&#8217;t wait to start using this technology on my next project.</p>
<p>My highlights of these two days of talks:</p>
<ul>
<li>I really loved <a href="http://twitter.com/tomaslin">Tomas Lin</a>&#8216;s talk about <a href="http://geb.codehaus.org/">Geb</a>. This is just a web testing framework based on <a href="http://code.google.com/p/spock/">Spock</a> using a groovy DSL based on the JQuery language. In other words, bye bye WebDriver&#8217;s findElementBy and welcome JQuery selectors. It uses the <a href="http://geb.codehaus.org/manual/latest/intro.html">Page Object pattern</a> so tests are organized better. This also comes as a Grails plugin.</li>
<li>I loved the talk by the guys from <a href="http://www.sky.com">Sky.com</a> who developed the whole site in Grails after comparing the productivity between two teams implementing the same features in two weeks. Groovy represents 95% of their code whereas 5% is Java. They test absolutely everything: unit testing and lots of functional testing to guarantee releases every week. They even test deployments!</li>
<li><a href="http://gradle.org/">Gradle</a> is becoming the next building tool. I really like it. It seems to be easy to use because it is just a combination of Ant and Maven with the power of Groovy.</li>
<li>From <a href="http://graemerocher.blogspot.com/">Graeme Rocher</a>&#8216;s keynote:
<ul>
<li>DB reverse engineering to create domain classes from a database schema.</li>
<li>Database migration</li>
<li>New GORM implementations for nosql databases: mongodb, redis, gemfire&#8230;</li>
<li>A demo of <a href="http://www.springsource.org/insight">Spring insight</a>, a tc server profiling tool. Very cool but <a href="http://code.google.com/p/javamelody/">JavaMelody</a> looks better and independent from tc Server.</li>
</ul>
</li>
<li>From Laforge&#8217;s keynote I liked:
<ul>
<li>Default values for maps via <a href="&lt;li&gt;Default values for maps via .withDefault()&lt;/li&gt;">.withDefault()</a></li>
<li>Inline dependency declaration with <a href="http://groovy.codehaus.org/Grapes+and+grab%28%29">Grape via @Grab</a></li>
<li><a href="http://mrhaki.blogspot.com/2009/12/groovy-goodness-powerful-assert.html">Powerful asserts</a></li>
<li><a href="http://groovy.codehaus.org/api/groovy/lang/Closure.html">Currying: rcurry, ncurry</a></li>
<li>Memoization in the next version of Groovy 1.8 (caching of results returned by closures)</li>
</ul>
</li>
<li>Plugins for almost everything!</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexcuesta.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexcuesta.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexcuesta.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexcuesta.wordpress.com&amp;blog=8321094&amp;post=132&amp;subd=alexcuesta&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sd-like-enabled"></div>]]></content:encoded>
			<wfw:commentRss>http://alexcuesta.wordpress.com/2010/12/17/groovy-grails-exchange-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/102a244af7155f2da00f56b7cbd32c43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alexcuesta</media:title>
		</media:content>
	</item>
	</channel>
</rss>
