<?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>Callista Blog</title>
	<atom:link href="http://blog.callistaenterprise.se/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.callistaenterprise.se</link>
	<description>Our consultants share their reflections on IT architecture.</description>
	<lastBuildDate>Sun, 13 Jun 2010 22:40:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get rid of your tedious and error-prone release process</title>
		<link>http://blog.callistaenterprise.se/2010/06/14/get-rid-of-your-tedious-and-error-prone-release-process-2/</link>
		<comments>http://blog.callistaenterprise.se/2010/06/14/get-rid-of-your-tedious-and-error-prone-release-process-2/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 22:40:31 +0000</pubDate>
		<dc:creator>Magnus Ekstrand</dc:creator>
				<category><![CDATA[Build]]></category>
		<category><![CDATA[Build automation]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.callistaenterprise.se/?p=570</guid>
		<description><![CDATA[It&#8217;s best practice to tag  each of your stable releases in your version control system for future  reference. However, it is very rare that this sort of work is free from failure. Like many tedious, error-prone tasks, it is one of  those things that could do with a bit of automation.
Luckily, the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s best practice to tag  each of your stable releases in your version control system for future  reference. However, it is very rare that this sort of work is free from failure. Like many tedious, error-prone tasks, it is one of  those things that could do with a bit of automation.</p>
<p>Luckily, the <strong>Maven  Release plugin</strong> can help you automate the whole process of upgrading  your POM version number and tagging a release version in your version  control system, and all of this with a single maven command. You can  even automate the entire release process by running the command in a  cronjob or a Continuous Integration system. Amazing!</p>
<p>Here is  an extract from a project&#8217;s top POM file, showing the version number  that uniquely identifies this version.</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;project&gt;</span><br />
<span>&#8230;</span><br />
<span>&lt;groupId&gt;se.nll.mhp&lt;/groupId&gt;</span><br />
<span>&lt;artifactId&gt;mhp&lt;/artifactId&gt;</span><br />
<span>&lt;packaging&gt;pom&lt;/packaging&gt;</span><br />
<span>&lt;version&gt;1.1-SNAPSHOT&lt;/version&gt;</span><br />
<span>&#8230;</span><br />
<span>&lt;/project&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>The  SNAPSHOT suffix means that each time I deploy this version, a new  snapshot will be deployed into my local Maven repository. Anyone who  wants to use the latest, bleeding-edge SNAPSHOT version can add a  SNAPSHOT dependency in their project. Snapshots, by definition, tend to  be fairly unstable beasts.</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;project&gt;</span><br />
<span> &#8230;</span><br />
<span> &lt;dependencies&gt;</span><br />
<span> &#8230;</span><br />
<span> &lt;dependency&gt;</span><br />
<span> &lt;groupId&gt;se.nll.mhp&lt;/groupId&gt;</span><br />
<span> &lt;artifactId&gt;mhp-bc&lt;/artifactId&gt;</span><br />
<span> &lt;version&gt;1.1-SNAPSHOT&lt;/version&gt;</span><br />
<span> &lt;/dependency&gt;</span><br />
<span> &#8230;</span><br />
<span> &lt;/dependencies&gt;</span><br />
<span><span>&#8230;</span><br />
<span>&lt;/project&gt;</span> </span></code><br />
<span>&nbsp;</span>
</div>
<p>When  the version 1.1 is ready, you need to:</p>
<ol>
<li>update the  POM file</li>
<li>commit the new POM file to version control</li>
<li>tag  this version as a release</li>
<li>and then move on to work on  version 1.2</li>
</ol>
<p><span style="font-family: verdana;"><br />
The Maven Release plugin can automate  much of this process. However, before the Maven Release plugin can do  its work, you need to make sure you have everything it needs set up in  your POM file.<br />
</span></p>
<p><span style="font-family: verdana;"><br />
First of all, you need to be working with a  SNAPSHOT release. However, when you are ready to release your new  version, you should <strong>remove any references to snapshots in your  dependencies</strong>. This is because a release needs to be stable, and a  build using snapshots is, by definition, not always reproducible. Maven  will not accept any snapshot references and force the user to change it  during the release process. If you answer is no (as below) to the  question of resolving dependencies or not, Maven will fail your build.<br />
</span></p>
<div style="font-family: courier new; font-size=7px">
<span>[INFO]  Checking dependencies and plugins for snapshots ...</span><br />
<span>There are still some remaining snapshot  dependencies.: Do you want to resolve them now? (yes/no) no: : no</span><br />
<span>[INFO]  --------------------------------------------------------------</span><br />
<span>[ERROR] BUILD FAILURE</span><br />
<span>[INFO]  --------------------------------------------------------------</span><br />
<span>[INFO] Can't release project due to non released  dependencies :</span><br />
<span> eu.jakubiak:jakubiak-red5-core:jar:0.9-SNAPSHOT:provided </span><span>in project 'mhp-red5'  (se.nll.mhp:mhp-red5:war:1.1-SNAPSHOT)</span><br />
<span>&nbsp;</span>
</div>
<p>The next thing  you need is another section in your POM file. Maven will tag your  project and commit it to your source control system. So it needs to know  the location of your source control system. You generally don’t need to  specify credentials as Maven inherits those from the environment. If  Maven needs credentials it will prompt you during the release process.</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;project&gt;</span><br />
<span> ...</span><br />
<span> &lt;scm&gt;</span><br />
<span> &lt;connection&gt;scm:svn:https://svn.forge.osor.eu/svn/mhp/code/trunk&lt;/connection&gt;</span><br />
<span> &lt;developerConnection&gt;scm:svn:https://svn.forge.osor.eu/svn/mhp/code/trunk&lt;/developerConnection&gt;</span><br />
<span> &lt;url&gt;https://svn.forge.osor.eu/svn/mhp/code/tags/trunk&lt;/url&gt;</span><br />
<span> &lt;/scm&gt;</span><br />
<span> ...</span><br />
<span>&lt;/project&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>You  can find reference documentation for the &lt;<i>scm</i>&gt; tag <span style="color: #000000;"><a title="Maven SCM - SCM URL format" href="http://maven.apache.org/scm/scm-url-format.html" target="_blank">here</a></span>.</p>
<p>Next, you  need to configure the Release plugin itself. This mainly involves  telling Maven where your release tags go, via the "tagBase"  configuration element. If you are using the Subversion  trunk/tags/branches convention, Maven will automatically put release  tags in the "tags" directory. I prefer to use a a slight variation on  the normal convention, and place releases in the "tags/releases"  directory:</p>
<div style="font-family: courier new; font-size=7px">
<span><span>&lt;project&gt;</span><br />
<span> ...</span><br />
<span> &lt;plugins&gt;</span><br />
<span> ...</span><br />
<span> &lt;plugin&gt;</span><br />
<span> &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;</span><br />
<span> &lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;</span><br />
<span> &lt;configuration&gt;</span><br />
<span> &lt;tagBase&gt;https://svn.forge.osor.eu/svn/mhp/code/tags/releases&lt;/tagBase&gt;</span><br />
<span> &lt;/configuration&gt;</span><br />
<span> &lt;/plugin&gt;</span><br />
<span> ...</span><br />
<span> &lt;/plugins&gt;</span><br />
<span> ...</span><br />
<span>&lt;/project&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>Now it's time to  get down to business, and try out a (semi-)automated release. The first  thing you need to do is to make sure all your latest changes have been  committed to your SCM system. If there are any outstanding changes,  Maven won't let you do a release. First of all, you need to prepare the  release, using the "prepare" goal:</p>
<div style="font-family: courier new; font-size=7px">
<span>&gt;  mvn release:prepare</span><br />
<span>&nbsp;</span>
</div>
<p>This goal will ask you a series of  questions to confirm:</p>
<ul>
<li>what version number you  want to release</li>
<li>what new snapshot version number you  want to use</li>
<li>where you want to place the release tag.</li>
</ul>
<p><span style="font-family: verdana;"><br />
If  you have set up your POM file correctly, these will have sensible  defaults, and you won't have to do much thinking. If you which you can  disable these questions using the "<span style="color: #ff0000;">--batch-mode</span>"  command line option. But to me it's a good last healthy check walking  through these questions.<br />
</span></p>
<p><span style="font-family: verdana;"><br />
If you want to know exactly what  Maven will do to your POM file and your SCM ahead of time (generally a  good idea), you can run the operation in the "dry-run" mode, as shown  here.</span></p>
<div style="font-family: courier new; font-size=7px">
<span>&gt; mvn release:prepare  -DdryRun=true</span><br />
<span>&nbsp;</span>
</div>
<p><span style="font-family: verdana;">This useful trick simulates  the SCM operations by writing them out to the console, and creates three  sample POM files that you can consult:</span></p>
<ul>
<li><span style="font-family: verdana;"><span style="font-family: courier new;">pom.xml.tag</span>, which is  the pom file that will be committed to Subversion and tagged </span></li>
<li><span style="font-family: verdana;"><span style="font-family: courier new;">pom.xml.next</span>, which  contains the next snapshot version number</span></li>
</ul>
<p><span style="font-family: verdana;"><br />
I recommend you to do a dry-run the first time you're  doing you use the Maven Release plugin. It is very useful and will  learn you about the set up of your own project and sub-projects. When  you're satisfied with what Maven will do, you can do it for real:</span></p>
<div style="font-family: courier new; font-size=7px">
<span>&gt; mvn release:clean release:prepare</span><br />
<span>&nbsp;</span>
</div>
<p>Things  you should know about the <span style="font-family: courier new;">prepare</span> goal:</p>
<ol>
<li>The command <i>checks  for local modifications</i>. If you have any modified files but not  checked in, the command will stop and ask you to first check-in modified  files.</li>
<li>Your project cannot have any <i>SNAPSHOT  dependencies</i> in your project. It's a requirement.</li>
<li>You  will be asked to <i>specify versions</i> for the release and the next  SNAPSHOT (e.g. going from "<span style="font-family: courier new;">1.1-SNAPSHOT</span>"  to "<span style="font-family: courier new;">1.1</span>"). Accept the default values if  unsure.</li>
<li>Maven will run all your <i>unit tests</i> to  make sure they work after changing the project version in pom.xml.</li>
<li><strong>Commit</strong> the changes made to the POM file</li>
<li>If all tests pass,  Maven will <strong>tag the source</strong> in the source control with the release  version you specified in step 3 above.</li>
<li><i>Update</i> the  SNAPSHOT version number to a new SNAPSHOT version (e.g. going from "<span style="font-family: courier new;">1.1</span>" to "<span style="font-family: courier new;">1.2-SNAPSHOT</span>")</li>
<li>Maven  collects all the information that you provide and write a local file  called <i>release.properties</i>. This file lets you continue from where  you left in case of errors.</li>
<li><i>Undo.</i> You can undo  everything you’ve done so far with <strong>mvn release:clean</strong> to start all  over.</li>
</ol>
<p><span style="font-family: verdana;"><br />
Indeed, the <span style="font-family: courier new;">prepare</span> goal does quite a lot. Once you're finished, you have your release  version tagged in Subversion and you are working on a new SNAPSHOT  version.</p>
<p>So far we have only  set everything up in preparation for the release. Nothing have actually  been released yet. But dont worry, performing the release is easy. Just  use "mvn release:perform" command:<br />
</span></p>
<div style="font-family: courier new; font-size=7px">
<span>&gt;  mvn release:perform</span><br />
<span>&nbsp;</span>
</div>
<p>This will effectively do a <span style="font-family: courier new;">mvn deploy</span> with the release we have just  created. More precisely, it will use the <span style="font-family: courier new;">release.properties</span> file generated by the <span style="font-family: courier new;">release:prepare</span> goal to do the following:</p>
<ul>
<li>Check out the release  we just tagged</li>
<li>Build the application (compiling, testing  and packaging)</li>
<li>Deploy the release version to local and  remote repositories</li>
</ul>
<p><span style="font-family: verdana;"><br />
However, both of these steps can  be made into a single line command and placed, for example, on a Hudson  server.<br />
</span></p>
<p><span style="font-size: small;"><strong>Single line release  process</strong></span></p>
<p>This  single line command will tag source control, bump up the current  pom.xml, version and push a tagged artifact (jar or war) to a remote  repo.</p>
<div style="font-family: courier new; font-size=7px">
<span>&gt; mvn release:prepare  release:perform -B</span><br />
<span>&nbsp;</span>
</div>
<p>For example, if your current  project version was 1.1.2-SNAPSHOT</p>
<ol>
<li>The release  version will be 1.1.2</li>
<li>The next development version will  be 1.1.3-SNAPSHOT</li>
<li>The SCM tagged version will be  artifactId-1_1_2</li>
</ol>
<p><span style="font-family: verdana;"><br />
If you want to specify the  versions manually, then you use the commands described earlier. A single  line release command is good for productivity and great for automation.  You can make a build plan on your Continuous Integration server with  the above command to automatically tag the current version, bump the  SNAPSHOT version and deploy to a repository of your choice.<br />
</span></p>
<p><strong><span style="font-size: small;">Publish release to remote repository</span></strong></p>
<p>After versioning your project, Maven  can deploy, if configured, your project artifact (jar or war) to a  remote repository of your choice. You can do this by using<em> scp,  webdav, sftp </em>etc. I will descripe how to set up your <span style="font-family: courier new;">pom.xml</span> for scp and sftp.</p>
<p>Assume  you have a Maven repository and you have <span style="color: #000000;">SSH</span> access to the repository, then you can publish your artifacts using <strong>scp</strong>:</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;distributionManagement&gt;</span><br />
<span>&lt;!--  Publish the versioned releases here --&gt;</span><br />
<span>&lt;repository&gt;</span><br />
<span>&lt;id&gt;repo&lt;/id&gt;</span><br />
<span>&lt;name&gt;Callista  Enterprise Maven 2 repository&lt;/name&gt;</span><br />
<span>&lt;url&gt;scp://username@maven.callistaenterprise.se/home/maven2/html&lt;/url&gt;</span><br />
<span>&lt;/repository&gt;</span><br />
<span>&lt;/distributionManagement&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>When  using <strong>sftp</strong>, the XML configuration looks like this</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;distributionManagement&gt;</span><br />
<span> &lt;!-- Publish the versioned releases here  --&gt;</span><br />
<span> &lt;repository&gt;</span><br />
<span> &lt;id&gt;repo&lt;/id&gt;</span><br />
<span> &lt;name&gt;Callista Enterprise Maven 2 repository&lt;/name&gt;</span><br />
<span> &lt;url&gt;sftp://maven.callistaenterprise.se/repo&lt;/url&gt;</span><br />
<span> &lt;/repository&gt;</span><br />
<span>&lt;/distributionManagement&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>If  using either <strong>scp</strong> or <strong>sftp</strong> for publishing, and having SSH as  your underlying transfer mechanism, you could setup <em><span style="color: #000000;">SSH without password</span></em> on the repository  machine. If not, Maven will ask you to enter password each time doing  these operations.</p>
<p>Alternatively you can specify  the remote repository credentials in your M2_HOME/settings.xml file. On  Linux/Mac OS X operating systems you should find the file here:</p>
<p><span style="font-family: Courier New;">&gt; ~/.m2/settings.xml</span></p>
<p>Open the file and use these setting</p>
<div style="font-family: courier new; font-size=7px">
<span>&lt;settings&gt;</span><br />
<span>&lt;servers&gt;</span><br />
<span>&lt;server&gt;</span><br />
<span>&lt;!-- this is the id of the repo tag  specified in distributionManagement --&gt;</span><br />
<span>&lt;id&gt;repo&lt;/id&gt;</span><br />
<span>&lt;username&#038;gtyourusername&lt;/username&gt;</span><br />
<span>&lt;password&gt;yourpassword&lt;/password&gt;</span><br />
<span>&lt;/server&gt;</span><br />
<span>&lt;/servers&gt;</span><br />
<span>&lt;/settings&gt;</span><br />
<span>&nbsp;</span>
</div>
<p>As  an alternative of deploying your artifacts to a remote Maven repository  (i.e. those spedcified in &lt;distributionManagement&gt;), you could  use the following command:</p>
<div style="font-family: courier new; font-size=7px">
<span>&gt; mvn deploy  -DaltDeploymentRepository=local::default::file:///tmp/foo</span><br />
<span>&nbsp;</span>
</div>
<p>The  command will deploy your artifacts to the directory <span style="font-family: courier new;">/tmp/foo</span> on your local machine. The command binds by  default to the lifecycle phase: <span style="font-family: Courier New;">deploy</span>.</p>
<p><strong>Summary</strong></p>
<p>Releasing software is difficult. It is usually tedious and error prone, full of manual steps that need to be completed in a particular order. Worse, it happens at the end of a long period of development when all everyone on the team wants to do is get it out there, which often leads to omissions or short cuts. Finally, once a release has been made, it is usually difficult or impossible to correct mistakes other than to make another, new release. </p>
<p>To make the release management process smooth, consistent and free from errors, working with a good tool is vital. Maven provides a release plugin that provides the basic functions of a standard release process. If you have work with Maven before, try it out. In the end, it will save you a lot of valuable time.</p>
<p><strong>Reference</strong></p>
<ul>
<li><a title="Official Maven Release Plugin documentation" href="http://maven.apache.org/plugins/maven-release-plugin/introduction.html">Official Maven  Release Plugin documentation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2010/06/14/get-rid-of-your-tedious-and-error-prone-release-process-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CDI &#8211; The first standard for DI containers</title>
		<link>http://blog.callistaenterprise.se/2010/01/27/cdi-the-first-standard-for-di-containers/</link>
		<comments>http://blog.callistaenterprise.se/2010/01/27/cdi-the-first-standard-for-di-containers/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 20:49:34 +0000</pubDate>
		<dc:creator>Johan Eltes</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2010/01/02/CDI+-+The+first+standard+for+DI+containers</guid>
		<description><![CDATA[
What is it?
CDI is an abbreviation of &#8220;Contexts and Dependency Injection for the Java EE platform&#8221;. First of all, I&#8217;d like to stress that CDI is not only for Java EE environments. It is equally applicable to Java SE applications, unit tests and other out-of-container environments.
The specification (JSR-299) defines its declared capabilities as follows:
This specification [...]]]></description>
			<content:encoded><![CDATA[<div>
<h2><a name="CDI-ThefirststandardforDIcontainers-Whatisit%3F"></a>What is it?</h2>
<p>CDI is an abbreviation of &#8220;Contexts and Dependency Injection for the Java EE platform&#8221;. First of all, I&#8217;d like to stress that CDI is not only for Java EE environments. It is equally applicable to Java SE applications, unit tests and other out-of-container environments.</p>
<p>The specification (JSR-299) defines its declared capabilities as follows:</p>
<p><em>This specification defines a powerful set of complementary services that help improve the structure of application code.</em></p>
<ul>
<li><em>A well-defined lifecycle for state-ful objects bound to lifecycle contexts, where the set of contexts is extensible</em></li>
<li><em>A sophisticated, type safe dependency injection mechanism, including the ability to select dependencies at either development or deployment time, without verbose configuration</em></li>
<li><em>Support for Java EE modularity and the Java EE component architecture&#8212;the modular structure of a Java EE application is taken into account when resolving dependencies between Java EE components</em></li>
<li><em>Integration with the Unified Expression Language (EL), allowing any contextual object to be used directly within a JSF or JSP page</em></li>
<li><em>The ability to decorate injected objects</em></li>
<li><em>The ability to associate interceptors to objects via type safe interceptor bindings</em></li>
<li><em>An event notification model</em></li>
<li><em>A web conversation context in addition to the three standard web contexts defined by the Java Servlets specification</em></li>
<li><em>An SPI allowing portable extensions to integrate cleanly with the contain</em></li>
</ul>
<p>I will walk you through all the above with samples on the upcoming <a href="http://www.callistaenterprise.se/cadec/cadec2010.html">Cadec 2010</a>. In this blog entry, I&#8217;d like to give you a sense of the power of type-safe dependency injection in CDI.</p>
<h2><a name="CDI-ThefirststandardforDIcontainers-Typesafedependencyinjection"></a>Type-safe dependency injection</h2>
<p>If you are used to <a href="http://www.springframework.org">Spring</a> you know that there are basically two ways of resolving a dependency: by auto-wireing and by referencing a particular bean by name. CDI builds on the new JSR for Dependency Injection (JSR-330). Spring 3.0 implements JSR-330, so the following sample should apply to Spring 3 as well as any full CDI implementation. I&#8217;ve verified my samples using the reference implementation of CDI: The <a href="http://docs.jboss.org/weld/reference/1.0.0/en-US/html/">Weld container</a>.</p>
<p>Type-safe dependency injection is about qualifying the requested bean among several possible ones, using annotations. Let&#8217;s look at an example: injection of Spring JMS templates. Some applications use JMS extensively. There are many JMS service endpoints to interact with and there a also JMS endpoints for dealing with QoS, like destinations dedicated for logging and destinations dedicated for inbound business messages that could not be processed. The end result is the need for a potentially large number of pre-defined JMSTemplates &#8211; one for each destination.</p>
<p>Some destinations may need transitions, others don&#8217;t. Oneway services will require XA support. RequestResponse services, Log services and error services will not.</p>
<p>Pre-CDI one would typically use configure each JMSTemplate as a named bean  and then reference the name using an annotation (org.springframework.beans.factory.annotation.Qualifier)</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">@Autowired @Qualifier(<span class="code-quote">"error-dest-jmstemplate"</span>)
JmsTemplate myService1JmsTemplate;</pre>
</div>
</div>
<p>The template XML configuration would then reference an appropriate connection factory configuration (XA, NONE-XA etc).</p>
<p>With CDI, there is no standardized XML / externalized configuration language. The idea is to use annotations and Java code:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">private</span> @Inject @JmsPolicy(ERROR) JmsTemplate errorQeueTemplate;</pre>
</div>
</div>
<p>In this case, we assume that there is single JmsTemplate defined to be used to send failed inbound messages to an error destination.</p>
<p>@Inject simply means (JSR-330) that the field is subject for dependency injection. Autoinjection is default in CDI. There are several options for restricting the injection target among those that match the type of the field, one of being custom qualifiers. A custom qualifier is a custom annotation type that itself is annotated with the javax.inject.Qualifier annotation. Here&#8217;s the source code for the @JmsPolicy annotation that allows us to express which JmsTemplate that we expect to be injected, using  the semantics of a policy:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">@Qualifier
@Target( { METHOD, FIELD, PARAMETER, TYPE })
@Retention(RUNTIME)
<span class="code-keyword">public</span> @<span class="code-keyword">interface</span> JmsPolicy {
	JmsPolicyEnum value();
	<span class="code-keyword">enum</span> JmsPolicyEnum {
		ERROR,
		LOG
	}
}</pre>
</div>
</div>
<p>When defining the JmsTemplate bean, we will annotate it with the same &#8220;policy&#8221;, which is to say: &#8220;This JmsTemplate declaration conforms to the policy of an error destination&#8221; (timeout, Xa-support&#8230;).</p>
<h2><a name="CDI-ThefirststandardforDIcontainers-TheJmsTemplatefactory"></a>The JmsTemplate factory</h2>
<p>Since there is no external configuration language for bean instances in CDI, we will have to define the CDI correspondence of a Spring bean factory using Java annotations. In CDI, a bean factory is called a producer. A producer is implemented as a method annotated with @producer, which will return an instance of a JmsTemplate. For this simple sample, it was handy to define a single class that hosts all JmsTemplate producer methods along with declarations of the ConnectionFactories that needs to be injected into et producer method parameters:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class JmsTemplateProducers {

	@Produces @Resource @ResourceXaPolicy(NO_XA) ConnectionFactory noxa_cf;
	@Produces @Resource @ResourceXaPolicy(XA) ConnectionFactory xacf;

	@Produces @JmsPolicy(ERROR)
	<span class="code-keyword">public</span> JmsTemplate getErrorQueueTemplate(
			@JmsTemplateConfig(defaultDestinationName = <span class="code-quote">"errorQueue"</span>,
					timeout = 3600)
				JmsTemplate template,
			@ResourceXaPolicy(NO_XA) ConnectionFactory cf) {
		template.setConnectionFactory(cf);
		<span class="code-keyword">return</span> template;
	}

	@Produces @JmsPolicy(LOG)
	<span class="code-keyword">public</span> JmsTemplate getLogQueueTemplate(
			@JmsTemplateConfig(defaultDestinationName = <span class="code-quote">"logQueue"</span>,
					timeout = 100)
				JmsTemplate template,
			@ResourceXaPolicy(NO_XA) ConnectionFactory cf) {
		template.setConnectionFactory(cf);
		<span class="code-keyword">return</span> template;
	}

	@Produces @Named(<span class="code-quote">"service1"</span>)
	<span class="code-keyword">public</span> JmsTemplate getService1QueueTemplate(
			@JmsTemplateConfig(defaultDestinationName = <span class="code-quote">"service1"</span>,
					timeout = 100)
				JmsTemplate template,
			@ResourceXaPolicy(XA) ConnectionFactory cf) {
		template.setConnectionFactory(cf);
		<span class="code-keyword">return</span> template;
	}

	@Produces @Named(<span class="code-quote">"service2"</span>)
	<span class="code-keyword">public</span> JmsTemplate getService2QueueTemplate(
			@JmsTemplateConfig(defaultDestinationName = <span class="code-quote">"service2"</span>,
					timeout = 100)
				JmsTemplate template,
			@ResourceXaPolicy(XA) ConnectionFactory cf) {
		template.setConnectionFactory(cf);
		<span class="code-keyword">return</span> template;
	}</pre>
</div>
</div>
<p>We see another example of a producer: a field that is injected as a @resource and at the same time made available for injection into other beans (and thus being a producer).</p>
<p>The abstraction of policies have been used once more so that a semantic policy declaration in the form of a custom qualifier annotation could be used to specify the capabilities of the connection factory for each of the templates.</p>
<p>This translates into:</p>
<p>The service bean that processes an inbound JMS message says:<br/><br />
&#8220;I need a JmsTemplate that qualifies for sending error message&#8221;</p>
<p>The producer method for JmsTemplates that claims to support the error handling policy says: &#8220;I need a connection factory that is compatible with my policy for transaction handling, which is XA-enlisting&#8221;.</p>
<p>The code also shows an example of a JmsTemplate producer that support a log policy. The log policy defines a substantially shorter timeout for invocation of the log service than does the error template producer.</p>
<p>Finally, there are samples of JmsTemplate producers for business service endpoints (service1, service2). They are defined using a pre-defined (JSR-330) qualifier annotation type, that is convenient to use when there is no added value of abstracting the matching of an injection point with a bean.</p>
<h2><a name="CDI-ThefirststandardforDIcontainers-MetaprogramminginCDI"></a>Meta-programming in CDI</h2>
<p>The @JmsTemplateConfig annotation used in the producer samples, is a custom annotation used in conjunction with the mata-programming capabilities of the CDI SPI, extend the annotation-based configuration language for our purpose (a real case would include all properties of the Spring JmsTemplate):</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">@Qualifier
@Target( { METHOD, FIELD, PARAMETER, TYPE })
@Retention(RUNTIME)
<span class="code-keyword">public</span> @<span class="code-keyword">interface</span> JmsTemplateConfig {
	@Nonbinding
	<span class="code-object">String</span> defaultDestinationName() <span class="code-keyword">default</span> "";

	@Nonbinding
	<span class="code-object">int</span> timeout() <span class="code-keyword">default</span> 0;
}</pre>
</div>
</div>
<p>The annotation is processed by a class that utilizes parts of the CDI SPI for meta programming:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class JmsTemplateConfigurationProducer {

	@Produces
	@JmsTemplateConfig
	<span class="code-keyword">public</span> JmsTemplate produceJmsTemplate(InjectionPoint injectionPoint) {
		JmsTemplateConfig t = injectionPoint.getAnnotated().getAnnotation(
				JmsTemplateConfig.class);
		JmsTemplate tmp = <span class="code-keyword">new</span> JmsTemplate();
		tmp.setDefaultDestinationName(t.defaultDestinationName());
		tmp.setReceiveTimeout(t.timeout());
		<span class="code-keyword">return</span> tmp;
	}
}</pre>
</div>
</div>
<h2><a name="CDI-ThefirststandardforDIcontainers-Summary"></a>Summary</h2>
<p>The idea of having a 100% java-based dependency injection model, based on annotations require some innovation to take place. CDI is a good example of what it takes. CDI also raises the bar in terms of type-safe dependency injection. There are several interesting innovations to explore in CDI. </p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2010/01/27/cdi-the-first-standard-for-di-containers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another perspective on JAX-WS portability</title>
		<link>http://blog.callistaenterprise.se/2010/01/07/another-perspective-on-jax-ws-portability/</link>
		<comments>http://blog.callistaenterprise.se/2010/01/07/another-perspective-on-jax-ws-portability/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 11:27:33 +0000</pubDate>
		<dc:creator>Johan Eltes</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/03/29/Another+perspective+on+JAX-WS+portability</guid>
		<description><![CDATA[
JAX-WS is the Java-standard for Web-Service XML to Java POJO binding. It entered the scene in Java EE 5 and Java SE 6. I wrote a blog entry a while back on it&#8217;s advantages over the predecessor (JAX-RPC). With WSDL-first (contract-first) design, Java POJO:s are generated from WSDL and XSD source files. The resulting Java [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>JAX-WS is the Java-standard for Web-Service XML to Java POJO binding. It entered the scene in Java EE 5 and Java SE 6. I wrote a <a href="/2006/05/31/harmoni-mellan-jaxb-och-jaxrpc-i-javaee-5/">blog entry</a> a while back on it&#8217;s advantages over the predecessor (JAX-RPC). With WSDL-first (contract-first) design, Java POJO:s are generated from WSDL and XSD source files. The resulting Java classes and interfaces are annotated with annotations standardized by <a href="http://jcp.org/en/jsr/detail?id=181">JSR-181</a>. Thanks to the standard, JAX-WS-compliant service consumers and producers can be deployed into any Java EE 5 or Java SE 6 execution environment. </p>
<h2><a name="AnotherperspectiveonJAX-WSportability-JAXWStoolingcapabilities"></a>JAX-WS tooling capabilities</h2>
<p>While JAX-WS and the associated JAX-B specifications standardize how WSDL and XSD-defined services are modeled by Java classes with annotations, they do not standardize the tooling for generating Java-classes. Thus, different JAX-WS implementations have different features in terms of how and to what detail the generation process can be controlled. As an example, the <a href="http://cxf.apache.org/">CXF</a> wsdl-to-java generator allows more fine-grained control of how namespaces are mapped to Java packages than does the <a href="https://jax-ws.dev.java.net/">reference implementation </a> (part of Suns Metro). </p>
<h2><a name="AnotherperspectiveonJAX-WSportability-CXFtoMetro"></a>CXF to Metro</h2>
<p>Recently, I set up a Maven project with CXF, to build a jar of JAXWS/JAXB POJOs from a WSDL with accompanying XML Schemas. The WSDL and the schemas was from different domains (business and technical domains, which I needed to keep apart in different packages. Moreover, the schemas applied different styles of namespaces (urn versus urls). The CXF tooling allowed be to take control of the package naming for each of the involved name spaces.  The generated jar of binding POJOs was referenced/re-used (dependency) by several Java-based web service projects that consumed or produced the WSDL &#8211; all using the CXF JAX-WS runtime. When I was developing a Grails application, I had problems integrating CXF due to library clashes (different spring versions and xml parsers in Grails and CXF), so I decided to go for Metro in my Grails application. </p>
<h2><a name="AnotherperspectiveonJAX-WSportability-Discoveringtheobvious"></a>Discovering the obvious</h2>
<p>Without giving it much thought, I started to configure Metros wsimport Maven plug-in (which serves the same purpose as wsdl-2-java of CXF) for my Grails application. Intuitively, I thought I would have to use Metro tooling to generate binding classes for the Metro run-time. I turned on my brain at the point when I realized the shortcomings of wsimport, with regards to mapping name-spaces to Java packages. Why should I have to use Metro tooling? Portability of JAX-WS (thanks to JSR-181) does not only allow me to deploy to different JAX-WS run-time libraries / Java EE-containers &#8211; it also gives me the option of choing one vendors wsdl-to-java tooling over anothers! Yes, yes &#8211; obvious, but it didn&#8217;t strike me as a value until recently, I must admit. So from now on, CXF is my preferred WSDL-to-java tooling, regardless of JAX-WS implementation to be used at run-ime.</p>
<p>This is how CXF allows me to control name-space-to-package mappings (maven sample):</p>
<div class="panel" style="border-width: 1px;">
<div class="panelHeader" style="border-bottom-width: 1px;"><b>CXF</b></div>
<div class="panelContent">
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;plugins&gt;</span>
			<span class="code-tag">&lt;plugin&gt;</span>
				<span class="code-tag">&lt;groupId&gt;</span>org.apache.cxf<span class="code-tag">&lt;/groupId&gt;</span>
				<span class="code-tag">&lt;artifactId&gt;</span>cxf-codegen-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
				<span class="code-tag">&lt;version&gt;</span>${cxf.version}<span class="code-tag">&lt;/version&gt;</span>
				<span class="code-tag">&lt;executions&gt;</span>
					<span class="code-tag">&lt;execution&gt;</span>
						<span class="code-tag">&lt;id&gt;</span>generate-sources<span class="code-tag">&lt;/id&gt;</span>
						<span class="code-tag">&lt;phase&gt;</span>generate-sources<span class="code-tag">&lt;/phase&gt;</span>
						<span class="code-tag">&lt;configuration&gt;</span>
							<span class="code-tag">&lt;sourceRoot&gt;</span>
								${basedir}/target/generated/src/main/java
							<span class="code-tag">&lt;/sourceRoot&gt;</span>
							<span class="code-tag">&lt;wsdlOptions&gt;</span>
								<span class="code-tag">&lt;wsdlOption&gt;</span>
									<span class="code-tag">&lt;extraargs&gt;</span>

										<span class="code-tag">&lt;extraarg&gt;</span>-p<span class="code-tag">&lt;/extraarg&gt;</span>
										<span class="code-tag">&lt;extraarg&gt;</span>
											urn:se:namespace1:v1=se.callista.namespace1.v1
										<span class="code-tag">&lt;/extraarg&gt;</span>

										<span class="code-tag">&lt;extraarg&gt;</span>-p<span class="code-tag">&lt;/extraarg&gt;</span>
										<span class="code-tag">&lt;extraarg&gt;</span>

http://namespace2.se/v1=se.callista.namespace2.v1

										<span class="code-tag">&lt;/extraarg&gt;</span>
									<span class="code-tag">&lt;/extraargs&gt;</span>
									<span class="code-tag">&lt;wsdl&gt;</span>
										${schema.path}mywsdl.wsdl
									<span class="code-tag">&lt;/wsdl&gt;</span>
								<span class="code-tag">&lt;/wsdlOption&gt;</span>
						<span class="code-tag">&lt;/wsdlOptions&gt;</span>
						<span class="code-tag">&lt;/configuration&gt;</span>
						<span class="code-tag">&lt;goals&gt;</span>
							<span class="code-tag">&lt;goal&gt;</span>wsdl2java<span class="code-tag">&lt;/goal&gt;</span>
						<span class="code-tag">&lt;/goals&gt;</span>
					<span class="code-tag">&lt;/execution&gt;</span>
				<span class="code-tag">&lt;/executions&gt;</span>
			<span class="code-tag">&lt;/plugin&gt;</span>
		<span class="code-tag">&lt;/plugins&gt;</span></pre>
</div>
</div>
</div>
</div>
<p>In Metro, I can only control the package mapping for the target namespace of the WSDL, not for the schema name-spaces. The others will be mapped to package names by default rules (which is usually in conflict with the package naming standards with a company):</p>
<div class="panel" style="border-width: 1px;">
<div class="panelHeader" style="border-bottom-width: 1px;"><b>Metro</b></div>
<div class="panelContent">
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;plugins&gt;</span>
			<span class="code-tag">&lt;plugin&gt;</span>
				<span class="code-tag">&lt;groupId&gt;</span>org.codehaus.mojo<span class="code-tag">&lt;/groupId&gt;</span>
				<span class="code-tag">&lt;artifactId&gt;</span>jaxws-maven-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
				<span class="code-tag">&lt;executions&gt;</span>
					<span class="code-tag">&lt;execution&gt;</span>
						<span class="code-tag">&lt;goals&gt;</span>
							<span class="code-tag">&lt;goal&gt;</span>wsimport<span class="code-tag">&lt;/goal&gt;</span>
						<span class="code-tag">&lt;/goals&gt;</span>
					<span class="code-tag">&lt;/execution&gt;</span>
				<span class="code-tag">&lt;/executions&gt;</span>
				<span class="code-tag">&lt;configuration&gt;</span>
					<span class="code-tag">&lt;packageName&gt;</span>se.callista.namespace1.v1<span class="code-tag">&lt;/packageName&gt;</span>
					<span class="code-tag">&lt;wsdlDirectory&gt;</span>${schema.path}<span class="code-tag">&lt;/wsdlDirectory&gt;</span>

					<span class="code-tag">&lt;wsdlFiles&gt;</span>
						<span class="code-tag">&lt;wsdlFile&gt;</span>
							mywsdl.wsdl
						<span class="code-tag">&lt;/wsdlFile&gt;</span>
					<span class="code-tag">&lt;/wsdlFiles&gt;</span>

				<span class="code-tag">&lt;/configuration&gt;</span>

				<span class="code-tag">&lt;dependencies&gt;</span>
					<span class="code-tag">&lt;dependency&gt;</span>
						<span class="code-tag">&lt;groupId&gt;</span>com.sun.xml.ws<span class="code-tag">&lt;/groupId&gt;</span>
						<span class="code-tag">&lt;artifactId&gt;</span>jaxws-tools<span class="code-tag">&lt;/artifactId&gt;</span>
						<span class="code-tag">&lt;version&gt;</span>2.1.2<span class="code-tag">&lt;/version&gt;</span>
					<span class="code-tag">&lt;/dependency&gt;</span>
				<span class="code-tag">&lt;/dependencies&gt;</span>
			<span class="code-tag">&lt;/plugin&gt;</span>

		<span class="code-tag">&lt;/plugins&gt;</span></pre>
</div>
</div>
</div>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2010/01/07/another-perspective-on-jax-ws-portability/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Increased productivity with JavaRebel</title>
		<link>http://blog.callistaenterprise.se/2009/10/21/increased-productivity-with-javarebel/</link>
		<comments>http://blog.callistaenterprise.se/2009/10/21/increased-productivity-with-javarebel/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 15:11:41 +0000</pubDate>
		<dc:creator>Pär Wenåker</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/09/14/Increased+productivity+with+JavaRebel</guid>
		<description><![CDATA[
In my current project we are using the JBoss Application Server. Since the project in based on EJB3 and is rather extensive we have been experiencing problems with long &#8220;deployment to test&#8221;-cycles during development. We write lots of unit tests and use a test driven approach, but we also need to do lots of integration [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>In my current project we are using the <a href="http://www.jboss.org/">JBoss Application Server</a>. Since the project in based on EJB3 and is rather extensive we have been experiencing problems with long &#8220;deployment to test&#8221;-cycles during development. We write lots of unit tests and use a test driven approach, but we also need to do lots of integration testing in the target environment since the application is heavily AJAX based. Sitting and waiting for application deployment and application server restarts is really not only wasting valuable time, but also interruptive for the creative flow that you build up during software development. But worst of all, it takes the joy out of programming.</p>
<p>What we have done to minimize this problem is to introduce <a href="http://www.zeroturnaround.com/javarebel">JavaRebel</a> (<a href="http://www.zeroturnaround.com/blog/renaming-javarebel">being renamed to JRebel</a>) together with the <a href="http://andrei.gmxhome.de/filesync/index.html">FileSync Eclipse plugin</a> and exploded deployment of war archives into the development cycle. JavaRebel is a commercial tool, but I think it is very reasonable priced for what you get. What it does is that it enables reloading of Java classes on the fly. You just edit and recompile your classes in <a href="http://www.eclipse.org">Eclipse</a> and the changes are picked up by the target JVM (running the app-server) without a restart or application redeploy.</p>
<p>JavaRebel is enabled using a <a href="http://www.zeroturnaround.com/javarebel/configuration/maven">Maven plugin</a> that places a rebel.xml file into all jar and war files in our application. The rebel.xml file specifies where JavaRebel should go and look for the actual class files. In our case it is in the target directories that Eclipse uses as it&#8217;s output folders. The second thing that is required is to enable a JavaRebel agent when starting the application server JVM. When the JVM is started the JavaRebel agent will start monitoring changes to classes and reload them when they are needed. It will even through plugins reload and reconfigure Spring application contexts when the xml configuration files are edited.</p>
<p>We use <a href="http://maven.apache.org">Maven</a> as our build system, so the development cycle used to look something like this:</p>
<ol>
<li>Build with maven</li>
<li>Deploy to application server</li>
<li>(wait&#8230;)</li>
<li>Test</li>
<li>Edit &#8211; and back to 1&#8230;</li>
</ol>
<p>Now it looks like this:</p>
<ol>
<li>Build ONCE with Maven</li>
<li>Deploy ONCE to application server</li>
<li>Edit/Compile/Test</li>
</ol>
<p>The <a href="http://andrei.gmxhome.de/filesync/index.html">FileSync plugin</a> is used to keep files in the exploded war archives in synch with the files in the Eclipse source folders. This enables editing in Eclipse and testing in the browser of JSP and Javascript files just by refreshing.</p>
<p>Keep in mind that JavaRebel does not handle all kind of file changes. If you change something that has to do with application configuration, e.g. annotations it is not picked up, but that would require a hook into the application server. You do not have to rebuild from Maven though. The only thing needed is a restart of the application server.</p>
<p>I definitely think that JavaRebel is a valuable, easy to setup tool that bring joy back to programming&#33;</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/10/21/increased-productivity-with-javarebel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Metamorphosis &#8211; The screwdriver turns into a nuclear plant</title>
		<link>http://blog.callistaenterprise.se/2009/09/10/metamorphosis-the-screwdriver-turns-into-a-nuclear-plant/</link>
		<comments>http://blog.callistaenterprise.se/2009/09/10/metamorphosis-the-screwdriver-turns-into-a-nuclear-plant/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 12:21:20 +0000</pubDate>
		<dc:creator>Björn Beskow</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/09/10/Metamorphosis+-+The+screwdriver+turns+into+a+nuclear+plant</guid>
		<description><![CDATA[
Continuous Integration servers have been around for quite a number of years. Mostly out of slentrian, I have stuck to CruiseControl since the alternatives (AntHill, Continuum, Hudsun, &#8230;) just haven&#8217;t been that much better to motivate me to switch.
I just attended Kuhsuke Kawaguchi&#8217;s Hudson presentation at JavaZone, and got quite a surprise. When I looked [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Continuous Integration servers have been around for quite a number of years. Mostly out of slentrian, I have stuck to CruiseControl since the alternatives (AntHill, Continuum, Hudsun, &#8230;) just haven&#8217;t been that much better to motivate me to switch.</p>
<p>I just attended Kuhsuke Kawaguchi&#8217;s <a href="https://hudson.dev.java.net/">Hudson</a> presentation at <a href="http://jz09.java.no/">JavaZone</a>, and got quite a surprise. When I looked at Hudson last time (yes, it was a time ago), it was just another CI server with a nice web GUI. The presentation today showed a completely different creature. Build distribution and scalability has obviously been the focus in the Hudson team, and the latest Hudson version comes with an extremely ambitious Clustering mechanism:</p>
<ul>
<li>Several nodes collaborate in a Master-Slave setup, with support for at least up to 100 slaves.</li>
<li>Master and slaves may run on heterogeneous hardware, with support for Solaris, most Linux dialects as well as windows.</li>
<li>Slaves can be automatically configured from the Master: when a new Slave node is added, it can have a specified version of the JVM, Ant and Maven libraries downloaded and installed automatically. Using the Hudson PXE protocol, a new slave node can even boot over the network, have the operating system installed from the Master before continuing the bootstrap!</li>
<li>Slave node system resources (disk space, wap space, memory etc) can be automatically monitored by the Master, and slave nodes are automatically put offline if they degenerate</li>
<li>The cluster utilization itself is constantly monitored: How many nodes are busy? How long is the job queue? Using the Hudson <a href="http://aws.amazon.com/ec2/">EC2</a> plugin, new Slave nodes can even be allocated dynamically in the Cloud, on demand!</li>
<li>You can even run other clustered applications like <a href="http://hadoop.apache.org/">Hadoop</a> or <a href="http://selenium-grid.seleniumhq.org/">Selenium Grid</a> on a Hudson cluster!</li>
</ul>
<p>Wow! Not what I was looking for, but really cool stuff.</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/09/10/metamorphosis-the-screwdriver-turns-into-a-nuclear-plant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails Unit Testing in Eclipse</title>
		<link>http://blog.callistaenterprise.se/2009/09/04/grails-unit-testing-in-eclipse/</link>
		<comments>http://blog.callistaenterprise.se/2009/09/04/grails-unit-testing-in-eclipse/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 15:37:44 +0000</pubDate>
		<dc:creator>Björn Beskow</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/09/04/Grails+Unit+Testing+in+Eclipse</guid>
		<description><![CDATA[
Groovy and Grails support have long been a sad story in Eclipse. Most notable, running and debugging Grails Unit tests in Eclipse has been quite painful, partly due to the fact that the Groovy eclipse plugin didn&#8217;t recognize the tests as being Unit tests (and hence the &#8220;Run as &#124; Unit Test&#8221; has not been [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Groovy and Grails support have long been a sad story in Eclipse. Most notable, running and debugging Grails Unit tests in Eclipse has been quite painful, partly due to the fact that the Groovy eclipse plugin didn&#8217;t recognize the tests as being Unit tests (and hence the &#8220;Run as | Unit Test&#8221; has not been available), and partly because of classpath clashes between Grails and the Eclipse Groovy plugin (manifested by the dreaded &#8216;Disable Groovy Compiler Generating Class Files&#8217; option, which needs to be both set and not set).</p>
<p>With the <a href="http://groovy.codehaus.org/Eclipse+Plugin">alpha release of V2 of the Groovy plugin</a>, things are getting better. Most of the classpath related problems are resolved, and Groovy Unit test classes are now correctly recognized. This means Grails unit tests can now be executed directly in the IDE, without the need to run a grails command.</p>
<p>Some flaws with Grails Unit tests still exist, however: The Eclipse Groovy plugin is not aware of many of the Grails conventions (e.g. that all Groovy classes within the grails-app/domain folder are Domain Entities). This means that the &#8220;magic&#8221; in terms of meta-programming that Grails performs on e.g. Entities is not done when executed directly in Eclipse, which cause most of the superb Grails mocking support to fail. Consider for instance the simple Employee entity below:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">class Employee {

    <span class="code-object">String</span> name

    <span class="code-keyword">static</span> constraints = {
    	name(blank:<span class="code-keyword">false</span>)
    }
}</pre>
</div>
</div>
<p>In a Unit test for the Employee, the constraint on &#8220;name&#8221; can be tested by mocking the Entity class:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">class EmployeeTests <span class="code-keyword">extends</span> GrailsUnitTestCase {
    void testNameNotBlank() {
    	mockDomain(Employee)
    	def e = <span class="code-keyword">new</span> Employee(name: "")
    	assertFalse <span class="code-quote">"validation should have fail"</span>, e.validate()
    	assertEquals <span class="code-quote">"blank"</span>, e.errors.name
    }
}</pre>
</div>
</div>
<p>This test runs as expected via the Grails command, but if executed directly within Eclipse, the Employee class is just an ordinary Groovy class that hasn&#8217;t been meta-programmed by Grails, and the test fails with the following exception:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">org.codehaus.groovy.grails.exceptions.GrailsDomainException:
Identity property not found, but required in domain class [Employee]</pre>
</div>
</div>
<p>There are ways around these problems. Starting with Groovy 1.6, <a href="http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations"><b>AST Transformations</b></a> allow meta-programming in compile time. A local AST transformation is triggered by an Annotation on the class to be transformed, and the compiler automatically applies the transformation. Most Grails meta-programming enhancements are also available as AST annotations.</p>
<p>Hence if we mark the Employee entity with the @Entity annotation (redundandly, since it lives in the grails-app/domain folder), the compiler will automatically transform it into a Grails entity and hence the mockDomain(Employee) mechanism will work again.</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">@grails.persistence.Entity
class Employee {

    ...

}</pre>
</div>
</div>
<p>One little caveat, though: The Eclipse Groovy plugin must be configured to use the correct classpath when doing AST transformations. Otherwise, it refuses to compile the annotated class, giving the following error:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">Groovy:Could not find class <span class="code-keyword">for</span> Transformation Processor org.codehaus.groovy.grails.compiler.injection.EntityASTTransformation declared by
 grails.persistence.Entity</pre>
</div>
</div>
<p>By adding a file <b>groovy.properties</b> with the contents as seen below to the root folder of the eclipse project, the Groovy compiler is configured to use the same classpath as the project (it sure sounds like that should be the default behaviour to me):</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">org.eclipse.jdt.core.compiler.groovy.groovyClassLoaderPath=%projclasspath%</pre>
</div>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/09/04/grails-unit-testing-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Categories to keep Java domain models uncluttered</title>
		<link>http://blog.callistaenterprise.se/2009/07/28/using-categories-to-keep-java-domain-models-uncluttered/</link>
		<comments>http://blog.callistaenterprise.se/2009/07/28/using-categories-to-keep-java-domain-models-uncluttered/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 13:44:07 +0000</pubDate>
		<dc:creator>Johan Eltes</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/07/23/Using+Categories+to+keep+Java+domain+models+uncluttered</guid>
		<description><![CDATA[
Going back to the roots of OOD has been commonly advocated since Eric Evans  presented his book &#8220;Domain-Driven Design: Tackling Complexity in the Heart of Software&#8221; back in 2003. There are several other sources of the movement, such as the Naked Objects Framework which we presented at Cadec 2007. 
In database systems, DDD often [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Going back to the roots of OOD has been commonly advocated since Eric Evans  presented his book <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1238687848&amp;sr=8-1">&#8220;Domain-Driven Design: Tackling Complexity in the Heart of Software&#8221;</a> back in 2003. There are several other sources of the movement, such as the <a href="http://en.wikipedia.org/wiki/Naked_objects">Naked Objects Framework</a> which we presented at <a href="http://www.callistaenterprise.se/download/18.5a1758e1117d436eebd80001364">Cadec 2007</a>. </p>
<p>In database systems, DDD often takes its representation in a class model of the persistent information to be managed by a service or a system. If Java is used to implement the entity classes describing persistent objects, JPA may be the persistence technology (presented at several Cadecs: <a href="http://www.callistaenterprise.se/download/18.5a1758e1117d436eebd80001363/JPA1.0.pdf">JPA 1.0</a>, <a href="http://www.callistaenterprise.se/download/18.6521041711855b35da480001036/JPA.pdf">2 years with JPA</a>) used to add data base persistence behavior to the Entity POJOs.</p>
<p>Within DDD, the idea is to allocate all logic (as much as feasible) to the entity POJOs. This often includes logic of the following categories: accessing state (setters, getters, navigation and change of object graph), validating the state, calculation of derived attributes (calculating order sum of an order) and event processing (action-logic triggered by changes to the state of an entity, such as producing a shipment note when the order state is changed to &#8220;ready-for-shipment&#8221;).</p>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-ProblemwithclutteredPOJOs"></a>Problem with cluttered POJOs</h2>
<p>A challenge with DDD is to know what should go into the object model and what shouldn&#8217;t. There are many types of behavior that are specific to process or external context that &#8211; when pushed into the entity classes &#8211; makes them cluttered and potentially fragile. They become fragile, when the the forces that generate change are related to external parties rather than the core business for which the model was initially creates. Change management and dependency management becomes complex.</p>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-Groovycategoriestotherescue"></a>Groovy categories to the rescue</h2>
<p>The Java language provides little support for dealing with this problem. <a href="http://www.qi4j.org/">qi4j</a> is an interesting approach to deal with many aspects of POJO cluttering, but not the dependency problem. With qi4j, model objects can only be extended by making changes to the definition of Java interface of a model class. This creates dependencies between change management processes and clutters the dependencies of the entities. I think qi4j carries a lot of promise, but its evolution is bound to the limitations of the Java language, which is sometimes a problem.</p>
<p>In Mid 90&#8217;s, I worked with Objective-C on the <a href="http://en.wikipedia.org/wiki/Nextstep">NextSTEP platform</a>. It has a construct called Category that allows a &#8220;package of behavior&#8221; (methods) to be added to an existing class in runtime. It was often used to add methods to the foundation classes (like NSString). </p>
<p>I&#8217;ve missed this ability in Java since I first learned it. It is how ever available in <a href="http://groovy.codehaus.org/">Groovy</a> &#8211; the dynamic language built on the JDK (<a href="http://www.callistaenterprise.se/download/18.5a1758e1117d436eebd80001355/Groovy.pdf">a Cadec presentation is available</a>). The remaining part of this blog entry illustrates how Groovy categories can be used to extend the use of DDD without cluttering your domain model.</p>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-Ourexample%3AaddingbehaviortoJAXBgeneratedPOJO%3As"></a>Our example: adding behavior to JAXB-generated POJO:s</h2>
<p>I see Groovy typically being used in the following contexts:</p>
<ul class="alternate" type="square">
<li>As the core development language of web application development based on the <a href="http://www.grails.org/">Grails framework</a> (Callista-presentation <a href="http://www.callistaenterprise.se/download/18.4e1bc06811fea7fe4fb80006778/EnterpriseGrails.pdf">here</a>)</li>
<li>As integration language complementing Java projects due to it&#8217;s phenomenal XML processing capabilities (dynamic DSLs through Groovy MarkupBuilder)</li>
<li>As scripting language</li>
</ul>
<p>My example for this blog is of the second category. This is the problem:</p>
<div class="panel" style="border-width: 1px;">
<div class="panelContent">
<p>Create an RSS feed on top of the AccuWeather RESTFul web service (WeatherData).</p>
</div>
</div>
<p>Prerequisites: </p>
<ul class="alternate" type="square">
<li>Use JAXB-generated POJOs available in an existing jar file to parse weather data from the AccuWeather service.</li>
</ul>
<p>The task:</p>
<ul class="alternate" type="square">
<li>Use Groovy to create a web app that transforms the response from the AccuWeather service to an RSS 2.0 feed.</li>
</ul>
<ul class="alternate" type="square">
<li>The result should look like this (in Safari RSS reader)<br/><br />
<img src="/wp-content/uploads/01_ScreenShotAccuStream.png" align="absmiddle" border="0" /></li>
</ul>
<p>Design constraints:</p>
<ul class="alternate" type="square">
<li>DDD should be applied such that entity logic related to producing RSS output should be added to the domain objects (JAXB-generated model classes)</li>
<li>All RSS-related logic should be in the same project as the logic that uses/depends on that logic. The logic should be added to the JAXB POJO:s in runtime, when needed by the Groovy RSS servlet.</li>
</ul>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-Thesolution"></a>The solution</h2>
<p>We need to create a Groovy servlet that requests XML weather data from the AccuWeather weather service, parses the response into JAXB-objects produced from the XML Schema of the service and finally writes RSS XML to the servlet response by accessing the JAXB POJOs. Here&#8217;s the Servlet:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">package</span> se.callistaenterprise.labs.groovydslblog.accuatomfeed

<span class="code-keyword">import</span> javax.servlet.http.HttpServlet;
<span class="code-keyword">import</span> javax.servlet.http.HttpServletRequest;
<span class="code-keyword">import</span> javax.servlet.http.HttpServletResponse;
<span class="code-keyword">import</span> javax.servlet.ServletException;
<span class="code-keyword">import</span> javax.xml.bind.Unmarshaller;
<span class="code-keyword">import</span> javax.xml.bind.JAXBContext;
<span class="code-keyword">import</span> com.accuweather.weatherdata.AdcDatabaseType;
<span class="code-keyword">import</span> com.accuweather.weatherdata.DayType;
<span class="code-keyword">import</span> java.text.SimpleDateFormat

/**
 * Servlet that queries the AccuWeather wetherdata service and re-publishes it as a RSS feed.
 * The query string is passed on to the accuweather service as is, i.e. it is expected to be a wetherdata query string.
 * A typical query string looks like <span class="code-keyword">this</span>: ?location=EUR|SE|SW005|KUNGSBACKA&amp;metric=1
 * So that the request to <span class="code-keyword">this</span> servlet (as by mapping in web.xml) becomes:
 *
 *  http:<span class="code-comment">//localhost:8080/accuatomfeed/AccuFeed.xml?location=EUR|SE|SW005|KUNGSBACKA&amp;metric=1
</span> *
 * @author Johan Eltes
 *
 */
<span class="code-keyword">public</span> class AccuAtomServlet <span class="code-keyword">extends</span> HttpServlet
{
	<span class="code-keyword">protected</span> void doGet(HttpServletRequest req,
            HttpServletResponse resp)
     <span class="code-keyword">throws</span> ServletException,
            java.io.IOException {

		def queryString = req.queryString <span class="code-comment">// We pass <span class="code-keyword">this</span> on to the Accu RESTFul service
</span>
		<span class="code-comment">// Get Weather Data from Accu Weather Data Service into JAXB pojos.
</span>		Unmarshaller um = JAXBContext.newInstance(<span class="code-quote">"com.accuweather.weatherdata"</span>).createUnmarshaller()
		URL url = <span class="code-keyword">new</span> URL(<span class="code-quote">"http:<span class="code-comment">//rdona.accu-weather.com/widget/rdona/weather-data.asp?${queryString}"</span>)
</span>		AdcDatabaseType accuResponse = um.unmarshal(url).value

		<span class="code-comment">// Produce RSS feed
</span>		resp.contentType = <span class="code-quote">"application/rss+xml"</span>
		resp.writer &lt;&lt; '&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span> ?&gt;'
		def rssBuilder = <span class="code-keyword">new</span> groovy.xml.MarkupBuilder(resp.writer)
		use (DayTypeRssSupportCategory, HttpServletRequestRssSupportCategory) {
			rssBuilder.rss (version: '2.0') {
				channel {
					title (<span class="code-quote">"Weather stream <span class="code-keyword">for</span> ${queryString?.replace('%7C','|')}"</span>)
					description(<span class="code-quote">"An RSS feed built with Groovy to transform the accu-wether RESTFul service into an RSS feed."</span>)
					language ('en-us')
					link (req.rssChannelLink) <span class="code-comment">// property rssChannelLink is added to HttpServletRequest by HttpServletRequestRssSupportCategory
</span>					ttl(60)
					pubDate(<span class="code-keyword">new</span> SimpleDateFormat(<span class="code-quote">"EEE, d MMM yyyy HH:mm:ss Z"</span>, Locale.US).format(<span class="code-keyword">new</span> Date()))
					accuResponse.forecast.day.each {DayType day -&gt;
						item () {
							title (day.daycode)
							link (day.url.replace('|','%7C'))
							description (day.itemDescription) <span class="code-comment">// Method itemDescription is added to class DayType by DayTypeRssSupportCategory
</span>							pubDate (day.pubDate) <span class="code-comment">// Method itemDescription is added to class DayType by DayTypeRssSupportCategory
</span>						}
					}
				}
			}
		}
	}
}</pre>
</div>
</div>
<p>The interesting part is the &#8220;use&#8221;-keyword that in runtime applies a category that adds the method &#8220;getItemDescription&#8221; that is later invoked as if it was part of the domain class DayType (Groovy allows for property-based access to Java-beans properties as a convenience to calling get&#8230;()) .</p>
<p>What is then exactly a Groovy Category? It is actually just a plan Groovy class that follows a set of conventions, that allows it to be applied as a Category using the use-keyword. Here&#8217;s the category class that defines the getItemDescription() method for the DatType class:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">package</span> se.callistaenterprise.labs.groovydslblog.accuatomfeed

<span class="code-keyword">import</span> com.accuweather.weatherdata.DayType
<span class="code-keyword">import</span> groovy.xml.MarkupBuilder

/**
 * Adds RSS behavior to DateType
 * @author Johan Eltes
 *
 */
 <span class="code-keyword">public</span> class DayTypeRssSupportCategory {

	/**
	 * Derives a RSS item description from the content of a DayType
	 * This is the old-school categories. The AST-transfomration <span class="code-keyword">for</span> @Category
	 * gives much neater grammar (like Objective-C categories), but it is abit
	 * too buggy at the moment.
	 *
	 * The description is produced as html, so we need to create a local
	 * MarkupBuilder rather than passing in the parent MarkupBuilder. Otherwise
	 * the html <span class="code-keyword">for</span> the description field would not be escaped.
	 */
	<span class="code-keyword">static</span> <span class="code-object">String</span> getItemDescription(DayType that) {
		StringWriter writer = <span class="code-keyword">new</span> StringWriter()
		MarkupBuilder htmlBuilder = <span class="code-keyword">new</span> MarkupBuilder(writer)
		writer &lt;&lt; that.daytime.txtlong
		htmlBuilder.table {
			tr {
				td {
					img (src: <span class="code-quote">"http:<span class="code-comment">//vortex.accuweather.com/adc2004/common/images/icons/standard/wx/45x45/${that.daytime.weathericon.padLeft(2, '0')}.gif"</span>)
</span>				}
				td {
					ul {
						li (<span class="code-quote">"Realfeel High: ${that.daytime.realfeelhigh}"</span>)
						li (<span class="code-quote">"Realfeel Low: ${that.daytime.realfeellow}"</span>)
						li (<span class="code-quote">"Wind direction: ${that.daytime.winddirection}"</span>)
						li (<span class="code-quote">"Wind speed: ${that.windspeed} m/s"</span>)
					}
				}
			}
		}
		writer.toString()
	}

	<span class="code-keyword">static</span> <span class="code-object">int</span> getWindspeed(DayType that) {
		that.daytime.windspeed / 3.6
	}

}</pre>
</div>
</div>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-Conclusions"></a>Conclusions</h2>
<p>I do think the type of construct represented by the Groovy Categories is a great way to make DDD scale for real-world-scenarios. In real-world scenarios for DDD require some way of separating concerns so that a core domain object can add value (as a first class object in the spirit of DDD). </p>
<p>Traditionally the solutions would involve various types of advanced patterns or frameworks. The sample used in this blog, would require the Visitor Pattern in order to keep the same level of separation of concerns and dependencies. Using qi4j is a Java-only framework solution that would solve the cluttering-problem, but still make the POJO library depend on the fact that it needs to support the needs of an RSS feed. In this specific case, when we are not in control (or pretend not to be) of the domain classes, qi4j would &#8211; to my understanding &#8211; not be useful.</p>
<p>With category support in the language (as in Groovy), DDD becomes much more intuitive to implement.</p>
<h2><a name="UsingCategoriestokeepJavadomainmodelsuncluttered-Tryitout"></a>Try it out</h2>
<p>I&#8217;ve attached a <a href="/wp-content/upload/GroovyDslBlog.zip">zip</a> with the a maven multi project for running the sample. The zip contains one project for the feed web-app and one project that builds the jaxb model classes from the xml schema of the accu weather data response payload.</p>
<p>If you want to use eclipse, then issue&#8230;</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">mvn -Dwtpversion=1.5 eclipse:eclipse</pre>
</div>
</div>
<p>&#8230;which generates an eclipse project for each of the maven projects. Make sure you are located in the GroovyDslBlog folder when running the command. To run/debug in Eclipse with WTP you will also need the Groovy plug-in, available here: <a href="http://dist.codehaus.org/groovy/distributions/update/">http://dist.codehaus.org/groovy/distributions/update/</a> Have fun!</p>
<div class='panelMacro'><b>Improved syntax with AST transformations</b></p>
<p>With Groovy 1.6, something called <a href="http://groovy.codehaus.org/Compile-time+Metaprogramming+-+AST+Transformations">AST Transformations</a> has been added. This allows the programming model to be extended in a modular way without changing the syntax of the language. It has some similarities with what you can achieve with aspectj. Using ast transformations, Groovy 1.6 adds a more object-oriented way of defining categories (yes, exactly the same model as in Objective-C <img class="emoticon" src="/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/>. Unfortunately, as of Groovy 1.6.3, the ast transformer for &#8220;OO&#8221; categories is <a href="http://jira.codehaus.org/browse/GROOVY-3543">a bit shaky (fixed for upcoming 1.6.4)</a>. Using this way of defining the category, it would look like:</p>
<pre class="code-java"><span class="code-keyword">package</span> se.callistaenterprise.labs.groovydslblog.accuatomfeed

<span class="code-keyword">import</span> com.accuweather.weatherdata.DayType
<span class="code-keyword">import</span> groovy.xml.MarkupBuilder
<span class="code-keyword">import</span> java.io.StringWriter

@Category(DayType)
class AstDayTypeRssSupportCategory {

	<span class="code-keyword">public</span> <span class="code-object">String</span> getItemDescription() {
		StringWriter writer = <span class="code-keyword">new</span> StringWriter()
		MarkupBuilder htmlBuilder = <span class="code-keyword">new</span> MarkupBuilder(writer)
		writer &lt;&lt; <span class="code-keyword">this</span>.daytime.txtlong
		htmlBuilder.table {
			tr {
				td {
					img (src: <span class="code-quote">"http:<span class="code-comment">//vortex.accuweather.com/adc2004/common/images/icons/standard/wx/45x45/${that.daytime.weathericon.padLeft(2, '0')}.gif"</span>)
</span>				}
				td {
					ul {
						li (<span class="code-quote">"Realfeel High: ${<span class="code-keyword">this</span>.daytime.realfeelhigh}"</span>)
						li (<span class="code-quote">"Realfeel Low: ${<span class="code-keyword">this</span>.daytime.realfeellow}"</span>)
						li (<span class="code-quote">"Wind direction: ${<span class="code-keyword">this</span>.daytime.winddirection}"</span>)
						li (<span class="code-quote">"Wind speed: ${<span class="code-keyword">this</span>.daytime.windspeed} m/s"</span>)
					}
				}
			}
		}
		writer.toString()
	}
}</pre>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/07/28/using-categories-to-keep-java-domain-models-uncluttered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A stab at Google App Engine</title>
		<link>http://blog.callistaenterprise.se/2009/07/28/a-stab-at-google-app-engine/</link>
		<comments>http://blog.callistaenterprise.se/2009/07/28/a-stab-at-google-app-engine/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 09:29:57 +0000</pubDate>
		<dc:creator>Johan Eltes</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[Java EE]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/07/27/A+stab+at+Google+App+Engine</guid>
		<description><![CDATA[
I decided to see what it would take to deploy the weather feed of my previous post to Google App Engine &#8211; a cloud platform for Java servlets. I went the maven path, so that I could simply deploy to GAE via a maven build command. In order to keep the original project independent of [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>I decided to see what it would take to deploy the weather feed of my previous post to Google App Engine &#8211; a cloud platform for Java servlets. I went the maven path, so that I could simply deploy to GAE via a maven build command. In order to keep the original project independent of GAE, I set up a second web-app project as a war overlay. A war overlay project is a maven war project that that declares a dependency to another war project. Maven then merges the web artifacts of both projects into the web war produced by the depending project. An additional advantage is that I could keep the maven default layout for the original web project. GAE needs a slightly different structure, which is then used in the overlay project only.</p>
<p>This was useful, since GAE-specific stuff goes into a GAE-specific deployment descriptor (appengine-web.xml).</p>
<h2><a name="AstabatGoogleAppEngine-Thetraps"></a>The traps</h2>
<p>Of cause I went into a number of traps, before it all worked.</p>
<ol>
<li>Script files not processed: My app uses Groovy Templates for dynamic html output. Although web.xml had a servlet mapping that matched the extension used for the templates, they were served unprocessed by GAE servlet engine. The solution was to specifically exclude them from static resources in appengine-web.xml:
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">&lt;<span class="code-keyword">static</span>-files&gt;
        &lt;exclude path=<span class="code-quote">"/WEB-INF/**.groovy"</span> /&gt;
        &lt;exclude path=<span class="code-quote">"**.gtpl"</span> /&gt;
    &lt;/<span class="code-keyword">static</span>-files&gt;</pre>
</div>
</div>
<p>(The app doesn&#8217;t use uncompiled groovy, but just to prepare for the future&#8230;)</li>
<li>JAXB doesn&#8217;t work in GAE, what so ever. Although I found JAXWS on the list of Java EE specs not supported by GAE, I still had a hope that plain JAXB without JAXWS network access would work. It didn&#8217;t. So I had to skip JAXB and use Groovy:s Markup builder. As a result, the DDD achieved by Groovy Categories is gone&#8230; <em><strong>(2010-05-15: JAXB is now a supported Java EE component)</strong></em></li>
</ol>
<h2><a name="AstabatGoogleAppEngine-Theresult"></a>The result</h2>
<p>Point an RSS-reader to <a href="http://rss2weather.appspot.com">http://rss2weather.appspot.com</a> and try the advertised feeds (weather for a list of places currently of interest to me).</p>
<p>The source projects are <a href="/wp-content/uploads/GroovyDslBlog_GAE.zip">uploaded </a> as well.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/07/28/a-stab-at-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The ultimate source for schema versioning strategies</title>
		<link>http://blog.callistaenterprise.se/2009/05/18/the-ultimate-source-for-schema-versioning-strategies/</link>
		<comments>http://blog.callistaenterprise.se/2009/05/18/the-ultimate-source-for-schema-versioning-strategies/#comments</comments>
		<pubDate>Sun, 17 May 2009 23:32:18 +0000</pubDate>
		<dc:creator>Johan Eltes</dc:creator>
				<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/05/18/The+ultimate+source+for+schema+versioning+strategies</guid>
		<description><![CDATA[
We are often asked to define WSDL- and schema design guidelines (contract-first) for clients. We have found a core set of guidelines that seem to work well for clients using XML_binding. The core challenge is to find a portable and reasonably useful approach to controlled evolution, supporting backwards- and forwards compatibility across service consumers and [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>We are often asked to define WSDL- and schema design guidelines (contract-first) for clients. We have found a core set of guidelines that seem to work well for clients using XML_binding. The core challenge is to find a portable and reasonably useful approach to controlled evolution, supporting backwards- and forwards compatibility across service consumers and producers bound (via JAX-B or .Net binding technologies). We&#8217;ve seen the chosen approach being used fairly broadly, among others in several oasis specifications (as an example: WS-Topic in <a href="http://docs.oasis-open.org/wsn/wsn-ws_topics-1.3-spec-os.htm#_Toc122514759">WS-Notification</a>), but never really found a good, authoritative point of reference. Until i found this excellent <a href="http://www.w3.org/2001/tag/doc/versioning-xml">document by w3c</a>. It outlines the problem, defines a number of versioning strategies &#8211; each with an identification, and finally lists examples of standards bodies that apply the different strategies. The strategy we are endorsing is <a href="http://www.w3.org/2001/tag/doc/versioning-xml#versionid25">number 2.5</a>.</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/05/18/the-ultimate-source-for-schema-versioning-strategies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Flex, BlazeDS and Spring</title>
		<link>http://blog.callistaenterprise.se/2009/03/06/integrating-flex-blazeds-and-spring/</link>
		<comments>http://blog.callistaenterprise.se/2009/03/06/integrating-flex-blazeds-and-spring/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 07:57:01 +0000</pubDate>
		<dc:creator>Jan Västernäs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wiki.callistaenterprise.se//display/CallistaCom/2009/01/28/Integrating+Flex%2C+BlazeDS+and+Spring</guid>
		<description><![CDATA[
Suppose you have an web application with a service layer implemented by spring beans and want to get a richer user interface ? One way to do it to use Flex.
Parts of the Flex development platform has become Open Source. What you absolutely need is addition to that is the Flex Builder. It enables debugging [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Suppose you have an web application with a service layer implemented by spring beans and want to get a richer user interface ? One way to do it to use Flex.</p>
<p>Parts of the Flex development platform has become Open Source. What you absolutely need is addition to that is the Flex Builder. It enables debugging of the Flex application and without that you are completely lost. The license is 150 Euro so it is no big deal.</p>
<p>So the User Interface is produced using Flex and to take care of the remoting we can use BlazeDS which is Open Source from Adobe. BlazeDS is deployed as an web appication.</p>
<p>My Helloworld sample version 1 uses a simple java class on the server side. Version 2 will use spring.<br/><br />
The class has a method</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>public List&lt;Topic&gt; getAllTopics()
</pre>
</div>
</div>
<p><br clear="all" /><br />
Topic contains two attributes speaker and name.</p>
<p>In Flex I define a RemoteObject to describe the communication with the server</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">&lt;mx:RemoteObject id=<span class="code-quote">"server"</span> destination=<span class="code-quote">"cadec-service"</span> &gt;
	&lt;mx:method name=<span class="code-quote">"getAllTopics"</span> result=<span class="code-quote">"getAllTopicsResult(event)"</span>/&gt;
&lt;/mx:RemoteObject&gt;</pre>
</div>
</div>
<p><br clear="all" /><br />
The method tag tells Flex that whenever the getAllTopics Method is called the return value will be handled by the getAllTopicsResult method which is defined like this</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>private function getAllTopicsResult(event:ResultEvent):void	{
	topics = event.result as ArrayCollection;
}
</pre>
</div>
</div>
<p><br clear="all" /><br />
It simply saves the result to a variable topics. Finally a DataGrid is defined to display the result</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>&lt;mx:DataGrid dataProvider="(topics)"&gt;
	&lt;mx:columns&gt;
		&lt;mx:DataGridColumn dataField="speaker" width="150"/&gt;
		&lt;mx:DataGridColumn dataField="name" width="350"/&gt;
	&lt;/mx:columns&gt;
&lt;/mx:DataGrid&gt;
</pre>
</div>
</div>
<p><br clear="all" /><br />
When the page is loaded a call to getAllTopics is made</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>&lt;mx:Application . . . creationComplete="server.getAllTopics()"&gt;
</pre>
</div>
</div>
<p><br clear="all" /><br />
and when the reply arrives the grid is populated and looks like this</p>
<p><br clear="all" /> <img src="/wp-content/uploads/image002.jpg" align="absmiddle" border="0" /><br clear="all" /><br />
<br clear="all" /></p>
<p>BlazeDS need to know what the destination=&#8221;cadec-server&#8221; means. The information is supplied in a file named remoting-config.xml </p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>&lt;destination id="cadec-service"&gt;
     &lt;properties&gt;
          &lt;source&gt;se.callista.CadecService&lt;/source&gt;
     &lt;/properties&gt;
&lt;/destination&gt;
</pre>
</div>
</div>
<p><br clear="all" /></p>
<p>This will create an instance of the CadecService (each time). The classes are put in WEB-INF classes.</p>
<p>HelloWorld sample version 2 uses spring on the server side.</p>
<p>To enable that I followed the instructions outlined by <a href="http://coenraets.org/flex-spring/">http://coenraets.org/flex-spring/</a> <br/><br />
2 classes SpringFactory.class and SpringFactory$SpringFactoryInstance.class needs to be present att WEB-INF/classes.</p>
<p>To enable the spring integration these classes needs to be configured in the services-config file</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>&lt;factories&gt;
     &lt;factory id="spring" class="flex.samples.factories.SpringFactory"/&gt;
&lt;/factories&gt;
</pre>
</div>
</div>
<p><br clear="all" /><br />
Now the remoting-config.xml destination can be changed to use the SpringFactory to get the bean from spring instead of initializing it. Obviously this means that the CadedService class will only be instatiated once.</p>
<div class="preformatted panel" style="border-width: 1px;">
<div class="preformattedContent panelContent">
<pre>&lt;destination id="cadec-service"&gt;
    &lt;properties&gt;
        &lt;factory&gt;spring&lt;/factory&gt;
        &lt;source&gt;cadecService&lt;/source&gt;
    &lt;/properties&gt;
&lt;/destination&gt;
</pre>
</div>
</div>
<p><br clear="all" /><br />
Now everything works again.</p>
<p>If this wasn&#8217;t simple enough we just have to wait for the new spring/flex integration project to deliver <br/><br />
<a href="http://www.infoq.com/news/2009/01/spring-adobe-blazeds;jsessionid=8F49E7F3F0F00D6880768A222111D793">http://www.infoq.com/news/2009/01/spring-adobe-blazeds;jsessionid=8F49E7F3F0F00D6880768A222111D793</a></p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.callistaenterprise.se/2009/03/06/integrating-flex-blazeds-and-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
