<?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>A Software Guy&#039;s Blog</title>
	<atom:link href="http://asoftwareguy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://asoftwareguy.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 12:46:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='asoftwareguy.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>A Software Guy&#039;s Blog</title>
		<link>http://asoftwareguy.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://asoftwareguy.com/osd.xml" title="A Software Guy&#039;s Blog" />
	<atom:link rel='hub' href='http://asoftwareguy.com/?pushpress=hub'/>
		<item>
		<title>MSDeploy and when it just stops working</title>
		<link>http://asoftwareguy.com/2012/05/03/msdeploy-and-when-it-just-stops-working/</link>
		<comments>http://asoftwareguy.com/2012/05/03/msdeploy-and-when-it-just-stops-working/#comments</comments>
		<pubDate>Fri, 04 May 2012 03:32:56 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Builds]]></category>
		<category><![CDATA[Deployments]]></category>
		<category><![CDATA[.IIS]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[failing]]></category>
		<category><![CDATA[failure]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[MSDeploy]]></category>

		<guid isPermaLink="false">https://asoftwareguy.wordpress.com/?p=298</guid>
		<description><![CDATA[On my current project, we have a Bamboo continuous integration server that deploys an ASP.net application packaged with MSBuild to our dev integration IIS server. This deployment happens via MSDeploy using the following command in the MSBuild script: Everything is good with the command and deployments to iisserver were happening many times a day for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=298&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On my current project, we have a Bamboo continuous integration server that deploys an ASP.net application packaged with MSBuild to our dev integration IIS server. This deployment happens via MSDeploy using the following command in the MSBuild script:</p>
<p><pre class="brush: plain;">
&quot;C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe&quot; -source:package='path\to\the.zip' -dest:auto,wmsvc='https://iisserver:8172/msdeploy.axd?Site=MySite',userName='*****',password='*****',includeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:path\to\the.SetParameters.xml -allowUntrusted
</pre></p>
<p>Everything is good with the command and deployments to iisserver were happening many times a day for a few months. Then the other day, the dev integration deployment job started failing with the following error:<br />
<code><br />
Error: (build date) An error occurred when the request was processed on the remote computer.</p>
<p>Error: Unable to perform the operation. Please contact your server administrator to check authorization and delegation settings.<br />
</code></p>
<p>Nice error! Very informative. So I go ahead and check all the usual things: did a code change break something (no); did the user account represented by userName in the command get locked (no), or did its password expire (no); was the wmsvc agent running on the server (yes); were any Windows updates installed on the server (yes, on the same day the deployment started breaking); were there any changes to the Window or IIS server configuration (no)</p>
<p>With these checks done, the only one that seemed possible was one of the Windows updates might have done it. So I backed out the updates. But that didn&#8217;t fix the issue. Hmm, alright. After quite a bit of effort and time expended by myself and our systems administrators, I finally dug up <a title="StackOverflow MSDeploy issue" href="http://stackoverflow.com/questions/6939150/web-deployment-task-build-failed" target="_blank">this StackOverflow issue</a> that sounded similar. The answer is what caught me:<br />
<em><br />
&#8230;Turns out that when you install web deploy it sets up two local accounts WDeployConfigWriter and WDeployAdmin. These passwords on these accounts are set to expire&#8230;<br />
</em><br />
Ah ha! Wait, what?! In addition to the domain service account I use on the command line, there are 2 more local accounts required by the tool? That I didn&#8217;t know were there? And they had passwords set to expire after 90 days? Really? Awesome. In any case, after &#8220;fixing&#8221; those two accounts on the dev integration server, they deployments started working as they had before.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/298/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=298&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2012/05/03/msdeploy-and-when-it-just-stops-working/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>A Groovy temperature conversion with Categories</title>
		<link>http://asoftwareguy.com/2012/03/12/a-groovy-temperature-conversion-with-categories/</link>
		<comments>http://asoftwareguy.com/2012/03/12/a-groovy-temperature-conversion-with-categories/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 15:43:00 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[DSL]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[MOP]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[groovy categories]]></category>
		<category><![CDATA[groovy meta programming]]></category>
		<category><![CDATA[groovy MOP]]></category>
		<category><![CDATA[groovy temperature conversion]]></category>
		<category><![CDATA[temperature conversion]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=263</guid>
		<description><![CDATA[I have been getting more interested with the capabilities of the Groovy language since I have used it more and more as part of my daily work on a Grails web application. I have also been having some interesting conversations with one of my co-workers about the possibilities provided by Groovy&#8217;s MOP (Meta Object Protocol) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=263&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been getting more interested with the capabilities of the Groovy language since I have used it more and more as part of my daily work on a Grails web application. I have also been having some interesting conversations with <a title="Vasya's Weblog" href="http://vasya10.wordpress.com" target="_blank">one of my co-workers</a> about the possibilities provided by Groovy&#8217;s MOP (Meta Object Protocol) for creating new ways of expressing meaning in the contextual space of a given problem area using DSLs (Domain Specific Languages). I have seen a few examples of augmenting existing Java classes with new functionality by using Categories wrapped around the existing classes, but have mainly seen these related to distances and conversion of units of measure within that domain. I thought back to one of the first programs I wrote (can&#8217;t remember the language, maybe it was C) for doing temperature conversion between degrees Fahrenheit and Celsius. So, I thought I would give an example of using <a title="Groovy Categories" href="http://docs.codehaus.org/display/GROOVY/Groovy+Categories" target="_blank">Groovy Categories</a> to add new functionality to existing Java classes.</p>
<h2>The problem</h2>
<p>So let&#8217;s assume that you are tasked with writing a temperature conversion application. This converter should be able to convert temperatures given in either degrees Fahrenheit or Celsius and give the result in degrees Fahrenheit. Sounds easy enough, you can model things within the class(es) exactly how you need to solve the problem. But wait! There is another stipulation. You are told that there is already an existing class in some existing archaic Java library that was written ten years ago, and you have you use this class within your code. You think, alright, even if the class is wretched, I can write some new Java code and extend the existing class to offer the new functionality. Presenting the Java class you are required to use:</p>
<p>AncientTemperature.java</p>
<p><pre class="brush: java;">
package com.asoftwareguy.temperature;

/**
 * This is an &quot;old&quot; existing Java class representing temperature.
 * It assumes the unit of measure is degrees Fahrenheit.
 *
 */
public final class AncientTemperature {
	// in degrees Fahrenheit
	private int temp;

	public AncientTemperature(int temp) {
		this.temp = temp;
	}

	public String toString() {
		return new StringBuilder().append(&quot;The current temperature is &quot; + temp + &quot; degrees F.&quot;).toString();
	}
}
</pre></p>
<p>The class is declared final! So the creator of this class, a decade or so ago, found it in their infinite wisdom that their representation of temperature was perfect and no one would ever need to add any more functionality. Awesome! :/</p>
<h2>The solution</h2>
<p>You could obviously also create new functionality by creating a <a title="Decorator pattern" href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank">decorator</a> class and using composition to delegate calls when necessary out to the existing class, but you are using Groovy, so why would you do that! Here the requirements stated above are as follows:</p>
<ol>
<li>We need to be able to give the temperature inputs in either degress Fahrenheit or Celsius.</li>
<li>We need to be able to give the resulting temperature in degrees Fahrenheit.</li>
<li>We have to use the existing AncientTemperature.java class.</li>
</ol>
<p>Requirement #3 is de facto by mandate, so let&#8217;s ignore that one. After looking at what we have to work with, it seems that we have requirement #2 already met by the functionality of the existing class. The toString() method spits out the temperature in degrees Fahrenheit:</p>
<p><pre class="brush: java; highlight: [7,8,9];">
package com.asoftwareguy.temperature;

public final class AncientTemperature {

	// other methods

	public String toString() {
		return new StringBuilder().append(&quot;The current temperature is &quot; + temp + &quot; degrees F.&quot;).toString();
	}
}
</pre></p>
<p>Let&#8217;s look at how we can meet requirement #1 using Categories. Categories in Groovy are somewhat similar to the concept of <a title="Extension Methods in C#" href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">static extension methods in C#</a> with one key difference: <em>In C#, you can only add new methods to the class which you are extending; you cannot override methods that already exist in the class. In Groovy, you can add new methods <strong>as well as override existing methods</strong> in the class you are extending!</em> This a powerful feature and one that I will use in this example. Let&#8217;s take a look at our Category:</p>
<p>TemperatureConversion.groovy</p>
<p><pre class="brush: groovy;">
package com.asoftwareguy.temperature

class TemperatureConversion {

	static AncientTemperature getFahrenheit(String fahrenheit) {
		new AncientTemperature(fahrenheit as int)
	}

	static AncientTemperature getCelsius(String celsius) {
		BigDecimal fahrenheit = (celsius.toInteger() *  (9/5) + 32)
		fahrenheit = fahrenheit.setScale(0, BigDecimal.ROUND_DOWN)
		new AncientTemperature(fahrenheit.toString() as int)
	}

	static AncientTemperature getFahrenheit(Integer fareheit) {
		new AncientTemperature(fareheit)
	}

	static AncientTemperature getCelsius(Integer celsius) {
		BigDecimal fahrenheit = (celsius *  (9/5) + 32)
		fahrenheit = fahrenheit.setScale(0, BigDecimal.ROUND_DOWN)
		new AncientTemperature(fahrenheit.toString() as int)
	}
}
</pre></p>
<p>If you have done any kind of temperature conversion before, the code above should look familiar. It uses the standard formulas for converting temperature between degrees Fahrenheit and Celsius, and vice-verse. With this code in place, it allows you to write code like the following, using a &#8216;use&#8217; block in Groovy:</p>
<p>TemperatureTest.groovy</p>
<p><pre class="brush: groovy;">
package com.asoftwareguy.temperature

use(TemperatureConversion) {
	assert  &quot;100&quot;.fahrenheit.toString() == 'The current temperature is 100 degrees F.'
	println &quot;100&quot;.fahrenheit

	assert 	&quot;50&quot;.fahrenheit.toString() == 'The current temperature is 50 degrees F.'
	println &quot;50&quot;.fahrenheit

	assert 	&quot;32&quot;.fahrenheit.toString() == 'The current temperature is 32 degrees F.'
	println &quot;32&quot;.fahrenheit

	assert 	&quot;100&quot;.celsius.toString() == 'The current temperature is 212 degrees F.'
	println &quot;100&quot;.celsius

	assert 	100.fahrenheit.toString() == 'The current temperature is 100 degrees F.'
	println 100.fahrenheit

	assert 	50.fahrenheit.toString() == 'The current temperature is 50 degrees F.'
	println 50.fahrenheit

	assert 	32.fahrenheit.toString() == 'The current temperature is 32 degrees F.'
	println 32.fahrenheit

	assert 	100.celsius.toString() == 'The current temperature is 212 degrees F.'
	println 100.celsius
}
</pre></p>
<p>All of the methods defined in TemperatureConversion.groovy only add new functionality to the AncientTemperature.java class. The &#8216;use&#8217; block is key to this working, as it provides that any types declared within the block expose the methods of the Category. I had mentioned earlier that in Groovy, you can also override existing methods and I also said I would give an example. So here is the version of the Category with overriding methods:</p>
<p>TemperatureConversion.groovy</p>
<p><pre class="brush: groovy; highlight: [7,8,9,10,11,12,13,14,15,16,17,18,19];">
package com.asoftwareguy.temperature

class TemperatureConversion {

	// other methods

	static AncientTemperature plus(AncientTemperature first, AncientTemperature second) {
		int tempFirst = first.temp
		int tempSecond = second.temp;
		int newTemp = tempFirst + tempSecond
		return new AncientTemperature(newTemp)
	}

	static AncientTemperature minus(AncientTemperature first, AncientTemperature second) {
		int tempFirst = first.temp
		int tempSecond = second.temp;
		int newTemp = tempFirst - tempSecond
		return new AncientTemperature(newTemp)
	}
}
</pre></p>
<p>As you can see above, we have actually overrode the ability to add and subtract objects of AncientTemperature with each other. We can do this even though we do not have this ability in Java because by default, Groovy adds the plus and minus (along with many other methods) to all objects. So now we can write code like this:</p>
<p><pre class="brush: groovy; highlight: [6,7,9,10,12,13];">
package com.asoftwareguy.temperature

use(TemperatureConversion) {
	// other methods

	assert (100.fahrenheit + 50.fahrenheit).toString() == 'The current temperature is 150 degrees F.'
	println 100.fahrenheit + 50.fahrenheit

	assert (100.fahrenheit + 0.celsius).toString() == 'The current temperature is 132 degrees F.'
	println 100.fahrenheit + 0.celsius

	assert (100.fahrenheit - 0.celsius).toString() == 'The current temperature is 68 degrees F.'
	println 100.fahrenheit - 0.celsius
}
</pre></p>
<p>Groovy Categories are a powerful tool in providing new functionality to existing types at run-time and for creating DSLs that can describe your problem space. Hopefully this has provided you with a good example of using Groovy Categories to add such functionality. </p>
<p>All of the source code for this post can be found in <a href="https://gist.github.com/2022678" title="Source code" target="_blank">this Gist</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=263&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2012/03/12/a-groovy-temperature-conversion-with-categories/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing a Grails required interstitial form page</title>
		<link>http://asoftwareguy.com/2012/03/05/implementing-a-grails-required-interstitial-form-page/</link>
		<comments>http://asoftwareguy.com/2012/03/05/implementing-a-grails-required-interstitial-form-page/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 19:31:27 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[intermediate form]]></category>
		<category><![CDATA[interstitial form]]></category>
		<category><![CDATA[required form]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=230</guid>
		<description><![CDATA[Having shared functionality/pages across software modules in web application development seems to be a common occurrence (at least within the projects on which I am working) and is a problem that can be handled in a number of ways. Currently, I happen to be implementing two different user modules in a Grails 2.0.x application that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=230&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Having shared functionality/pages across software modules in web application development seems to be a common occurrence (at least within the projects on which I am working) and is a problem that can be handled in a number of ways. Currently, I happen to be implementing two different user modules in a Grails 2.0.x application that ended up needing such shared functionality, so I thought I would share my solution. I am going to describe how I initially developed the modules, and how I solved the problem of having a required common interstitial form page that is shared between the two or more page flows.</p>
<h2>The first module</h2>
<p>The page flow within the first module is as described in Figure 1 below:</p>
<div id="attachment_232" class="wp-caption alignnone" style="width: 507px"><a href="http://asoftwareguy.files.wordpress.com/2012/03/option1.png"><img class="size-full wp-image-232" title="Option1" src="http://asoftwareguy.files.wordpress.com/2012/03/option1.png?w=497&h=70" alt="" width="497" height="70" /></a><p class="wp-caption-text">Figure 1</p></div>
<p>When developing the module, both web page forms represented by the 2nd and 3rd steps in the flow were implemented within the same controller class (following the practice of Agile development of implementing what you need right now, and refactoring when circumstances require you to do so). Everything good so far, this is all standard web application development. Story complete, so let&#8217;s look at the second module.</p>
<h2>The second module</h2>
<p>The page flow within the second module is as described in Figure 2 below:</p>
<div id="attachment_234" class="wp-caption alignnone" style="width: 507px"><a href="http://asoftwareguy.files.wordpress.com/2012/03/option2.png"><img class="size-full wp-image-234" title="Option2" src="http://asoftwareguy.files.wordpress.com/2012/03/option2.png?w=497&h=70" alt="" width="497" height="70" /></a><p class="wp-caption-text">Figure 2</p></div>
<p>Note that the 2nd step in both Figure 1 and Figure 2 both note that some user input is required before the actual function can commence. As it turns out, the user input required is identical, meaning the exact same form data is captured from the user. This is depicted in Figure 3:</p>
<div id="attachment_233" class="wp-caption alignnone" style="width: 507px"><a href="http://asoftwareguy.files.wordpress.com/2012/03/option1-2.png"><img class="size-full wp-image-233" title="Option1-2" src="http://asoftwareguy.files.wordpress.com/2012/03/option1-2.png?w=497&h=145" alt="" width="497" height="145" /></a><p class="wp-caption-text">Figure 3</p></div>
<p>In &#8220;traditional&#8221; (read: lazy) web development, I might just copy all of the logic for displaying the form and capturing the input from the Option1 controller(s) within Module A into the Option 2 controller(s) within Module B. But I figured it could be implemented so much more cleanly without the need for any code duplication. The solution I decided upon was to implement the logic for determining the need to direct the user to the interstitial page within a Grails <a title="Grails Filter" href="http://grails.org/doc/latest/guide/theWebLayer.html#6.6%20Filters" target="_blank">Filter</a>.</p>
<h2>The solution</h2>
<p>Let&#8217;s take a look at the Filter class that determines whether the user is required to be directed to the interstitial page.</p>
<p>RequiredAttributeFilters.groovy<br />
<pre class="brush: groovy;">
class RequiredAttributeFilters {
  def filters = {
    attributeRequiredforOptionA(controller: 'optionA', action: 'index') {
      before = {
        if(session.someAttribute == null) {
          // attribute not set, redirect user to collect data
          def targetUri = request.forwardURI.replace(request.contextPath, '')
          session.requiredAttributesFilterRedirectUri = targetUri
          redirect controller: 'requiredUserInput', action: 'index'
        }
      }
    }
    attributeRequiredforOptionB(controller: 'optionB', action: 'index') {
      before = {
	if(session.someAttribute == null) {
          // attribute not set, redirect user to collect data
          def targetUri = request.forwardURI.replace(request.contextPath, '')
          session.requiredAttributesFilterRedirectUri = targetUri
          redirect controller: 'requiredUserInput', action: 'index'
        }
      }
    }
    removeSomeAttribute(controller: 'user', action: 'menu') {
      before = {
        // user exited current function, remove required attribute
        session.someAttribute = null
      }
    }
  }
}
</pre></p>
<p>This is just a standard Grails filter class that intercepts requests to &#8220;/option1/index&#8221; and &#8220;/option2/index&#8221; and redirects the user to &#8220;/requiredUserInput/index&#8221; if the value of session.someAttribute is null. Before redirection, it stores the value of the URL that user initially requested in the session. It also removes the attribute from session if the user exits current function (in my case, goes back to their menu). Now that we have the filter is place, let&#8217;s look at the controller that captures the required user input.</p>
<p>RequiredUserInputController.groovy<br />
<pre class="brush: groovy;">
class RequiredUserInputController {
  def index = {
    // do stuff
    // render view
    render view: 'index'
  }
  def captureData = { 
    // check form errors etc.
    def someAttribute = null;
    // get the data and set the attribute in session
    session.someAttribute = someAttribute
    redirect uri: session.requiredAttributesFilterRedirectUri
  }
}
</pre></p>
<p>The above controller has two methods: the standard &#8220;index&#8221; method for rendering the form and the &#8220;captureData&#8221; method, which is called upon form submission. The latter performs any required form processing, and in addition, sets the value of session.someAttribute to the correct current value. It then redirects to the URL that was set in session by the filter that redirected here in the first place. The filter is called again, but session.someAttribute has a value so filter processing is skipped. I won&#8217;t detail the GSP code for the form page, but it contains a simple form whose action attribute points to the &#8220;captureData&#8221; URL.</p>
<p>That&#8217;s all there is to it. If in the future additional page flows need to same data in order to proceed, those controllers/actions/URIs just need to be added to the Filter class so that the interception occurs.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=230&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2012/03/05/implementing-a-grails-required-interstitial-form-page/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>

		<media:content url="http://asoftwareguy.files.wordpress.com/2012/03/option1.png" medium="image">
			<media:title type="html">Option1</media:title>
		</media:content>

		<media:content url="http://asoftwareguy.files.wordpress.com/2012/03/option2.png" medium="image">
			<media:title type="html">Option2</media:title>
		</media:content>

		<media:content url="http://asoftwareguy.files.wordpress.com/2012/03/option1-2.png" medium="image">
			<media:title type="html">Option1-2</media:title>
		</media:content>
	</item>
		<item>
		<title>Grails 2.0 mockFor() Gotcha</title>
		<link>http://asoftwareguy.com/2012/02/28/grails-2-0-mockfor-gotcha/</link>
		<comments>http://asoftwareguy.com/2012/02/28/grails-2-0-mockfor-gotcha/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 15:35:36 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[gmock]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[grails 2.0]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[groovy mock]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[test mixin]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=206</guid>
		<description><![CDATA[Update: When I was researching another Grails issue, I found out that what I encountered below looks to be fixed in Grails 2.0.1. I have yet to verify the fix, but if you also encounter this issue I urge you to try Grails 2.0.1 to see if it resolves the problem. I am working on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=206&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Update: When I was researching another Grails issue, I found out that what I encountered below <a title="GRAILS-8511 JIRA" href="http://jira.grails.org/browse/GRAILS-8511" target="_blank">looks to be fixed</a> in Grails 2.0.1. I have yet to verify the fix, but if you also encounter this issue I urge you to try Grails 2.0.1 to see if it resolves the problem.</em></p>
<p>I am working on a Grails 2.0.x project and am quite enjoying some of the new features that are part of the current Grails release. The new test mixins that are part of Grails 2.0.x are awesome and really simplify the creation of your unit test classes. But I ran across a &#8220;gotcha&#8221; when using the test mixins.</p>
<p>I was writing a unit test class for a Grails controller, and was using the default template that gets created via:</p>
<p><code>grails create-controller com.asoftwareguy.example.Example</code></p>
<p>One of the helper methods exposed by the GrailsUnitTestMixin is the mockFor() method, which is a simplified way of creating a new Groovy mock. I though this to be much cleaner than needing to instantiate a new MockFor() every time I needed a mock proxy for an interface. However, I ran into an issue where the proxy instances created by the mockFor() method of the mixin are not cleaned up between test case runs. Let me give an example of what was failing.</p>
<p>ExampleController.groovy</p>
<p><pre class="brush: groovy;">

package com.asoftwareguy.example

class ExampleController {

  def exampleService

  def index() {
    def something = exampleService.doSomething()
    render (view: 'index', model: [something: something])
  }
}
</pre></p>
<p>ExampleService.groovy</p>
<p><pre class="brush: groovy;">
package com.asoftwareguy.example

interface ExampleService {
  List doSomething();
}
</pre></p>
<p>ExampleControllerTests.groovy</p>
<p><pre class="brush: groovy;">
package com.asoftwareguy.example

@TestFor(ExampleController)
class ExampleControllerTests {

  void testDoSomething_first_time() {
    def mockService = mockFor(ExampleService) //use the mixin
    mockService.demand.doSomething() { -&gt;
      return true
    }
    controller.exampleService = mockService.createMock()
    controller.index()
    // assertions
  }

  void testListStations_second_time() {
    def mockService = mockFor(ExampleService) //use the mixin
    mockService.demand.doSomething() { -&gt;
      return true
    }
    controller.exampleService = mockService.createMock()
    controller.index()
    // assertions
  }
}
</pre></p>
<p>With the above code in place, the first test case would always pass, but the second test case would fail with the following error:</p>
<pre>| Failure:  testListStations_second_time(com.asoftwareguy.example.ExampleControllerTests)
|  junit.framework.AssertionFailedError: No more calls to 'doSomething' expected at this point. End of demands.
at grails.test.MockClosureProxy.doBeforeCall(MockClosureProxy.java:66)
at grails.test.AbstractClosureProxy.call(AbstractClosureProxy.java:74)
at com.asoftwareguy.example.ExampleController.index(ExampleController.groovy:xx)
at com.asoftwareguy.example.ExampleControllerTests.testListStations_second_time(ExampleControllerTests.groovy:xx)
| Completed 2 unit tests, 1 failed</pre>
<p>After some troubleshooting and debugging the issue, I have concluded that there is a bug in the version of Grails I running (2.0.0) and hopefully it is fixed in the next release. As a workaround, I have reverted to instantiating new MockFor() instances within each test case.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=206&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2012/02/28/grails-2-0-mockfor-gotcha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>Web service clients &#8211; where Grails lost its mojo</title>
		<link>http://asoftwareguy.com/2012/02/25/web-service-clients-where-grails-lost-its-mojo/</link>
		<comments>http://asoftwareguy.com/2012/02/25/web-service-clients-where-grails-lost-its-mojo/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 05:10:43 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[groovyws]]></category>
		<category><![CDATA[jax-ws]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring-ws]]></category>
		<category><![CDATA[web service]]></category>
		<category><![CDATA[web service client]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=192</guid>
		<description><![CDATA[I am working on a Grails 2.0.x application that needs to consume some web services. Simple enough, I have written many clients in the past, using Axis and Spring-WS in Java, and WCF in .Net. Almost everything I have done so far was easy with Grails and Groovy, so I set out to create a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=192&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am working on a <a title="Grails" href="http://grails.org/doc/2.0.x/guide/introduction.html" target="_blank">Grails</a> 2.0.x application that needs to consume some web services. Simple enough, I have written many clients in the past, using <a title="Apache Axis" href="http://ws.apache.org/axis/overview.html" target="_blank">Axis</a> and <a title="Spring Web Services" href="http://static.springsource.org/spring-ws/sites/2.0/" target="_blank">Spring-WS</a> in Java, and WCF in .Net. Almost everything I have done so far was easy with Grails and Groovy, so I set out to create a client in Grails.</p>
<p>First off, I found <a title="GroovyWS" href="http://groovy.codehaus.org/GroovyWS" target="_blank">GroovyWS</a> and discovered the ease in which one can create clients with this tool. All was well when running Grails locally, but when the application deployed to our dev integration server (Tomcat 6, Java 6), it was throwing some exceptions about not finding the JAXB types for the specified class name. Apparently, the JAXB implementation on the dev integration was creating classes of different names than the implementation running on my local machine, from the same WSDL. I started debugging but quickly found myself in dependency hell, so I stepped back and tried a different client.</p>
<p>I had used Spring-WS before on a Spring 2.5 Java project and knew how it worked, so I gave it a shot. Even with this implementation, I was getting errors and again finding myself in dependency hell. There was still one more client I had used in the past, so I thought I would give it a try. Running wsdl2java against Axis 1.4 resulted in a client where classes actually would not compile. I attribute this to the complexity of the service itself and Axis&#8217; inability to correctly parse out the types correctly. In any case, no dice on Axis 1.4.</p>
<p>Then I remembered <a title="JAX-WS" href="http://en.wikipedia.org/wiki/Java_API_for_XML_Web_Services" target="_blank">JAX-WS</a>. It is the most up-to-date web service tool supported by Java. After some issues with wsimport failing to generate a client at all (the WSDL has not <a title="WS-I" href="http://www.ws-i.org/Profiles/BasicProfile-1.1.html" target="_blank">WS-I BP 1.1</a> compliant and was later fixed by the service developer), I was able to successfully generate the client. I integrated it with my code, fired up Grails, invoked the service and bam!:</p>
<p><code><br />
runtime modeler error: SEI rsastationinventorymgmtcontract.StationInventoryMgmtPT has method __execute annotated as BARE but it has more than one parameter bound to body. This is invalid. Please annotate the method with annotation: @SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)<br />
</code></p>
<p>What?! So JAX-WS doesn&#8217;t know how to correctly generate a client from a WSDL? I was doubtful and wanted to prove it worked. I created a simple Java application containing the source files for the generated client and a single Java class to test the service. I fired up the 1.6 JVM and ran the class, and lo and behold, the client invoked the service successfully. Then I thought, &#8216;Oh no, more dependency issues?!&#8217; Then I thought of something. What if I &#8216;forced&#8217; the JAX-WS implementation used at runtime? Surely that would help, right? I added the following to the Grails BuildConfig.groovy:</p>
<p><pre class="brush: css;">
grails.project.dependency.resolution = {
	...
	dependencies {
		...
		runtime('com.sun.xml.ws:jaxws-rt:2.1.4')
	}
}
</pre></p>
<p>I built the application and fired up Grails, and was able to invoke the service successfully.</p>
<p>All in all, I have been happy with my development experience in Grails, but dealing with web service clients left me wanting more from the framework in this area. Maybe it is just my unfamiliarity with the framework, but this solution was not obvious to me and left me scratching my head for a while.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=192&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2012/02/25/web-service-clients-where-grails-lost-its-mojo/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>A Groovy way to mask data</title>
		<link>http://asoftwareguy.com/2011/12/21/a-groovy-way-to-mask-data/</link>
		<comments>http://asoftwareguy.com/2011/12/21/a-groovy-way-to-mask-data/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 14:20:04 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=181</guid>
		<description><![CDATA[I was working on some code where I needed to mask data, and the application was being written in Groovy. I came up with this (what I think is a) neat trick to do it, using regular expressions and lambda expressions/closures.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=181&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was working on some code where I needed to mask data, and the application was being written in Groovy. I came up with this (what I think is a) neat trick to do it, using regular expressions and lambda expressions/closures.<br />
<pre class="brush: groovy;">
package example

class Model implements Serializable {
	...
	String value
	...

	def valueMasked() {
		return value.replaceFirst('.*(?=.{4})', { match -&gt;
			return &quot;&quot;.padLeft(match.length(), '*')
		});
	}
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=181&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2011/12/21/a-groovy-way-to-mask-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>nawk/grep script for counting occurences on line before</title>
		<link>http://asoftwareguy.com/2011/09/19/nawkgrep-script-for-counting-occurences-on-line-before/</link>
		<comments>http://asoftwareguy.com/2011/09/19/nawkgrep-script-for-counting-occurences-on-line-before/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:48:32 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[count occurences before line]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[nawk]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=174</guid>
		<description><![CDATA[I was helping out a co-worker of mine construct a script to find/count occurrences of a given string that occur on a line preceding another given string. Using GNU grep, this would be easy: Unfortunately, Solaris does not use GNU grep, so I had to resort to using nawk + grep: where within the nawk [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=174&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was helping out a co-worker of mine construct a script to find/count occurrences of a given string that occur on a line preceding another given string. Using GNU grep, this would be easy:</p>
<p><pre class="brush: bash;">
grep -B 1 tofind FILE_PATTERN | grep -c tofindabove
</pre></p>
<p>Unfortunately, Solaris does not use GNU grep, so I had to resort to using nawk + grep:</p>
<p><pre class="brush: bash;">
nawk 'c--&gt;0;$0~s{if(b)for(c=b+1;c&gt;1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=0 s=&quot;tofind&quot; FILE_PATTERN | grep -c tofindabove
</pre><br />
where within the nawk command,<br />
b: number of lines before match to display<br />
a: number of lines after match to display<br />
s: string to match</p>
<p><a href="http://www.unix.com/solaris/33533-grep-display-few-lines-before-after.html" title="Using nawk to display match in context" target="_blank">Credit</a> for the usage of the nawk command in this context.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/174/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=174&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2011/09/19/nawkgrep-script-for-counting-occurences-on-line-before/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>Now with GitHub!</title>
		<link>http://asoftwareguy.com/2011/07/05/now-with-github/</link>
		<comments>http://asoftwareguy.com/2011/07/05/now-with-github/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 13:50:22 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=163</guid>
		<description><![CDATA[I now have a GitHub account and have decided to move my lengthier code examples over from DropBox files to GitHub Gist. You can find the links in the updated posts.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=163&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I now have a <a href="https://github.com/geneticdisorder">GitHub account</a> and have decided to move my lengthier code examples over from DropBox files to <a href="https://gist.github.com/geneticdisorder">GitHub Gist</a>. You can find the links in the updated posts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=163&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2011/07/05/now-with-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>ExpandoObject and XML in C# 4.0</title>
		<link>http://asoftwareguy.com/2011/04/17/expandoobject-and-xml-in-c-4-0/</link>
		<comments>http://asoftwareguy.com/2011/04/17/expandoobject-and-xml-in-c-4-0/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 04:27:41 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC2]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[ExpandoObject]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=138</guid>
		<description><![CDATA[I am working on a .Net project recently and was toying with how to bring in configuration data from an XML file. I thought about creating XSD binding objects, but this felt to restrictive. I thought about creating a map for the data, but when you start nesting maps inside of maps ad nauseam, things [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=138&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am working on a .Net project recently and was toying with how to bring in configuration data from an XML file. I thought about creating XSD binding objects, but this felt to restrictive. I thought about creating a map for the data, but when you start nesting maps inside of maps ad nauseam, things can get a little confusing. Then I considered using Linq, but this still seems quite tedious. Then I started doing <a href="http://msdn.microsoft.com/en-us/magazine/ff796227.aspx">some</a> <a href="http://blogs.msdn.com/b/csharpfaq/archive/2009/10/01/dynamic-in-c-4-0-introducing-the-expandoobject.aspx">reading</a> on ExpandoObjects and the dynamic keyword, introduced in C# 4.0.</p>
<p>After some research and trial and error, I came up with The source code is also available <a href="https://gist.github.com/1064812">this snippet of code</a> that allowed me to create a dynamic object, based on the structure of the given XML document. Enjoy.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=138&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2011/04/17/expandoobject-and-xml-in-c-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring PropertyPlaceholderConfigurer within web and application context</title>
		<link>http://asoftwareguy.com/2010/11/19/spring-propertyplaceholderconfigurer-within-web-and-application-context/</link>
		<comments>http://asoftwareguy.com/2010/11/19/spring-propertyplaceholderconfigurer-within-web-and-application-context/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 14:18:03 +0000</pubDate>
		<dc:creator>asoftwareguy</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[applicationcontext]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[propertyplaceholderconfigurer]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[springframework]]></category>
		<category><![CDATA[web context]]></category>

		<guid isPermaLink="false">http://asoftwareguy.com/?p=122</guid>
		<description><![CDATA[I ran into an issue where I was attempting to load properties for a Spring 3.0 web application in both the application context configuration and the web application configuration.The configuration was initially defined as follows: applicationContext.xml Both the application context and the web context referenced the same &#8216;payment.proxy.X&#8217; placeholders, however, only the placeholders in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=122&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue where I was attempting to load properties for a Spring 3.0 web application in both the application context configuration and the web application configuration.The configuration was initially defined as follows:</p>
<p><a href="https://gist.github.com/1064817">applicationContext.xml</a></p>
<p>Both the application context and the web context referenced the same &#8216;payment.proxy.X&#8217; placeholders, however, only the placeholders in the application context resolved (ENV_CODE is resolved from the System properties). I found the following quote from Jürgen Höller, one of the founder of Spring, on the spring-dev list from a long time back:</p>
<blockquote><p>
PropertyPlaceholderConfigurer is an implementation of the<br />
BeanFactoryPostProcessor interface: This interface and its sibling<br />
BeanPostProcessor just apply to the BeanFactory that defines them, that is,<br />
to the application context that defines them.</p>
<p>If you combine multiple config files into a single contextConfigLocation, a<br />
PropertyPlaceholderConfigurer defined in any of the files will apply to all<br />
of the files, because they are loaded into a single application context.</p>
<p>However, a DispatcherServlet has its own application context, just using the<br />
root web application context as parent. Therefore, it needs to define its<br />
own BeanFactoryPostProcessors and/or BeanPostProcessors, in this case its<br />
own PropertyPlaceholderConfigurer.</p>
<p>I believe that this is the better general solution: Each application context<br />
might want to resolve its placeholders against its own properties files,<br />
where applying PropertyPlaceholderConfigurer from parent contexts would<br />
interfere.
</p></blockquote>
<p>I then defined the same PropertyPlaceholderConfigurer in both the application context and the web context and the issue resolved.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/asoftwareguy.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/asoftwareguy.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/asoftwareguy.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asoftwareguy.com&#038;blog=15771260&#038;post=122&#038;subd=asoftwareguy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asoftwareguy.com/2010/11/19/spring-propertyplaceholderconfigurer-within-web-and-application-context/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cda4957610d4783269e691c926e4db4b?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">asoftwareguy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
