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

<channel>
	<title>.Hibri</title>
	<atom:link href="http://www.hibri.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hibri.net</link>
	<description>The software philosopher</description>
	<lastBuildDate>Fri, 17 Feb 2012 13:14:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting started with web applications on Mono</title>
		<link>http://www.hibri.net/2012/02/17/getting-started-with-web-applications-on-mono/</link>
		<comments>http://www.hibri.net/2012/02/17/getting-started-with-web-applications-on-mono/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 13:14:59 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[.Net Web]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://www.hibri.net/2012/02/17/getting-started-with-web-applications-on-mono/</guid>
		<description><![CDATA[&#160; I’ve started to explore mono, with a view to moving some of our web applications to Linux. Used MonoDevelop&#160; on OSX to&#160; spike a simple HttpHandler to return a response.&#160; I was more interested in how the hosting and deployment story worked with mono. This is a little list of things I discovered as [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I’ve started to explore mono, with a view to moving some of our web applications to Linux. Used MonoDevelop&#160; on OSX to&#160; spike a simple HttpHandler to return a response.&#160; I was more interested in how the hosting and deployment story worked with mono.</p>
<p>This is a little list of things I discovered as I went along.</p>
<p><a href="http://www.mono-project.com/ASP.NET">http://www.mono-project.com/ASP.NET</a> has&#160; list of the hosting options available.&#160; Went with the Nginx option.&#160; Mono comes with xsp, which is useful for local testing.</p>
<h3>Running a simple web application</h3>
<p>To run xsp&#160; /usr/bin/xsp &#8211;port 9090 &#8211;root&#160; &lt;path to your application&gt;, and the application will be available on <a href="http://localhost:9090">http://localhost:9090</a></p>
<p>&#160;</p>
<p>To install Nginx on OSX,&#160; get <a href="http://mxcl.github.com/homebrew/" target="_blank">Homebrew</a>.&#160; And then simply&#160; <em>sudo brew install nginix</em></p>
<p>Follow the instructions here <a href="http://www.mono-project.com/FastCGI_Nginx">http://www.mono-project.com/FastCGI_Nginx</a> to configure Nginix to work with Mono’s FastCGI server.</p>
<p>On OSX, the Nginix configs can be found in /usr/local/etc/nginx/nginx.conf</p>
<p>This is the configuration I tried for my testing,</p>
<p>In /usr/local/etc/nginx/nginx.conf</p>
<p> server{   <br />&#160;&#160; listen 80;    <br />&#160;&#160; server_name localhost;    <br />&#160;&#160; access_log /<span class="kwrd">var</span>/log/nginx/localhost_mono_access.log;    <br />&#160;&#160; location / {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; root /Users/hibri/Projects/WebApp/;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; index <span class="kwrd">default</span>.aspx index.html;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; fastcgi_index <span class="kwrd">default</span>.aspx;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; fastcgi_pass 127.0.0.1:9000;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; include /usr/local/etc/nginx/fastcgi_params;    <br />&#160;&#160; }    <br />}    </p>
<p>Add the following lines to /usr/local/etc/nginx/fastcgi_params</p>
<pre> fastcgi_param  PATH_INFO          &quot;&quot;;
 fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;</pre>
<p>&#160;</p>
<p>Start Nginx.</p>
<p>Start the Mono FastCGI server</p>
<p>fastcgi-mono-server2<br />
  <br />&#160;&#160;&#160;&#160; /applications=localhost:/:/Users/hibri/Projects/WebApp/ /socket=tcp:127.0.0.1:9000</p>
<p></p>
<p>And the application is available on <a href="http://localhost">http://localhost</a></p>
<h3>Web Frameworks</h3>
<p>We use OpenRasta for the services I want to run on Linux. OR didn’t work out of the box. This is something I’ll be exploring in the next few days. </p>
<p>Tried <a href="http://servicestack.net/" target="_blank">ServiceStack</a> too, and was able to get one our projects (<a href="https://github.com/gregsochanik/basic-servicestack-catalogue">https://github.com/gregsochanik/basic-servicestack-catalogue</a>) working on Mono as is.&#160; <a href="https://github.com/NancyFx/Nancy" target="_blank">Nancy</a> is next on the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2012/02/17/getting-started-with-web-applications-on-mono/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>F# on OSX</title>
		<link>http://www.hibri.net/2011/09/21/f-on-osx/</link>
		<comments>http://www.hibri.net/2011/09/21/f-on-osx/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 15:15:10 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=539</guid>
		<description><![CDATA[Make sure you have the latest mono installed (http://www.go-mono.com/mono-downloads/download.html) Then download the F# CTP zip, from here http://msdn.microsoft.com/en-us/fsharp/cc835251 and extract  it. Download the mono strong name key to the same place where you&#8217;ve extracted F# to. Run sudo ./install-mono.sh &#160; There is also mono develop f# addin  but is currently broken with mono develop 2.6]]></description>
			<content:encoded><![CDATA[<p>Make sure you have the latest mono installed (<a href="http://www.go-mono.com/mono-downloads/download.html">http://www.go-mono.com/mono-downloads/download.html</a>)</p>
<p>Then download the F# CTP zip, from here</p>
<p><a href="http://msdn.microsoft.com/en-us/fsharp/cc835251">http://msdn.microsoft.com/en-us/fsharp/cc835251</a></p>
<p>and extract  it.</p>
<p>Download the mono strong name key to the same place where you&#8217;ve extracted F# to.</p>
<p>Run sudo ./install-mono.sh</p>
<p>&nbsp;</p>
<p>There is also <a href="http://functional-variations.net/monodevelop/">mono develop f# addin </a> but is currently broken with mono develop 2.6</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/09/21/f-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPA 2011 Roundup</title>
		<link>http://www.hibri.net/2011/06/16/spa-2011-roundup/</link>
		<comments>http://www.hibri.net/2011/06/16/spa-2011-roundup/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 13:12:31 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bcs]]></category>
		<category><![CDATA[spa 2011]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=520</guid>
		<description><![CDATA[A summary of my SPA (Software Practice Advancement) Conference experience. Node.js The session on node.js on Sunday, was my first serious introduction to server side js and node.js. Start by downloading the source at http://nodejs.org/#download, extract the source do ./configure and make install in the source directory. Takes a few minutes to build. The build works painlessly [...]]]></description>
			<content:encoded><![CDATA[<p>A summary of my <a href="http://www.spaconference.org/spa2011/">SPA (Software Practice Advancement) Conference</a> experience.</p>
<h3><a href="http://www.spaconference.org/spa2011/sessions/session366.html">Node.js</a></h3>
<p>The session on node.js on Sunday, was my first serious introduction to server side js and node.js.</p>
<p>Start by downloading the source at <a href="http://nodejs.org/#download">http://nodejs.org/#download</a>, extract the source do ./configure and make install in the source directory. Takes a few minutes to build. The build works painlessly on OSX and Linux. If you are on OSX install it via brew</p>
<p><a title="http://shapeshed.com/journal/setting-up-nodejs-and-npm-on-mac-osx/" href="http://shapeshed.com/journal/setting-up-nodejs-and-npm-on-mac-osx/">http://shapeshed.com/journal/setting-up-nodejs-and-npm-on-mac-osx/</a></p>
<p>The documentation is at <a href="http://nodejs.org/docs/v0.4.8/api/">http://nodejs.org/docs/v0.4.8/api/</a></p>
<p>Node.js is a good way to get into event driven non-blocking programming. It’s easy to do this when you think about doing things (sending responses, rendering) only when things happen.</p>
<p>For example, when data arrives on a socket listening on the server an event is triggered. Code is executed when events are triggered. Instead of polling and waiting for stuff to happen, which can be very in-efficient.</p>
<p>This got me thinking about tiny programs running in a system and only doing things as a result of something being triggered. This could lead to us writing code that is only needed by the system. Code that is not used by the system (i.e not triggered) are culled.</p>
<h3><a href="http://www.spaconference.org/spa2011/sessions/session369.html">Treating JavaScript as a programming language.</a></h3>
<p>Going on with the js theme, the guys from Caplin Systems, showed how to build applications with js while still testing the full stack. We were shown how to use Eclipse and JSTestDriver. We were also taken thorough building the full application stack using  domain and view models in js. While using a Model View View Model pattern with <a href="http://knockoutjs.com/">knockout.js</a> to bind the domain to client HTML.</p>
<h3><a href="http://www.spaconference.org/spa2011/sessions/session376.html">Master of Puppets</a></h3>
<p>I had mixed feelings about attending this session but in the end it was worth it. <a href="http://www.puppetlabs.com/">Puppet</a> is an open source platform to manage systems, similar to <a href="http://www.opscode.com/">Chef</a>. Puppet and Chef use recipes to build and configure machines. It seems to work smoothly with Ubuntu, using apt get to install and configure the software as specified in a recipe. Still no good Windows support though, which is going to make it hard to use at work.</p>
<p>It is also possible to use Puppet to control/build virtual machines using <a href="http://vagrantup.com/">vagrant</a>. There is also a VMware API and a ruby gem for the API . For further reading on this please follow the links below.</p>
<p><a title="http://www.jedi.be/blog/2009/11/17/controlling-virtual-machines-with-an-API/" href="http://www.jedi.be/blog/2009/11/17/controlling-virtual-machines-with-an-API/">http://www.jedi.be/blog/2009/11/17/controlling-virtual-machines-with-an-API/</a></p>
<p><a title="http://rubyvmware.rubyforge.org/" href="http://rubyvmware.rubyforge.org/">http://rubyvmware.rubyforge.org/</a></p>
<h3>Non-Technical Sessions</h3>
<p>I enjoyed the non-techy sessions very much. To start it off there was Rachel Davies’ session on <a href="http://www.spaconference.org/spa2011/sessions/session387.html">building trust within teams</a>. The slides from this are up now <a title="http://www.agilexp.com/presentations/SPA-ImprovingTrustInTeams.pdf" href="http://www.agilexp.com/presentations/SPA-ImprovingTrustInTeams.pdf">http://www.agilexp.com/presentations/SPA-ImprovingTrustInTeams.pdf</a></p>
<p>Benjamin Mitchell’s session on <a href="http://www.spaconference.org/spa2011/sessions/session403.html">double loop learning</a> was insightful. It made me think about how much my perception of things don’t necessarily reflect the reality. It is better to seek knowledge than take actions based on assumptions. It became clear how easily we can fall into this trap. There is more reading on double loop learning and the work by Chris Argyris here <a href="http://bit.ly/Argyris">http://bit.ly/Argyris</a></p>
<p><a href="http://www.spaconference.org/spa2011/sessions/session394.html">Developer anarchy at forward</a> clearly illustrated that to go faster, you need great devs and ditch technology that is slowing down feedback loops. It’s not just about building feedback loops, its how fast you can react to those loops is what matters. On the Internet scale, we’d would have to respond in seconds, minutes and at least in hours. Definitely not in days, sprints or months. In the conversation afterwards, learnt that they spent about 6 months re-building the tools and infrastructure that let them deliver at the speed that the do now.</p>
<p><a href="http://www.spaconference.org/spa2011/sessions/session378.html">Comic Communication and Collaboration</a> completed the SPA experience with much hilarity and fun. Think I could try my hand and xkcd style comics. More importantly, the insight learned was ,communicate by talking with peers, or communicate by producing something (i.e readable code, working software). If you have to communicate via email or worse through a 3rd party (i.e project manager) don’t bother. It’s not as effective as you think.</p>
<p>All in all, a very well organised conference, including the invited rants. Looking forward to next year.</p>
<p>Many thanks to those <a href="http://www.spaconference.org/spa2011/index.php?page=organisers">who organised it.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/06/16/spa-2011-roundup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocking HTTP Servers</title>
		<link>http://www.hibri.net/2011/06/11/mocking-http-servers/</link>
		<comments>http://www.hibri.net/2011/06/11/mocking-http-servers/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 13:03:44 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA["acceptance tests"]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=504</guid>
		<description><![CDATA[The problem There are tests (mostly what we call acceptance tests). The system under test (SUT) works with a couple of web services to do its work. The problem I&#8217;m faced with is that, when I write these tests, the external web services have to be arranged with data for the test, or the test [...]]]></description>
			<content:encoded><![CDATA[<h3>The problem</h3>
<p>There are tests (mostly what we call acceptance tests). The system under test (SUT) works with a couple of web services to do its work. The problem I&#8217;m faced with is that, when I write these tests, the external web services have to be arranged with data for the test, or the test has to rely on existing data. Writing these tests is extremely painful. Knowledge of the magic existing data is required and in the end what we are really writing are integration tests. But we don&#8217;t want integration tests.</p>
<p>At <a href="http://blogs.7digital.com/dev/">7digital</a>, we are exposing more of our domain via HTTP APIs, in a “NotSOA” manner. To test each service by itself it becomes necessary to mock the dependencies.</p>
<h3>Solutions.</h3>
<p>There are a couple of solutions to this.<br />
Set up an stub HTTP web service somewhere, and let it return canned responses. It behaves like the real web service, but only returns responses that have been arranged. The disadvantage of this approach is that I have to know about what canned responses have already been setup.</p>
<p>To change the response for a particular test I have to make changes to the stub server and deploy it, as it is a separate application. It takes the focus away from writing the test I&#8217;m concerned with.</p>
<p>Another way is to insert some sort of &#8220;switch&#8221; in production code that will return canned responses when under test. I don&#8217;t like this approach because it requires production code just for tests</p>
<h3>My solution.</h3>
<p>What I want to do is something similar to setting up mocks/stubs in unit tests, but to do it with an actual http server. To setup the stubbed responses in the test code itself, and not to have to make any change to production code, other than a configuration change.</p>
<p>So this is what I came up with</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span>[Test]</pre>
<pre><span class="lnum"> 2: </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> SUT_should_return_stubbed_response() {</pre>
<pre class="alt"><span class="lnum"> 3: </span>            IStubHttp stubHttp = HttpMockRepository</pre>
<pre><span class="lnum"> 4: </span>                .At(<span class="str">"http://localhost:8080/someapp"</span>);</pre>
<pre class="alt"><span class="lnum"> 5: </span></pre>
<pre><span class="lnum"> 6: </span></pre>
<pre class="alt"><span class="lnum"> 7: </span>            <span class="kwrd">const</span> <span class="kwrd">string</span> expected = <span class="str">"&lt;xml&gt;&lt;&gt;response&gt;Hello World&lt;/response&gt;&lt;/xml&gt;"</span>;</pre>
<pre><span class="lnum"> 8: </span>            stubHttp.Stub(x =&gt; x.Get(<span class="str">"/someendpoint"</span>))</pre>
<pre class="alt"><span class="lnum"> 9: </span>                .Return(expected)</pre>
<pre><span class="lnum"> 10: </span>                .OK();</pre>
<pre class="alt"><span class="lnum"> 11: </span></pre>
<pre><span class="lnum"> 12: </span>            <span class="kwrd">string</span> result = <span class="kwrd">new</span> SystemUnderTest().GetData();</pre>
<pre class="alt"><span class="lnum"> 13: </span></pre>
<pre><span class="lnum"> 14: </span>            Assert.That(result, Is.EqualTo(expected));</pre>
<pre class="alt"><span class="lnum"> 15: </span></pre>
<pre><span class="lnum"> 16: </span>        }</pre>
</div>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>HttpMockRepoisitory.At creates a HTTP server listening on port 8080, and behaves as if it is process request under the /someapp path. This is the web service that the SUT will get it’s data from.</p>
<p>Using the object returned,  it is possible to setup stubbed responses using a fluent syntax. The stub server can return text and files. I’ve posted a few more examples on github <a title="https://github.com/hibri/HttpMock/blob/master/src/HttpMock.Integration.Tests/HttpEndPointTests.cs" href="http://github.com/hibri/HttpMock/blob/master/src/HttpMock.Integration.Tests/HttpEndPointTests.cs">http://github.com/hibri/HttpMock/blob/master/src/HttpMock.Integration.Tests/HttpEndPointTests.cs</a></p>
<p>&nbsp;</p>
<h3>Kayak.</h3>
<p>I’m using <a href="http://kayakhttp.com/" target="_blank">Kayak</a>, a light weight, asynchronous HTTP server written in C#. Kayak, can accept request processing delegates, and post them to the HTTP server listening on the given socket. This allows me to add stub responses at runtime.</p>
<h3>Current status.</h3>
<p>This is very much a work in progress. HTTP GET works. There is support for returning stubbing content types and HTTP return codes. I’ll be able to add to this while changing a very large test suite to not rely on real web services.  I’ve created a repository on github at <a title="https://github.com/hibri/HttpMock" href="http://github.com/hibri/HttpMock">http://github.com/hibri/HttpMock</a></p>
<p>There are no unit tests now, but I’ll be adding them soon as I wanted to prove the concept first.</p>
<p>Describing this as mocking is not entirely correct, but I couldn’t find a term to describe the concept. It is possible to do the same in Ruby using Sinatra.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/06/11/mocking-http-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Learning Objective-C</title>
		<link>http://www.hibri.net/2011/05/28/on-learning-objective-c/</link>
		<comments>http://www.hibri.net/2011/05/28/on-learning-objective-c/#comments</comments>
		<pubDate>Sat, 28 May 2011 20:16:54 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=497</guid>
		<description><![CDATA[Learning Objective-C has been an interesting experience, and this is how I went about it. My motivation in learning Obj_C was most of all add another language to my toolkit. I wanted to get behind the mysteries of developing for the iOS. Found a fairly good set of coursework to get started at http://courses.csail.mit.edu/iphonedev/ . [...]]]></description>
			<content:encoded><![CDATA[<p>Learning Objective-C has been an interesting experience, and this is how I went about it.<br />
My motivation in learning Obj_C was most of all add another language to my toolkit. I wanted to get behind the mysteries of developing for the iOS.</p>
<p>Found a fairly good set of coursework to get started at<a href=" http://courses.csail.mit.edu/iphonedev/"> http://courses.csail.mit.edu/iphonedev/</a> . This is a very basic introductory course and the set of presentations guide you through developing a complete iPhone application. Before this I had no clue on how to use XCode. This helped me grasp the basic language concepts. Going through the whole set is highly recommended.</p>
<p>There is a very handy Obj-C tutorial at <a href="http://cocoadevcentral.com/d/learn_objectivec/">http://cocoadevcentral.com/d/learn_objectivec/</a></p>
<p>Setting up tests was frustrating in XCode 3. Although XCode4 has improved on this, it is no where near Eclipse and Visual Studio.  Skip the built in test framework  (STAssert) in favour of <a href="https://github.com/jonreid/OCHamcrest">OCHamcrest</a> and you&#8217;ll be in familiar territory. There was a bit of hair pulling in figuring out how to get XCode4 to use it.</p>
<p>Now that I&#8217;ve figured out XCode4 , I&#8217;m going through the  iOS development videos at <a href="https://developer.apple.com/videos/iphone/">http://developer.apple.com/videos/iphone/</a> .</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/05/28/on-learning-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I don&#8217;t like web service wrappers</title>
		<link>http://www.hibri.net/2011/05/10/why-i-dont-like-web-service-wrappers/</link>
		<comments>http://www.hibri.net/2011/05/10/why-i-dont-like-web-service-wrappers/#comments</comments>
		<pubDate>Tue, 10 May 2011 20:32:44 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[API]]></category>

		<guid isPermaLink="false">http://www.hibri.net/2011/05/10/why-i-dont-like-web-service-wrappers/</guid>
		<description><![CDATA[Martin Fowler’s post http://martinfowler.com/bliki/TolerantReader.html mirrors my thoughts on consuming web services. What is a web service wrapper ? A wrapper for a web service is a library, helps you deal with said service in the language programming language of your choice. It hides the details of the web service, and saves you the trouble of [...]]]></description>
			<content:encoded><![CDATA[<p>Martin Fowler’s post <a title="http://martinfowler.com/bliki/TolerantReader.html" href="http://martinfowler.com/bliki/TolerantReader.html">http://martinfowler.com/bliki/TolerantReader.html</a> mirrors my thoughts on consuming web services. </p>
<h3>What is a web service wrapper ?</h3>
<p>A wrapper for a web service is a library, helps you deal with said service in the language programming language of your choice. It hides the details of the web service, and saves you the trouble of having to know how to parse XML or JSON. The wrapper gives you first class objects to work with.</p>
<p>Many web service providers provide a wrapper for their services in most programming languages.</p>
<h3>Why I don’t like wrappers.</h3>
<p>I strongly believe that web services should be simple to use. If you expose a web service via HTTP, your consumers should be able to use any HTTP client to consume the service.</p>
<p>You should be able to use a web service by simply typing the URL for the web service method in the web browser’s address bar and see the result in the browser itself.&#160; You should be able to use a command line tool such as <a href="http://curl.haxx.se/" target="_blank">curl</a> to call the web service. Using a web service should not be more complicated than this. If you were hardcore even telnet should suffice.</p>
<p>To consume the service in code, the bare minimum a&#160; developer should need is a decent HTTP client library and a standard XML/JSON parser. Even a decent string library should suffice to make sense of the HTTP responses. These are pretty much available in the framework provided out of the box with the major programming languages. Of course there are situations where you’ll need more, but then this should be the exception and not the norm.</p>
<p>From the point of view of a web service provider, this simplicity increases adoption of your web service. Consumers don’t have to wait for you publish a new version of the wrapper library in order to start using a new service endpoint. Maintenance of the wrapper library is a non-issue, as you can focus on fixing issues with the service only, and not the wrapper library.</p>
<h3>Avoid using wrappers internally.</h3>
<p>When building a web service, avoid the temptation to use wrappers in your acceptance and integration tests. Strongly typed wrappers are a bad idea. I’ve seen this first hand when writing tests when building the <a href="http://developer.7digital.net/" target="_blank">7digital API</a>. Don’t even parse responses to strongly typed objects. I’ve forbidden the use of wrappers and strongly typed objects for testing the 7Digital API within my team.</p>
<p>The reason for this is, as a provider, you have to use the service as a consumer would. Wrappers hide the complexity of your own service, and you won’t know how complex the service has become.&#160; When you work with bare HTTP response strings, you will see potential usability issues that consumers will face.</p>
<h3>Publish sample code, but not wrappers.</h3>
<p>If you are providing a web service, my recommendation is to publish sample code, and not wrappers around your service. Show developers how to consume the service in their favorite programming languages. A good idea is to give them tests as Martin Fowler recommends. The tests can serve as sample code. They can run those tests against your service and see where the problem lies.</p>
<h3>Thoughts</h3>
<p>In my experience, using a strongly typed language such as C# has been a bad idea.&#160; Dynamic languages like Ruby can be used to write more tolerant wrappers. This is because with Ruby you can evaluate the API responses at run time rather than having to use an object that requires the response to be in a certain format.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/05/10/why-i-dont-like-web-service-wrappers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unit testing time eaters: Getting past them</title>
		<link>http://www.hibri.net/2011/05/04/unit-testing-time-eaters-getting-past-them-2/</link>
		<comments>http://www.hibri.net/2011/05/04/unit-testing-time-eaters-getting-past-them-2/#comments</comments>
		<pubDate>Wed, 04 May 2011 20:16:56 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=480</guid>
		<description><![CDATA[I was reading http://7enn.com/2011/05/02/the-biggest-time-eater-in-unit-testing/ the other day. How do we get past the discovery phase without getting stuck ? My suggestion is to start the tests with what you know and go with it. Think about it as we write the test. It will become clearer gradually. I’ll explain with an example. The test name. [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading <a title="http://7enn.com/2011/05/02/the-biggest-time-eater-in-unit-testing/" href="http://7enn.com/2011/05/02/the-biggest-time-eater-in-unit-testing/">http://7enn.com/2011/05/02/the-biggest-time-eater-in-unit-testing/</a> the other day. </p>
<p>How do we get past the discovery phase without getting stuck ? </p>
<p>My suggestion is to start the tests with what you know and go with it. Think about it as we write the test. It will become clearer gradually. </p>
<p>I’ll explain with an example.</p>
<p>The test name. This is the part where most of us get stuck. It’s an art. Getting it right is solving half the problem, but lets not get stuck on it. It doesn’t matter if we don’t have the perfect test name at the start. Give it a name that is good enough. </p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> Foo () {

}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&nbsp;</p>
<p>This is all we need for now. </p>
<p>We have name, we have a test, our test runner can run the test.</p>
<p>Next. What is the proper outcome to test for ?.&nbsp; In other words what are we testing ?</p>
<p>Start with the assert first.&nbsp; Assume we want the title property in some object set to the expected value. Don’t worry about what type the object is, if you don’t have it already.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> Foo (){

  Assert.That(fooObject.Title, Is.EqualTo(expectedTitle));

}</pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>Start with the smallest thing you can assert. Let’s not be concerned with all the other things that need to be tested. In the example code above, I’m testing that an object named fooObject has it’s Title property set to the expected string. At this point I’m not concerned about the exact value of the expectation.</p>
<p>We have an assert. Something needs to happen in the thing we are testing. This is the action. Think about where we get fooObject from.</p>
<p>Some action needs to be executed to get an instance. This action is a method. In code , the way to make something happen is to call a method.</p>
<p>Create a method. Let’s not get stuck on the name too much. I’ll call it Get(). Calling Get() gives me fooObject.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> Foo (){

   var fooObject = controller.Get();
  Assert.That(fooObject.Title, Is.EqualTo(expectedTitle));

}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&nbsp;</p>
<p>We have an assert and an action. The code even compiling yet. Keep typing.</p>
<p>Our object controller needs to be an instance of something. Is this an existing object we are testing ?, if not I’ll create it.&nbsp; We always have a context in which we are writing a unit test. This gives us an indication on what the thing we are testing should be called. </p>
<p>In this example, we are testing a Controller. Instantiate the controller object.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> Foo (){

 var controller = <span class="kwrd">new</span> HomeController();

  var fooObject = controller.Get();  

 Assert.That(fooObject.Title, Is.EqualTo(expectedTitle));

}</pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>Next use resharper ( or similar tool for your language) to create the missing objects. Let’s make the code compile at this time. Give a value for the expectation. Don’t worry about which project (in Visual Studio) the classes will be in. It’s fine to keep it in the test class for now.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> Foo (){

<span class="kwrd">string</span> expectedTitle = <span class="str">"some title"</span>;
 var controller = <span class="kwrd">new</span> HomeController();

  var fooObject = controller.Get();  

 Assert.That(fooObject.Title, Is.EqualTo(expectedTitle));

}</pre>
<pre class="csharpcode">&nbsp;</pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>We have an assert, action and arrange. Read it the other way.&nbsp; Arrange, Act and Assert. The 3 parts we need for a test.</p>
<p>Run the test, see it fail. Write the bare minimum of code to make the test pass. Even hardcode things. Get a green bar. Even give temporary names. </p>
<p>Let’s refactor.&nbsp; Rename things. The test is much more clearer now. Rename Foo to ShouldSetTitleOnView.&nbsp; </p>
<p>Run the tests again, and keep renaming things. Move files to where they should be.</p>
<p>At this point we can think about injecting dependencies. Remember those hard coded values we put in to make the test pass ? </p>
<p>Inject a dependency to give those values. There is now a place to inject dependencies, the constructor of the HomeController. </p>
<p>To summarize,</p>
<p>Writing the assert first, gives a focal point for the test. Working backwards from this focal point ensures that we write the bare minimum code needed to make the test pass. We don’t need to worry about injecting dependencies that are not even relevant to what we are asserting.</p>
<p>Avoid thinking about your team/company standards of how you should write your tests. Just write the test with what you know. You can always rename things later when you have a green bar to the appropriate standard.</p>
<p>You can follow the same pattern even in unit tests, integration tests or acceptance tests. By doing this we speed up our discovery phase by writing the tests. </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;<br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2011/05/04/unit-testing-time-eaters-getting-past-them-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experiences of a Lead Developer</title>
		<link>http://www.hibri.net/2010/10/02/experiences-of-a-lead-developer/</link>
		<comments>http://www.hibri.net/2010/10/02/experiences-of-a-lead-developer/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 15:40:48 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA["team leading" "lead developer" "agile software develoment"]]></category>

		<guid isPermaLink="false">http://www.hibri.net/?p=464</guid>
		<description><![CDATA[It has been 3 years and a bit since I started leading software teams and recently I’ve been reflecting on my experiences since then. I’ve lead 3 teams, all working on core and large products for the companies I’ve worked for. My current and 3rd team is in the midst of a rebirth and in [...]]]></description>
			<content:encoded><![CDATA[<p>It has been 3 years and a bit since I started leading software teams and recently I’ve been reflecting on my experiences since then. </p>
<p>I’ve lead 3 teams, all working on core and large products for the companies I’ve worked for. My current and 3rd team is in the midst of a rebirth and in many ways my 4th team.</p>
<p>No team is the same. What worked for one team does not work for the other. Each team has had different approaches to testing, coding standards and work ethics.</p>
<p>What I’d like to reflect upon is what I did, what worked, what didn’t work. I’m very much interested in what other lead devs do for their teams.</p>
<h2>What does a lead developer / team lead do ?</h2>
<p>I’m not going to define the role here, only to describe what I’ve had to do as a lead dev so far.</p>
<p>Facilitate standups and retrospectives. Watch out for <a href="http://martinfowler.com/articles/itsNotJustStandingUp.html" target="_blank">standup smells</a></p>
<p>Act as a buffer between product ownership/ project management and the team. </p>
<p>Make the call on technical decisions. Have the technical architect hat handy.</p>
<p>Mentor developers. Enforce TDD, refactoring and clean code practices. I say enforce but not encourage. this is because I believe in these so strongly that I’m not willing let my team do anything else.</p>
<p>Build a team that learns not a team that expects me to tell them what to do. Do regular katas and demos of new tools/techniques we can use.&#160; Do code reviews and refactoring exercises as a team, in front of a projector.</p>
<p>Keep the team focused. I’ve done this by having the team not work on anything else other than what our card wall says.</p>
<p>Know the product/ project thoroughly. Learn the quirks, know where everything is. Know the source, read the source to figure out what is going on.</p>
<p>Own the release process, do releases.</p>
<p>Do the grunt work. As a lead dev, I’ve spent an great deal of time on build and deployment scripts. Setting up source control and continuous integration with Teamcity</p>
<p>Staying out of the way. Leave&#160; the majority of the work to the team. I expect to be pulled into meetings, asked to answer questions and deal with issues outside of the team. Part of this is good, as this takes away distractions from the rest of the team, but this also means that I can’t work on something continuously and see it to the end most of the time.&#160; Let someone else in the team own the work.</p>
<p>Be there for the team, be prepared to answer questions all the time. This could be design decisions, having to explain the domain, or the history of why something was done in a certain way. This can be exhausting but it is necessary.&#160; </p>
<p>Listen to the team chatter. Ask what is going on, when there is a discussion around code or a problem. Listen, observe and break into the conversation if needed.</p>
<p>Know the strengths and weaknesses of each team member. Know what they can do and what they cant do. Manage pair programming, some pairs may not be productive. This is necessary in the early stages of a team, but there will always be differences in skill levels.</p>
<h2>What works.</h2>
<p>I’ve covered a few of these above, but these the short list below is what I think every team needs.</p>
<p>Fostering a learning culture. The best teams I’ve had learned together and taught each other.</p>
<p>Strong discipline in the team.&#160; Stick to what we’ve agreed as a team.</p>
<p>Having a programming god on the team. An expert, for example who knows NHibernate, MVC or can write a book on TDD, help with technical decisions, and tell you what you are doing is wrong. Someone who can go away and figure out the hard things and come back and present to the team.</p>
<p>Automate automate automate.</p>
<p>Have people with passion for what they do. Encourage this.</p>
<h2>What doesn’t work.</h2>
<p>Team members with an aversion to pair programming and sharing. No rock stars or heroes. Notice this early, don’t ignore it. This will fester and kill team morale.</p>
<p>Fear of code, and fear of breaking things. People shouldn’t be afraid to make mistakes. Mistakes are ok, we learn by breaking things. Give team members the power and confidence to change things.</p>
<p>Indiscipline. Nip it in the bud. Tell people when they are not following the rules and agreed practices. This is something I’ve learned the hard way.</p>
<p>Self organization without direction. Self organization needs a goal. A team suffers when they don’t have know what they are working towards.</p>
<p>Team democracy is not always good, a benevolent dictatorship works much better.</p>
<h2>It’s the team, not the project.</h2>
<p>An important lesson I’ve learnt is that, what matters is not the software we produce, it is what the team learns while writing all that code. The code we write is an expression of what we learn, and every new line of code is a new learning opportunity.</p>
<p>A good project, with quality code and a few bugs in production is a side effect of a good team, and this team is the most important asset a company has, and not the software that was produced.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2010/10/02/experiences-of-a-lead-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thoughts on branching strategies.</title>
		<link>http://www.hibri.net/2010/05/17/thoughts-on-branching-strategies/</link>
		<comments>http://www.hibri.net/2010/05/17/thoughts-on-branching-strategies/#comments</comments>
		<pubDate>Mon, 17 May 2010 21:00:42 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.hibri.net/2010/05/17/ThoughtsOnBranchingStrategies.aspx</guid>
		<description><![CDATA[There comes a time during every project, when someone in the team asks the question “What is our branching strategy? “. Off we go trying to find out what is the current branching best practice, what are other teams using ? , What is the Agile way ? We may find solutions in feature branching, [...]]]></description>
			<content:encoded><![CDATA[<p>There comes a time during every project, when someone in the team asks the question “What is our branching strategy? “. Off we go trying to find out what is the current branching best practice, what are other teams using ? , What is the Agile way ? We may find solutions in <a href="http://martinfowler.com/bliki/FeatureBranch.html" target="_blank">feature branching</a>, per story branches, <a href="http://svnbook.red-bean.com/en/1.5/svn.branchmerge.commonpatterns.html" target="_blank">release branches</a> and so on.</p>
<p>Let’s take a step back. Why do we need a branching strategy ? What is a branch ?</p>
<p>We want to put some code in a source control branch, because the code contains the risk of breaking the software in the mainline of development, trunk. </p>
<p>Are we 100% sure that the code in the branch won’t break what is in trunk ? We won’t know for sure till we integrate the branch with trunk.&#160; We won’t know, until it goes through automated/manual testing, and all this after going through merge hell.</p>
<p>We put code in a branch to reduce risk. However, we haven’t reduced that risk. The risk is still there, and we bring it back into trunk. Why not look at methods of reducing the risk in the first place ? </p>
<p>How do we reduce risk ?</p>
<p><strong>1. Cut up a big piece of risk into smaller pieces of risk.</strong> </p>
<p>The bigger the risk the more chopping it needs. Now we have smaller things to work on. We do those small pieces one by one, and if something breaks, we know which change broke it. Easier to fix because it was a small change. </p>
<p><strong>2. Break down a big piece of risk, into parts that have no risk and parts that have risk.</strong> </p>
<p>Analyze the problem, break it out in to parts that can be done without breaking our software. This is interesting. The part which we thought would be a problem might have become a non-issue. We’ve isolated it. We know exactly which change will break our software. See 1 above</p>
<p><strong>3. Write tests for things that can be broken by the risky bit of code and continuously test.</strong> </p>
<p>We know what could break, by the new change. Before we make the change, let’s write tests for our software so we know when it is broken.&#160; Let’s make a change. Is anything broken ? No. Did the next change break it ? yes. Fix it. Keep going.</p>
<p>Instead of shoving off our risky code into a branch, we’ve learnt to manage the risk, and reduce it. If the risk is so high that we can’t mitigate it by doing 1,2 and 3, then let’s create a branch for the code. We have a branching strategy based on risk. We create a branch only for code that is riskiest, and we haven’t been able to reduce that risk by a divide and conquer approach.</p>
<p>In my opinion this is a much better way than having a default branching strategy for every piece of work/story/feature/MMF. Working continuously on trunk has benefits. We can release a feature faster, get refactoring changes others have made quicker. Not go through merge hell, and risk loosing code in the process. Along the way we’ve learnt how to break up a problem into smaller pieces. We’ve got better at writing tests. We’ve learnt how to structure our software so that one thing does not break everything else and we get closer to the nirvana of <a href="http://toni.org/2010/05/19/in-praise-of-continuous-deployment-the-wordpress-com-story/" target="_blank">continuous deployment</a>, because we have only one production line of code to deploy from.</p>
<p>Do you need a branching strategy ? Think again.</p>
<p>&#160;</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f6aa0a36-a879-49f6-afe1-ead4480d5b94" class="wlWriterSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/%22branching+strategies%22" rel="tag">&quot;branching strategies&quot;</a>,<a href="http://del.icio.us/popular/%22agile+branching%22" rel="tag">&quot;agile branching&quot;</a>,<a href="http://del.icio.us/popular/branching" rel="tag">branching</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2010/05/17/thoughts-on-branching-strategies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to : Sign XML messages with a SHA-1 signature, for Adobe Content Server</title>
		<link>http://www.hibri.net/2010/02/14/how-to-sign-xml-messages-with-a-sha-1-signature-for-adobe-content-server/</link>
		<comments>http://www.hibri.net/2010/02/14/how-to-sign-xml-messages-with-a-sha-1-signature-for-adobe-content-server/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 11:38:53 +0000</pubDate>
		<dc:creator>Hibri Marzook</dc:creator>
				<category><![CDATA[.Net General]]></category>

		<guid isPermaLink="false">http://www.hibri.net/2010/02/14/HowToSignXMLMessagesWithASHA1SignatureForAdobeContentServer.aspx</guid>
		<description><![CDATA[The past week I’ve been doing a spike to talk to Adobe Content Server 4 (ACS4). Querying the content in ACS4 is done in a REST style. The client sends a XML message via HTTP POST to the admin endpoint. The endpoint details are in the documentation but are vague.&#160; This is usually at&#160; http://youracs4server/admin/EndPoint. [...]]]></description>
			<content:encoded><![CDATA[<p>The past week I’ve been doing a spike to talk to <a href="http://www.adobe.com/products/contentserver/" target="_blank">Adobe Content Server 4</a> (ACS4). Querying the content in ACS4 is done in a REST style. The client sends a XML message via HTTP POST to the admin endpoint. The endpoint details are in the documentation but are vague.&#160; This is usually at&#160; <strong><a href="http://youracs4server/admin/EndPoint">http://youracs4server/admin/EndPoint</a></strong>. </p>
<p>These need a signed XML message, in the POST body. A typical message looks like this</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">request</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">nonce</span><span class="kwrd">&gt;</span>ABCD123==<span class="kwrd">&lt;/</span><span class="html">nonce</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">hmac</span><span class="kwrd">&gt;</span>XXXXXXXXX===<span class="kwrd">&lt;/</span><span class="html">hmac</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">distributor</span><span class="kwrd">&gt;</span>uid:8888-43434-34343434<span class="kwrd">&lt;/</span><span class="html">distributor</span><span class="kwrd">&gt;</span>
   <span class="kwrd">&lt;</span><span class="html">resource</span><span class="kwrd">&gt;</span>
     ......
   <span class="kwrd">&lt;/</span><span class="html">resouce</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">request</span><span class="kwrd">&gt;</span></pre>
<pre class="csharpcode"><span class="kwrd"></span>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</pre>
<p>The hmac element contains the SHA1 signature&#160; of the XML message. The signature is generated using a shared secret.&#160; The signature is for the whole XML except the hmac element. Before signing the message, we have to construct the XML without the hmac, then sign it, and then add then hmac.</p>
<p>I did this by using a two stage Xml serialization process. This may not be the best way to do it, and there has to be a better solution.&#160; I created a class named SignedXMLSerializer, and this inherits from <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx" target="_blank">XmlSerializer</a>. SignedXMLSerializer serializes objects that are of the base type Signable. The Signable class has two properties, Nonce and Hmac. Any class that has to be sent as a signed XML message must inherit from Signable</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> Signable
    {
        [XmlElement(<span class="str">&quot;nonce&quot;</span>)]
        <span class="kwrd">public</span> <span class="kwrd">string</span> Nonce { get; set; }

        [XmlElement(<span class="str">&quot;hmac&quot;</span>)]
        <span class="kwrd">public</span> <span class="kwrd">string</span> HMAC { get; set; }
    }</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>In the serialize method of the SignedXMLSerializer, we first generate the nonce. The nonce makes each message unique. Then we serialize the object to a string. The signature is generated using this string, and assigned it to the Hmac property.</p>
<p> We then serialize the signed object to the writer that was passed in.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">void</span> Serialize(T o, XmlTextWriter writer) {
            o.Nonce = GenerateNonce();
            StringBuilder stringBuilder = GetXMLToSign(o);
            <span class="kwrd">string</span> hmac = GetSignature(stringBuilder);
            o.HMAC = hmac;
            Serialize(writer, o);
        }</pre>
<pre class="csharpcode">To use the SignedXMLSerializer, pass in one of the <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx" target="_blank">HashAlgorithm</a> types. I’ve used SHA1 in my case.</pre>
<pre class="csharpcode">This makes it easier to use with different signing algorithms. </pre>
<pre class="csharpcode">Typical usage of the SignedXMLSerializer is as follows</pre>
<pre class="csharpcode">HMACSHA1 hmacsha1 = <span class="kwrd">new</span> HMACSHA1 {Key = Encoding.ASCII.GetBytes(<span class="str">&quot;consumerSecret&quot;</span>)};
            SignedXmlSerializer&lt;Request&gt; signedXmlSerializer = <span class="kwrd">new</span> SignedXmlSerializer&lt;Request&gt;(hmacsha1);

 StringBuilder sb = <span class="kwrd">new</span> StringBuilder();
            StringWriter writer = <span class="kwrd">new</span> StringWriter(sb);
            signedXmlSerializer.Serialize(req, <span class="kwrd">new</span> XmlTextWriter(writer));</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The final serialized string can be sent via HTTP post to ACS4.&#160; </p>
<p>Code for the SignedXMLSerializer class is here <a title="http://gist.github.com/303962" href="http://gist.github.com/303962">http://gist.github.com/303962</a></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:dce654d7-c3f9-4b00-8118-1e8524af3791" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/%22Adobe+Content+Server%22" rel="tag">&quot;Adobe Content Server&quot;</a>,<a href="http://del.icio.us/popular/xml" rel="tag">xml</a>,<a href="http://del.icio.us/popular/sha-1" rel="tag">sha-1</a>,<a href="http://del.icio.us/popular/%22signing+xml+messages%22" rel="tag">&quot;signing xml messages&quot;</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.hibri.net/2010/02/14/how-to-sign-xml-messages-with-a-sha-1-signature-for-adobe-content-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

