<?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>blog.codecentric.de &#187; Fabian Lange</title>
	<atom:link href="http://blog.codecentric.de/en/author/fla/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codecentric.de/en/</link>
	<description>codecentrics Blog on Agile, Architecture, Java, Performance and Enterprise Content Management</description>
	<lastBuildDate>Thu, 02 Sep 2010 13:49:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Easy Performance Analysis with AppDynamics Lite</title>
		<link>http://blog.codecentric.de/en/2010/08/easy-performance-analysis-with-appdynamics-lite/</link>
		<comments>http://blog.codecentric.de/en/2010/08/easy-performance-analysis-with-appdynamics-lite/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 10:30:20 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Performance @en]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4957</guid>
		<description><![CDATA[AppDynamics is the rising star in the Application Performance Management sky. Mirko gives a really good description why AppDynamics delivers the right solutions for todays distributed architectures in his Post &#8220;Troubleshoot Java in production – introducing AppDynamics Lite&#8220;. If you &#8230; <a href="http://blog.codecentric.de/en/2010/08/easy-performance-analysis-with-appdynamics-lite/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>AppDynamics is the rising star in the <strong>Application Performance Management</strong> sky.</p>
<p>Mirko gives a really good description why AppDynamics delivers the right solutions for todays distributed architectures in his Post &#8220;<a href="http://blog.codecentric.de/en/2010/08/troubleshoot-java-in-production-introducing-appdynamics-lite/">Troubleshoot Java in production – introducing AppDynamics Lite</a>&#8220;. If you have not read it yet, head over to it now.</p>
<p>The key promise of AppDynamics is <strong>simplicity</strong>. Easy installation, easy operation and very fast results. In fact this sounds uncommon and hard to believe. But this is indeed the case, as proven by the following uncut screencasts.<br />
<span id="more-4957"></span></p>
<p>Installation of AppDynamics is fast and easy like pie. In this screencast I will be showing to you how to perform the installation in less than 3 minutes (there is a full screen mode in the lower right corner):<br/><br />
<center><object id="scPlayer" class="embeddedObject" width="574" height="393" type="application/x-shockwave-flash" data="http://content.screencast.com/users/FabianLange/folders/Default/media/2b80ef2a-3add-41da-a0dd-1638e0ad27fc/bootstrap.swf" ><param name="movie" value="http://content.screencast.com/users/FabianLange/folders/Default/media/2b80ef2a-3add-41da-a0dd-1638e0ad27fc/bootstrap.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="thumb=http://content.screencast.com/users/FabianLange/folders/Default/media/2b80ef2a-3add-41da-a0dd-1638e0ad27fc/FirstFrame.jpg&#038;containerwidth=574&#038;containerheight=393&#038;content=http://content.screencast.com/users/FabianLange/folders/Default/media/2b80ef2a-3add-41da-a0dd-1638e0ad27fc/appdynamics-lite-installation-english.swf&#038;blurover=false" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="allowScriptAccess" value="always" /><param name="base" value="http://content.screencast.com/users/FabianLange/folders/Default/media/2b80ef2a-3add-41da-a0dd-1638e0ad27fc/" /></object></center></p>
<p>Directly after the installation you can start investigating your performance issues. In the following screencast I show you the basic functionality and a possible workflow for finding the root cause of a slow response (there is a full screen mode in the lower right corner):<br />
<center><br />
<object id="scPlayer" class="embeddedObject" width="586" height="366" type="application/x-shockwave-flash" data="http://content.screencast.com/users/FabianLange/folders/Default/media/3b225a6b-96d5-418d-baa4-32cb97948b95/bootstrap.swf" ><param name="movie" value="http://content.screencast.com/users/FabianLange/folders/Default/media/3b225a6b-96d5-418d-baa4-32cb97948b95/bootstrap.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="thumb=http://content.screencast.com/users/FabianLange/folders/Default/media/3b225a6b-96d5-418d-baa4-32cb97948b95/FirstFrame.jpg&#038;containerwidth=586&#038;containerheight=366&#038;content=http://content.screencast.com/users/FabianLange/folders/Default/media/3b225a6b-96d5-418d-baa4-32cb97948b95/appdynamics-usage-english.swf&#038;blurover=false" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="allowScriptAccess" value="always" /><param name="base" value="http://content.screencast.com/users/FabianLange/folders/Default/media/3b225a6b-96d5-418d-baa4-32cb97948b95/" /></object><br />
</center><br />
AppDynamics Lite is suitable for Development and for Production. It can be installed in almost no time, does not require any complex configuration and delivers valuable results within the first minutes. You can download the free lite edition on <a href="http://www.appdynamics.com/free">appdynamics.com/free</a>.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F08%2Feasy-performance-analysis-with-appdynamics-lite%2F&title=Easy+Performance+Analysis+with+AppDynamics+Lite" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/08/easy-performance-analysis-with-appdynamics-lite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Richfaces Sessions Eating Memory &#8211; Analysis of a Memory Leak</title>
		<link>http://blog.codecentric.de/en/2010/08/richfaces-sessions-eating-memory-analysis-of-a-memory-leak/</link>
		<comments>http://blog.codecentric.de/en/2010/08/richfaces-sessions-eating-memory-analysis-of-a-memory-leak/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 16:36:29 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Java @en]]></category>
		<category><![CDATA[Performance @en]]></category>
		<category><![CDATA[Heapdump]]></category>
		<category><![CDATA[OutOfMemoryError]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Richfaces]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4860</guid>
		<description><![CDATA[When developing a site in JSF many people like to use the Richfaces Framework. It is a pretty solid framework that comes wit a lot of functionality and nice components. It also comes with an Ajax framework called Ajax4JSF (also &#8230; <a href="http://blog.codecentric.de/en/2010/08/richfaces-sessions-eating-memory-analysis-of-a-memory-leak/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When developing a site in JSF many people like to use the <a href="http://www.jboss.org/richfaces">Richfaces Framework</a>. It is a pretty solid framework that comes wit a lot of functionality and nice components. It also comes with an Ajax framework called <a href="http://en.wikipedia.org/wiki/Ajax4jsf">Ajax4JSF</a> (also called a4j). When deploying this site then facing the Internet to production, many people start finding out that their applications eat a lot of memory, leading to unresponsive systems or OutOfMemoryError crashes. This is due to a design issue in JSF / A4J and cannot be easily fixed, but worked around. But lets start with an analysis of whats wrong with our otherwise nice application.<br />
<span id="more-4860"></span></p>
<p><strong>Finding the culprit</strong></p>
<p>To find out whats wrong the best is to create a heap dump at peak usage to show whats consuming all the memory.<br />
After opening that dump in the wonderful <a href="http://www.eclipse.org/mat/">Eclipse MAT</a> you might get a picture like this:</p>
<p><img class="aligncenter size-full wp-image-4863" title="richfaces-sessions" src="http://blog.codecentric.de/wp-content/uploads/2010/08/richfaces-sessions.png" alt="" width="538" height="441" /></p>
<p>Ouch. 1.8 GB out of 2GB are consumed by sessions. I usually then filter by &#8220;StandardSession&#8221; for apache sessions to be able to easily browse around the sessions that have high amount of retained heap.</p>
<p><img class="aligncenter size-full wp-image-4866" title="richfaces-sessions-per-session" src="http://blog.codecentric.de/wp-content/uploads/2010/08/richfaces-sessions-per-session.png" alt="" width="533" height="170" /></p>
<p>Ouch again&#8230; 10MB per session, this cannot scale. Now it could of course be possible that some careless programmer put in  much of our data into the session, but thats simply not true, as we can  easily find out:</p>
<p><img src="http://blog.codecentric.de/wp-content/uploads/2010/08/richfaces-session-detail.png" alt="" title="richfaces-session-detail" width="590" height="435" class="aligncenter size-full wp-image-4964" /></p>
<p>Thats interesting. Almost all of our memory is consumed by AjaxStateHolders. So what does this actually do?</p>
<p><strong>How JSF and A4J work</strong></p>
<p>I try to keep it simple. Before JSF actually renders HTML to the users browser, it builds an internal representation. For each page (or view) this internal representation (called component tree) is created and run through the lifefcycle. Any user events are processed. If there is a component where a user can select one of 3 items, those 3 items are loaded and a string representation put onto the page. The component keeps track of which item is selected.</p>
<p>Now we do not want the user to submit the whole page to select another item, which would cause the component tree to be recreated and a different item to be selected. We want Ajax! For that A4J remembers the state of the components when the page was displayed. So it knows the component tree and those 3 items, and which one was selected. On AJAX actions the component is looked up, the state modified by selecting another item and the partial HTML representation sent back. This is also called partial page rendering.</p>
<p>So how does the remembering work? Well you might have guessed it: It creates a AjaxStateHolder in the user session and attaches the component tree to it.</p>
<p><strong>How this can get big</strong></p>
<p>Ok, this might be the current page. I can have big views but it is only one. No thats unfortunately not true. A4J does store more than one view. But why? Look at your browser, you are quite likely to find a &#8220;back&#8221; button somewhat in the to-left corner. When you click that you see the last page. But the browser did not send a request, so the server does not know that you are on that page. Imagine you click AJAX functionality: Where should the server get the component tree from for that time you have been on the page? Easy answer: This is as well in the AjaxStateHolder. By default this tracks back <strong>16 views</strong>. and because you might come across the same view in your browsing history more than once there are up to <strong>16 variants</strong> of a view.</p>
<p>As you can see this can get big. And remember, this is per user.</p>
<p><strong>How to fix</strong></p>
<p>Unfortunately there is no fix. This is how JSF works, and how A4J works.</p>
<p>There is a ticket on the Richfaces bug tracker which describes this: <a href="https://jira.jboss.org/browse/RF-3878">RF-3878 &#8211; Session memory leak</a>. And the best answer is: reduce the number of views you store.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.faces.numberOfViewsInSession<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.faces.numberOfLogicalViews<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You will loose the browser back button functionality, but gain a lot of memory. Second way to fix is to reduce the size of the component tree, which is most likely affected by big lists of data and complex structures. However this is easier said than done.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F08%2Frichfaces-sessions-eating-memory-analysis-of-a-memory-leak%2F&title=Richfaces+Sessions+Eating+Memory+%26%238211%3B+Analysis+of+a+Memory+Leak" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/08/richfaces-sessions-eating-memory-analysis-of-a-memory-leak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Different Take on Sprint Retrospectives</title>
		<link>http://blog.codecentric.de/en/2010/08/a-different-take-on-sprint-retrospectives/</link>
		<comments>http://blog.codecentric.de/en/2010/08/a-different-take-on-sprint-retrospectives/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 10:00:11 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Scrum @en]]></category>
		<category><![CDATA[Retrospectives]]></category>
		<category><![CDATA[SCRUM]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4854</guid>
		<description><![CDATA[There are many ways to do a good sprint retrospective, so we decided to try a new one every now and then. This time we took the role of a painter, painting out impression of the last sprint into a &#8230; <a href="http://blog.codecentric.de/en/2010/08/a-different-take-on-sprint-retrospectives/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are many ways to do a good sprint retrospective, so we decided to try a new one every now and then.<br />
This time we took the role of a painter, painting out impression of the last sprint into a formidable piece of art.<br />
It might look strange at the beginning, but it quite nicely captures the impressions and feelings about the last iteration and provokes different thoughts than a simple list of items which could be improved. Lets see if we will use this method some time again.<br />
As an example I am going to present you my painting. The ones from my team mates are interesting as well, but I would not dare to show them without permission <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<span id="more-4854"></span><br />
<img class="aligncenter size-full wp-image-4852" title="a_different_reflection" src="http://blog.codecentric.de/wp-content/uploads/2010/08/a_different_reflection.png" alt="" width="565" height="419" /></p>
<p>You can see the long way to our goal. But we are close to it. You can see that I would like to get a reward for the fantastic sprints we did, so I painted a little cake right after the finish line.<br />
Below the path leading to the finish, I depicted our architecture and the actual goal of the project. I really like how well the architecture evolves and works our for us, and also like that our customers start to realize that their confusion was not necessary and they can realize their ideas wit it.<br />
At the top left, there is a bad test stability. It really can be improved and we actually started already addressing this. Right below that you can see our burndown for that iteration, which is not bad, but should have run below the line instead above it.<br />
It seems that I was as well pretty pleased with the amount of features we did create and the value (meaning money) it can generate for our customers. last but not least I draw the great sprint demo we did for our customers the day before.</p>
<p>So how do you like my picture (or doing this kind of retrospective at all)?</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F08%2Fa-different-take-on-sprint-retrospectives%2F&title=A+Different+Take+on+Sprint+Retrospectives" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/08/a-different-take-on-sprint-retrospectives/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Invoking System.gc() can have serious impact</title>
		<link>http://blog.codecentric.de/en/2010/08/invoking-system-gc-can-have-serious-impact/</link>
		<comments>http://blog.codecentric.de/en/2010/08/invoking-system-gc-can-have-serious-impact/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 14:07:09 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Performance @en]]></category>
		<category><![CDATA[Garbage Collection]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4822</guid>
		<description><![CDATA[Not taking JavaDoc seriously can easily happen to any developer. Or maybe you haven&#8217;t read that specific part of it, you should better have read. If you did and cannot see a problem locally, you might be tempted to ignore &#8230; <a href="http://blog.codecentric.de/en/2010/08/invoking-system-gc-can-have-serious-impact/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Not taking JavaDoc seriously can easily happen to any developer. Or maybe you haven&#8217;t read that specific part of it, you should better have read. If you did and cannot see a problem locally, you might be tempted to ignore it. </p>
<p>Here is an often ignored part from <em> java.text.SimpleDateFormat</em> JavaDoc:</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;"> * Date formats are not synchronized.
 * It is recommended to create separate format instances for each thread.
 * If multiple threads access a format concurrently, it must be synchronized
 * externally.</pre></div></div>

<p>Perhaps that warning isn&#8217;t strong enough, because it reads: &#8220;It is recommended&#8221;.<br />
This leads to this highly dangerous line of code I have seen in almost every project and is likely to produce hangs in concurrently accessed code.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> SimpleDataFormat DATE_FORMAT = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yyyy.MM.dd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But it gets worse with <em>System.gc()</em>. <span id="more-4822"></span><br />
There is no warning in the JavaDoc:</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">* Calling the gc method suggests that the Java Virtual
* Machine expend effort toward recycling unused objects in order to
* make the memory they currently occupy available for quick reuse.
* When control returns from the method call, the Java Virtual
* Machine has made a best effort to reclaim space from all discarded
* objects.</pre></div></div>

<p>Doesn&#8217;t sound too bad, does it? You should wonder what &#8220;suggests&#8221; and &#8220;best effert&#8221; really means. Perhaps you are tempted to use System.gc(), so you might look on the internet for other people using this, hoping for an explanation what in reality happens. You might find <a href="http://stackoverflow.com/questions/2414105/why-is-it-a-bad-practice-to-call-system-gc">good insights on Stackoverflow</a>. But what exactly this does nobody seems to know.</p>
<p>I think a picture tells more than thousand words:<br />
<img class="aligncenter size-full wp-image-4796" title="avoid_system_gc" src="http://blog.codecentric.de/wp-content/uploads/2010/07/avoid_system_gc.png" alt="" width="594" height="363" /></p>
<p>We are looking at a pretty big system of one of our customers. It has 14GB of heap and we helped them to bring down the memory consumtion so that the app ran quite well. However there were still pretty long pause times (so called stop the world time). The graph was created from a Garbage Collection log and points us to the cause of the pause times. The blue line shows Garbage Collection activity. So why are there exactly 13 spikes with up to 35 seconds? All the other activity seems to be really fast.<br />
The reason for those 13 spikes is simple: They all were caused by an invocation of <em>System.gc()</em>.</p>
<p>So what happens? Calling <em>System.gc()</em> seems to effectively stop any optimization the GC is doing, forcing a full collection to start, rather than the optimized CMS Algorithm used.</p>
<blockquote><p>Note: This system is using a Sun 1.6.0.18 64 bit HotSpot Server VM. GC is set to -XX:+UseConcMarkSweepGC and -XX:+UseParNewGC. System.gc() does not have to produce results like that. Your results might vary. However also <a href="http://stackoverflow.com/questions/2414105/why-is-it-a-bad-practice-to-call-system-gc/2415234#2415234">others have reported</a>, that when using CMS and System.gc() a Full GC is always performed.</p></blockquote>
<p>If you cannot find yourself invoking <em>System.gc()</em>, they might hide deeply in a used library. To fix this, you can use the the server argument &#8220;-XX:+DisableExplicitGC&#8221;. This argument is also recommended by the <a href="http://docs.sun.com/source/819-0084/pt_tuningjava.html#wp57022">SUN/Oracle performance tuning guide</a>.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F08%2Finvoking-system-gc-can-have-serious-impact%2F&title=Invoking+System.gc%28%29+can+have+serious+impact" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/08/invoking-system-gc-can-have-serious-impact/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Top Excuses Why Automatic Builds Suddenly Fail</title>
		<link>http://blog.codecentric.de/en/2010/07/top-excuses-why-automatic-builds-suddenly-fail/</link>
		<comments>http://blog.codecentric.de/en/2010/07/top-excuses-why-automatic-builds-suddenly-fail/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 22:01:56 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[eXtreme Programming @en]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[hudson]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=2387</guid>
		<description><![CDATA[We at codecentric have hundreds of automatic builds run every day, sometimes they &#8230; fail. This post is not about lame excuses. &#8220;nah the build shouldn&#8217;t fail, that was a trivial change&#8230;&#8221; does not count. But there are situations where &#8230; <a href="http://blog.codecentric.de/en/2010/07/top-excuses-why-automatic-builds-suddenly-fail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We at codecentric have hundreds of automatic builds run every day, sometimes they &#8230; fail. This post is not about lame excuses. &#8220;nah the build shouldn&#8217;t fail, that was a trivial change&#8230;&#8221; does not count. But there are situations where a build fails because &#8230; well nobody really knows.</p>
<p>Some people say: cosmic rays! But we know that is not true. To efficiently utilize a CI system without the need to troubleshoot a long time here some common issues we encountered and ideas how to mitigate them.<br />
<span id="more-2387"></span></p>
<ul>
<li>A test might do some <strong>time calculation</strong> and either in the test or in the code under test time is taken twice. While most of the time there is no difference, there might be a microsecond sometimes. A good indicator for this is a message like: Time was 23:30:00 but expected 23:30:00 (note microseconds are not shown)</li>
<li>Code, Testcode or Testrunner/CI code might leave files behind. Sometimes these are log files, sometimes files produced as test output. Take the time to search the whole server for all file writes made during a test run and take care to have a cleanup in place. Don&#8217;t forget to add <strong>disk space monitoring</strong>, because build machines have hard discs that tend to get full. (Hudson can do both)</li>
<li>Users logging into the CI system might <strong>lock resources</strong>, like files or ports, or do anything bad to the machine. You should not allow user logons.  All &#8220;analysis&#8221; should be made read only. Note that also read access or parallel tests can lock files.</li>
<li>It is not necessarily a bug when your code or tests do not run when the system date is 1th of January 1970. It could be, but you should make sure the system always uses the <strong>current time</strong>. Set up a ntp daemon. If you must use specific points in time for testing, you should be able to set a time source for all of your code, like a spring bean called TimeProvider which normally resorts to the system time.</li>
<li>If your tests need to apply evil hacks to test your software (which might be required. If not get rid of the hacks) it is often safer to let <strong>test execution fork</strong>, so tests cannot introduce side effects via the JVM (like setting System properties). Code coverage tools using bytecode manipulation count as hacks.</li>
<li>If you have multiple build machines ensure that they are as similar as possible. If you can afford it, you can set up a farm of build machines with <strong>defined</strong> differences, so you can spread testing on varying hardware in case this cannot be simulated. You do not want any surprise differences on which you spend hours to find out.</li>
<li>Consider setting up the system under test for integration tests nightly <strong>from scratch</strong>. Those tests tend to get messed up by exploratory testing and ad hoc demos. It is easier to automate such stuff than one would think, though it takes some time.</li>
<li>If you do automatic deployment, you need to at least stop the server, copy changed artifacts and then restart the server. Any kind of &#8220;<strong>hot deployment</strong>&#8221; is unfortunately just to fragile for reliable results.</li>
<li>After doing any <strong>change to configuration</strong> or infrastructure of your CI system trigger a build manually. If not done the next normal developer checkin will cause a failing build and will leave the dev wondering how that change could break this stuff.</li>
<li>If you find your tests hanging in your code, especially if multiple tests were run at the same time,<strong> take a heap and thread dump</strong> of the JVM before restarting the tests. You might be lucky that you found by accident a <strong>real concurrency issue</strong> inside your code. You should be grateful for that because you hardly can deliberately test this.</li>
</ul>
<p>Yes it is possible that the build breaks without any issues in your software, but it wastes a lot of time on investigation. Know the weaknesses of your system and try to fix them or at least document them.</p>
<p>We have an issue with one of our integration test suites, which connects to an external service. Sometimes this just hangs and results in a connection timeout. Until a while ago this always &#8220;broke&#8221; the build. The result of this was that every engineer had a look at the build, the logs and eventually found out it was a timeout on the external system- We discussed this and decided to stop wasting time on investigating this. So we added a mechanic that in this special timeout case the build does not turn red. It stays green, but creates a tag &#8220;timeouted&#8221; on the test. This of course has a problem. A green build with &#8220;timouted&#8221; can have a problem with the computation of the extern call results. It might be really red. But we cannot know this. Real green build are not allowed to have &#8220;timeouted&#8221; tests. But the important part is that we want &#8220;real red&#8221; builds, which turn only red when there is a issue we can fix. In RobotFramework you can <a href="http://robotframework.googlecode.com/svn/trunk/doc/userguide/RobotFrameworkUserGuide.html#setting-background-colors">define a third state for &#8220;noncritical failures&#8221;</a>. Decide yourself if this is something for you.</p>
<p>But the most important takeaway is: <strong>If a broken build is not caused by test or production code, you must find the reason and address it</strong>. You cannot say: &#8220;cosmic rays&#8221; because that will lead everybody to say &#8220;broken build &#8211; cosmic rays&#8221; and you will have much less successful builds because eventually no one will care. <strong>Red should always mean: Team take action!</strong></p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F07%2Ftop-excuses-why-automatic-builds-suddenly-fail%2F&title=Top+Excuses+Why+Automatic+Builds+Suddenly+Fail" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/07/top-excuses-why-automatic-builds-suddenly-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress WPML Comments Filter Plugin</title>
		<link>http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/</link>
		<comments>http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 19:39:56 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4496</guid>
		<description><![CDATA[I admit, this post is a bit &#8220;off-topic&#8221;. Recently we migrated this blog from using qTranslate to WPML for publishing in German and English. Main reasons were much better updates and a cleaner separation. But one feature was missing because &#8230; <a href="http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I admit, this post is a bit &#8220;off-topic&#8221;. Recently we migrated this blog from using qTranslate to WPML for publishing in German and English. Main reasons were much better updates and a cleaner separation.<br />
But one feature was missing because of that: We want to have comments from both languages below the postings (which are now two posts, where they have been one before). WPML doesn&#8217;t support this out of the box, but we were able to do this easily ourselves.<br />
<span id="more-4496"></span></p>
<p>Because we believe in Open Source, here the sourcecode of our comment-merging plugin. If required one could also make languages configurable, but we did not need that, and it would have introduced some more complexity.</p>
<p><a href="http://wordpress.org/extend/plugins/wpml-comment-merging/">WPML comment merging plugin on wordpress.org</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: WPML comment merging
Plugin URI: http://www.codecentric.de
Description: This plugin merges comments from all translations of the posts, so that they all are displayed on each other. Comments are internally still attached to the post they were made on.
Version: 1.0
Author: Fabian Lange
Author URI: http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/
License: MIT
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sort_merged_comments<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$b</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> merge_comments<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// get all the languages for which this post exists</span>
	<span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> icl_get_languages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'skip_missing=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$languages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$l</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// in $comments are already the comments from the current language</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$l</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'active'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$otherID</span> <span style="color: #339933;">=</span> icl_object_id<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$l</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'language_code'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$othercomments</span> <span style="color: #339933;">=</span> get_comments<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$otherID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'approve'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #339933;">,</span> <span style="color: #000088;">$othercomments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$languages</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// if we merged some comments in we need to reestablish an order</span>
		<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sort_merged_comments'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$comments</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> merge_count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// get all the languages for which this post exists</span>
	<span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> icl_get_languages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'skip_missing=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$languages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$l</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// in $count is already the count from the current language</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$l</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'active'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		        <span style="color: #000088;">$otherID</span> <span style="color: #339933;">=</span> icl_object_id<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$l</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'language_code'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$otherpost</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$otherID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// increment comment count using translation post comment count.</span>
                	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$otherpost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_count</span><span style="color: #339933;">;</span>
        	<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments_array'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'merge_comments'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_comments_number'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'merge_count'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F06%2Fwordpress-wpml-comments-filter-plugin%2F&title=WordPress+WPML+Comments+Filter+Plugin" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/06/wordpress-wpml-comments-filter-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Style Tests using Selenium and Robotframework</title>
		<link>http://blog.codecentric.de/en/2010/06/style-tests-using-selenium-and-robotframework/</link>
		<comments>http://blog.codecentric.de/en/2010/06/style-tests-using-selenium-and-robotframework/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 07:49:38 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[codecentric]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Robotframework]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=3989</guid>
		<description><![CDATA[In projects facing end customers style matters, often more than less. While in internal apps it doesn&#8217;t matter if the UI changes after each release, there might be customers that want their app to follow a very strict style guide &#8230; <a href="http://blog.codecentric.de/en/2010/06/style-tests-using-selenium-and-robotframework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In projects facing end customers style matters, often more than less. While in internal apps it doesn&#8217;t matter if the UI changes after each release, there might be customers that want their app to follow a very strict style guide to integrate with their corporate identity.<br />
If you ever worked with HTML and pixel perfect CSS you know that things can easily screw up, even with very strict layout guidelines.<br />
Last Friday we brainstormed in our team on how to make this part of our nightly build.<br />
We found a solution which was surprisingly simple..<br />
<span id="more-3989"></span></p>
<h3>The idea</h3>
<p><img src="http://blog.codecentric.de/wp-content/uploads/2010/06/style-checking.png" alt="" title="style-checking" width="301" height="127" class="alignright size-full wp-image-3881" /> When the developer created HTML and CSS for a component (like a login box) and made sure that it was looking fine in all required browsers, the developer would take a screenshot, and crop it to contain only the box. Like depicted here on the right, we would want to make sure that the logo inside the red box looks exactly like that.<br />
Next the automatic build needs to be told on which page this box is expected to be (e.g. a page with a user that is not logged in). The test takes then a screenshot and searches it for the expected box.<br />
We considered also telling at which position we expect it, but that would cause multiple issues: The dev needs to find the pixel position. It needs to be absolute on different screen sizes, changes are hard to track.<br />
When thinking about this, we believe that finding the expected sub-image in the screenshot is sufficient. If you would want to make sure it is at a specific position you just include neighboring objects in your expectation image.</p>
<h3>The Implementation</h3>
<p>We wrote a very simple keyword that takes a screenshot of a given URL (and possibly after performing steps like putting stuff to a shopping cart) and checks the occurrences of template screenshots. The keyword is implemented in Robot BDD using Selenium.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">*** Keywords ***	
&nbsp;
Match Styles ${Styles}
    Execute Javascript  window.resizeTo(100,100)
    ${ID} =  Get Unique ID
    Capture Page Screenshot  ${OUTPUT DIR}${/}StyleTest-${ID}.png  css=
	:FOR  ${style}  IN  @{Styles}
    \	Match Style  ${CURDIR}${/}styles${/}${style}.png  ${OUTPUT DIR}${/}StyleTest-${ID}.png
    Remove File  ${OUTPUT DIR}${/}StyleTest-${ID}.png</pre></div></div>

<p>The Javascript helps in bringing down the file size of the screenshot and makes searching faster, as it compresses unused whitespace which occurs in many liquid layouts. Get Unique ID generates us an ID using <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html">Java UUID</a>.</p>
<p>The keyword is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #006600; font-weight: bold;">void</span> matchStyle<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> expectedFilename, <span style="color: #003399; font-weight: bold;">String</span> actualFilename<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">IOException</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-weight: bold;">boolean</span> check = StyleChecker.<span style="color: #006633;">check</span><span style="color: #009900;">&#40;</span>expectedFilename, actualFilename<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>check<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;could not find expected image in actual screenshot&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The actual picture searching is done in Java. The code is not superclever, but after a few rounds of optimization pretty fast (worst case: up to 300ms when expected part is not found, in real use cases averages about 200ms for existing sub-images). In fact the screenshot generation is the bottleneck.<br />
<a href='http://blog.codecentric.de/wp-content/uploads/2010/06/StyleChecker.java'>Java code can be downloaded</a> and is excluded here for brevity.</p>
<p>A test can look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">*** Keyword ***
Behaviour
    [Arguments]  ${Url}  @{Styles}
&nbsp;
    Go To  ${Url}
    Match Styles @{Styles}
&nbsp;
| *Test Case* | | *Url*                        | *style*          |
| 1 | Behaviour | http://${BASE_URL}${CONTEXT} | Login | ShoppingCart-Empty|</pre></div></div>

<h3>Caveats</h3>
<ol>
<li>The screenshots need to be lossless.</li>
<li>Our code is pixel perfect. Which means that every tiny detail is important. Because of that Developers cannot take screenshots of their own to crop, but need to take the screenshot that is produced by selenium. There are differences, for example clear type, or available fonts.</li>
<li>When implementing picture comparison in Java you can make it horribly wrong. I hope my code is not that bad. At least I benchmarked it and for the simplicity of the algorithm it performs fine.</li>
</ol>
<h3>Benefits</h3>
<p>With those simple steps we are able to do regression testing on our user interfaces that have strict standards. It helps even more, because CSS is sometimes a bit fragile. And because of the simplicity of the testsetup it is also very easy to add new test withing seconds.</p>
<h3>Debugging</h3>
<p>What happens, if a style test fails? More often than not, the analysis is trivial, because style bugs that should be found with these kind of tests (wrong borders and margins, colors don&#8217;t match, wrong image, etc.) can be quickly detected by looking at the screenshot. But right now we had the situation, where this was not the case, and immediately suspected a refactoring gone bad. We were wrong! In order to detect differences in two images, you can use <a href="http://docs.gimp.org/en/gimp-concepts-layer-modes.html#layer-mode-difference">GIMP&#8217;s layer mode &#8220;difference&#8221;</a>; </p>
<ul>
<li>Load screenshot (1) in GIMP</li>
<li>Load image (2), that should be found in the screenshot, in GIMP</li>
<li>Lay image (2) as new, half-transparent layer over the screenshot</li>
<li>Apply mode &#8220;difference&#8221; to the new layer</li>
<li>Merge the visible layers</li>
<li>Brighten up the darker image parts, to see the differences.</li>
</ul>
<p>So far for the short tutorial for debugging. In case you run into troubles, please comment.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F06%2Fstyle-tests-using-selenium-and-robotframework%2F&title=Style+Tests+using+Selenium+and+Robotframework" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/06/style-tests-using-selenium-and-robotframework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Automatic Proxy Selection for Mule ESB Webservices</title>
		<link>http://blog.codecentric.de/en/2010/03/automatic-proxy-selection-for-mule-esb-webservices/</link>
		<comments>http://blog.codecentric.de/en/2010/03/automatic-proxy-selection-for-mule-esb-webservices/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 07:05:16 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[Java @en]]></category>
		<category><![CDATA[Spring @en]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[mule]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4104</guid>
		<description><![CDATA[When configuring mule, you might find out that some of your services need to call external parties. Depending on your deployment scenario there needs to be a proxy server involved. However this might change for various test stages, some need, &#8230; <a href="http://blog.codecentric.de/en/2010/03/automatic-proxy-selection-for-mule-esb-webservices/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When configuring mule, you might find out that some of your services need to call external parties. Depending on your deployment scenario there needs to be a proxy server involved. However this might change for various test stages, some need, some don&#8217;t, some need them only for specific domains and like that.<br />
To reduce configuration overhead we have created an automatic proxy selector used for our services. Because I think its neat, I want to share it with you.<br />
<span id="more-4104"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;https:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autoProxy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proxyHostname&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jndiName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/jndi/config/proxyHost&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultObject&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proxyPort&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jndiName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/jndi/config/proxyPort&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultObject&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service-overrides</span> <span style="color: #000066;">dispatcherFactory</span>=<span style="color: #ff0000;">&quot;de.codecentric.mule.HttpAutoProxyMessageDispatcherFactory&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;https:tls-key-store</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/mule.keystore&quot;</span> <span style="color: #000066;">keyPassword</span>=<span style="color: #ff0000;">&quot;changeit&quot;</span> <span style="color: #000066;">storePassword</span>=<span style="color: #ff0000;">&quot;changeit&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;https:tls-server</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/mule.keystore&quot;</span> <span style="color: #000066;">storePassword</span>=<span style="color: #ff0000;">&quot;changeit&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/https:connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As you can se we configured a Connector which creates this MessageDispatcherFactory, it passes the configuration obtained from JNDI to it and also adds a keystore for ssl connections to it (with the great default password changeit <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )<br />
Using it is then straightforward:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound-endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;https://external.service/endpoint&quot;</span> <span style="color: #000066;">synchronous</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">connector-ref</span>=<span style="color: #ff0000;">&quot;autoProxy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>The Factory itself is dead simple:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HttpAutoProxyMessageDispatcherFactory
  <span style="color: #000000; font-weight: bold;">extends</span> AbstractMessageDispatcherFactory <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> MessageDispatcher create<span style="color: #009900;">&#40;</span>OutboundEndpoint endpoint<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MuleException <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> HttpAutoProxyMessageDispatcher<span style="color: #009900;">&#40;</span>endpoint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The HttpAutoProxyMessageDispatcher implementation is easy was well. And contains a few hardcoded hosts that should not be proxied. Feel free to improve that part:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HttpAutoProxyMessageDispatcher
  <span style="color: #000000; font-weight: bold;">extends</span> HttpClientMessageDispatcher <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">boolean</span> hasProxy<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">String</span> proxyHost<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #006600; font-weight: bold;">int</span> proxyPort<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> HttpAutoProxyMessageDispatcher<span style="color: #009900;">&#40;</span>OutboundEndpoint endpoint<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>endpoint<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">proxyHost</span> = <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpConnector<span style="color: #009900;">&#41;</span> endpoint.<span style="color: #006633;">getConnector</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getProxyHostname</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">proxyPort</span> = <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpConnector<span style="color: #009900;">&#41;</span> endpoint.<span style="color: #006633;">getConnector</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getProxyPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hasProxy</span> = StringUtils.<span style="color: #006633;">isNotBlank</span><span style="color: #009900;">&#40;</span>proxyHost<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @<span style="color: #003399; font-weight: bold;">Override</span>
  <span style="color: #000000; font-weight: bold;">protected</span> HostConfiguration getHostConfig<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">URI</span> uri<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">URISyntaxException</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399; font-weight: bold;">String</span> host = uri.<span style="color: #006633;">getHost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    HostConfiguration config = <span style="color: #000000; font-weight: bold;">new</span> HostConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    config.<span style="color: #006633;">setHost</span><span style="color: #009900;">&#40;</span>host, uri.<span style="color: #006633;">getPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, Protocol.<span style="color: #006633;">getProtocol</span><span style="color: #009900;">&#40;</span>uri.<span style="color: #006633;">getScheme</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hasProxy <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isLocalhost<span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      config.<span style="color: #006633;">setProxy</span><span style="color: #009900;">&#40;</span>proxyHost, proxyPort<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> config<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #006600; font-weight: bold;">boolean</span> isLocalhost<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> host<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;localhost&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#41;</span> || <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When you applied this pattern you only need to make sure JNDI information regarding the proxy is correct on each environment, and the mule configuration will automatically adapt to it.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F03%2Fautomatic-proxy-selection-for-mule-esb-webservices%2F&title=Automatic+Proxy+Selection+for+Mule+ESB+Webservices" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/03/automatic-proxy-selection-for-mule-esb-webservices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple and Fast Webservices with Mule ESB and Apache CXF</title>
		<link>http://blog.codecentric.de/en/2010/03/simple-and-fast-webservices-with-mule-esb-and-apache-cxf/</link>
		<comments>http://blog.codecentric.de/en/2010/03/simple-and-fast-webservices-with-mule-esb-and-apache-cxf/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 19:50:55 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java @en]]></category>
		<category><![CDATA[Performance @en]]></category>
		<category><![CDATA[codecentric]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[mule]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4108</guid>
		<description><![CDATA[In this blog post, I want to show you how we at codecentric are using Mule ESB and Apache CXF in our projects to create webservices very easily, and what you can do to make them faster, because they are &#8230; <a href="http://blog.codecentric.de/en/2010/03/simple-and-fast-webservices-with-mule-esb-and-apache-cxf/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this blog post, I want to show you how we at codecentric are using Mule ESB and Apache CXF in our projects to create webservices very easily, and what you can do to make them faster, because they are pretty slow out of the box.<br />
So why a webservice at all? This is a good question, and perhaps the most critical for performance. Webservices are good if you want to make your Interface or Service public, or want to use them internally where other transports (like RMI) are not available, either due to firewall configuration or cross programming language environments. People struggling with a good setup might often not be able to change this at all, so lets take it for granted.<br />
<span id="more-4108"></span><br />
We use the Mule Enterprise Service Bus in some projects, but it might not be your product of choice. Documentation is only available when registering on their site, and their release policy is a bit unclear. I am not that happy with it, but it works pretty well when you found your hooks and patched a <a href="http://www.mulesoft.org/jira/browse/MULE-4095">few</a> <a href="http://www.mulesoft.org/jira/browse/MULE-4634">places</a>. To expose Webservices you can handcode them, use <a href="http://ws.apache.org/axis/">Apache Axis</a> or <a href="http://cxf.apache.org/">Apache CXF</a>. I prefer CXF because I find its API and generated code cleaner, also it is still alive and maintained by mule people and default for mule as well. For the service component we use plain spring pojos.</p>
<p>So lets have a look at our Webservice Interface. To make it a little more interesting, we make a nontrival service, which takes and returns domain objects (but be aware of the http request size on large object trees)</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">@WebService
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> RecommendationService <span style="color: #009900;">&#123;</span>
	@WebMethod
	<span style="color: #000000; font-weight: bold;">public</span> Products recommendProducts<span style="color: #009900;">&#40;</span>
		@WebParam<span style="color: #009900;">&#40;</span>name=<span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span>
		User user,
		@WebParam<span style="color: #009900;">&#40;</span>name=<span style="color: #0000ff;">&quot;genre&quot;</span><span style="color: #009900;">&#41;</span>
		Genre genre
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There is an implementation for this service existing as well. The next step is then to wire it up in mule.<br />
First we need to configure mule to accept webservice calls. Because we start mule in an WAR file, we use the servlet connector, but you can use the jetty connector as well when running standalone:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;servletConnector&quot;</span> </span>
<span style="color: #009900;">                   <span style="color: #000066;">servletUrl</span>=<span style="color: #ff0000;">&quot;http://localhost:8080/mule/services/recommendation?wsdl&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Next up is the config of the service itself using cxf:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;recommendationServiceModel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;recommendation&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cxf:inbound-endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;servlet://recommendation&quot;</span> <span style="color: #000066;">synchronous</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring-object</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;RecommendationService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And of course the service:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;RecommendationService&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;de.codecentric.RecommendationServiceImpl&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>While you can mash all into one file, I recommend to split your mule and component configuration to multiple files, so that you do not get lost in the masses of xml. You could separate them by type (service, component, mule config) or by service.<br />
That is it already for the mule configuration part, so lets try to invoke it. Because we do not have an easy way to pass the domain objects yet, we just try to read the wsdl to veryify it is working.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>mule<span style="color: #000000; font-weight: bold;">/</span>services<span style="color: #000000; font-weight: bold;">/</span>recommendation?wsdl</pre></div></div>

<p>Watch out for any <wsdl:import/>s which tell you that the listing is not complete, but is available on a seperate url geven as attribute in the import.</p>
<p>Generating a java client for accessing the service is very easy using the wsdl2java command from CXF:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wsdl2java <span style="color: #660033;">-client</span> <span style="color: #660033;">-d</span> src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>java <span style="color: #660033;">-p</span> de.codecentric.client 
  http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>mule<span style="color: #000000; font-weight: bold;">/</span>services<span style="color: #000000; font-weight: bold;">/</span>recommendation?wsdl</pre></div></div>

<p>If you would be an external party, you now could work with the stuff that has been generated. Internally however you most likely would prefer continue working with your domain objects User, Products and Genre. This will help you dealing with updates happening in your developmentcycle and provide domain methods you implemented on the model, but are not generated. Because CXF is really smart we can just delete the following generated classes:</p>
<ul>
<li>Genre</li>
<li>ObjectFactory</li>
<li>package-info</li>
<li>Products</li>
<li>User</li>
</ul>
<p>Fix the imports by using your domain objects instead and delete the <strong>@XmlSeeAlso({ObjectFactory.class})</strong> reference.</p>
<p>This should leave you with the interface and implementation of the service and two wrapper objects for request and response, and a dummy client. Running the dummy client (with CXF on the classpath) should now invoke the webservice.</p>
<p>What it does behind the scenes when you are using</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">RecommendationServiceImplService ss = <span style="color: #000000; font-weight: bold;">new</span> RecommendationServiceImplService<span style="color: #009900;">&#40;</span>wsdlURL, SERVICE_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
RecommendationService port = ss.<span style="color: #006633;">getRecommendationServiceImplPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>is that it creates a dynamic proxy using reflection from the remote wsdl.</p>
<p>We could stop here now. We have a dynamic Webservice client that uses the domain objects. All is fine, but the performance really sucks.</p>
<p>The WSDL is read over the wire, and translated to the proxy class. We could add the WSDL locally, but that would require downloading it everytime the domain objects change. External clients of course need to do that, but we want to be less affected by the changes incremental development introduces. Also still the proxy class generation would be slow. We measured the wall time spent in the whole stack, and proxy generation by far outnumbered every other code.</p>
<p>To improve this we create a pool, using commons pool GenericObjectPool.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> GenericObjectPool recommendationServicePool<span style="color: #339933;">;</span>
&nbsp;
RecommendationServiceFactory recommendationServiceFactory = <span style="color: #000000; font-weight: bold;">new</span> RecommendationServiceFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
recommendationServicePool = <span style="color: #000000; font-weight: bold;">new</span> GenericObjectPool<span style="color: #009900;">&#40;</span>recommendationServiceFactory, <span style="color: #000000; font-weight: bold;">new</span> Config<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So the pool needs a factory to make instances and a configuration. The confguration can be tweaked, but defaults should be fine for now.The factory implementation is straightforward:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RecommendationServiceFactory <span style="color: #000000; font-weight: bold;">implements</span> PoolableObjectFactory  <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Object</span> makeObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
  RecommendationServiceImplService service = <span style="color: #000000; font-weight: bold;">new</span> RecommendationServiceImplService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  RecommendationService port = service.<span style="color: #006633;">getRecommendationServiceImplPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">return</span> port<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">boolean</span> validateObject<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// consider all controllers valid objects</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> destroyObject<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> activateObject<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> passivateObject<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we can invoke our service like that:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">RecommendationService port = <span style="color: #009900;">&#40;</span>RecommendationService<span style="color: #009900;">&#41;</span> recommendationServicePool.<span style="color: #006633;">borrowObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
  Products products = port.<span style="color: #006633;">recommendProducts</span><span style="color: #009900;">&#40;</span>user, genre<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
  recommendationServicePool.<span style="color: #006633;">returnObject</span><span style="color: #009900;">&#40;</span>port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Please do not forget to return the Service you have borrowed.</p>
<p><strong>Wrap up</strong><br />
We used MuleESB to configure and deploy a Spring component based Webservice which uses Domain objects. We exposed the service using Apache CXF and used it to generate a client as well. Afterwards we tweaked the generated client to use our domain objects instead of generated clients. Then we introduced an object pool to avoid creating the proxy classes over and over again.</p>
<p>perhaps you want to know if there was a real performance gain. I strongly advise to profile it yourself. The simplest method is to measure milliseconds orund our last codeblock, executing it more than once. The very first invocation of the whole stack took 360ms on my machine. All subsequent calls were down to 4-6ms. This is a 100x improvement. Remember, that this time includes a lot: Calling over HTTP (even on localhost) a ESB running inside a WAR on JBoss, finding the correct service endpoint based on the URL, invoking an instance of that Service, and all the way back.</p>
<p>Do not judge premature. Web Services can be pretty fast. And thanks to a lot of frameworks, also easy to setup.</p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F03%2Fsimple-and-fast-webservices-with-mule-esb-and-apache-cxf%2F&title=Simple+and+Fast+Webservices+with+Mule+ESB+and+Apache+CXF" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/03/simple-and-fast-webservices-with-mule-esb-and-apache-cxf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Specialist Master Course Field Report</title>
		<link>http://blog.codecentric.de/en/2010/03/java-specialist-master-course-field-report/</link>
		<comments>http://blog.codecentric.de/en/2010/03/java-specialist-master-course-field-report/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 09:11:37 +0000</pubDate>
		<dc:creator>Fabian Lange</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Java @en]]></category>
		<category><![CDATA[meet the experts @en]]></category>
		<category><![CDATA[codecentric]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[meet the experts]]></category>

		<guid isPermaLink="false">http://blog.codecentric.de/?p=4114</guid>
		<description><![CDATA[Last week I had the pleasure attended Heinz Kabutz Java Specialists Master course to sharpen my Java skills. Java Champion Heinz, is a great trainer who manages to combine anecdotes, hard facts and deep Java knowledge with engaging exercises to &#8230; <a href="http://blog.codecentric.de/en/2010/03/java-specialist-master-course-field-report/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last week I had the pleasure attended Heinz Kabutz <a href="http://www.javaspecialists.eu/courses/master.jsp">Java Specialists Master course</a> to sharpen my Java skills. <a href="https://java-champions.dev.java.net/content/corechampions.html">Java Champion Heinz</a>, is a great trainer who manages to combine anecdotes, hard facts and deep Java knowledge with engaging exercises to a well done course. The scope was the whole spectrum of Java, but focusing on the details you normally do not use, or know how to use. Some of the material he already published as part of <a href="http://www.javaspecialists.eu/archive/archive.jsp">his newsletters</a>, which are read all around the world.</p>
<p>Let me share my impressions on the course with you in this day by day review&#8230;<br />
<span id="more-4114"></span></p>
<p><strong>Day 1</strong></p>
<p>The course started with discussing Threads, and how we should use them. Quite a complex topic for early morning. We played with a ThreadGroup that became a custom Thread pool. <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadGroup.html">ThreadGroup</a> is not the best designed class. Heinz called it a child&#8217;s drawing from the early years of Java. I found using the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/package-summary.html">java.util.concurrent Locks</a> really easy. Finally gone are the days of <em>synchronized()</em>. Before the lunch break, Heinz showed us his laws on concurrency, which he also presented in an abbreviated form at our <a href="http://www.meettheexperts.de/static/pdf/praesentationen/2009-06-26-performance/meet-the-experts-the-secrets-of-concurrency.pdf">meet the experts &#8211; performance event</a>. We came across this code:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #006600; font-weight: bold;">boolean</span> running = <span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> dojob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000;  font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>running<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something useful</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> shutdown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  running = <span style="color: #006600; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When running in a Server VM (with java -server), this might never stop, due to optimizing running would be inlined by HotSpot with being true all the time. To avoid this you would have to make it <em>volatile</em>. Because I asked about debugging, we tried stopping there and the debugger showed us: <em>running = false</em>. Still the code continued to executed, because the debugger sees the correct field value, but the running code doesn&#8217;t. It gets more interesting with this code:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> doJob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-weight: bold;">boolean</span> myRunning = running<span style="color: #339933;">;</span>
  <span style="color: #000000;  font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>running<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something useful</span>
    myRunning = running<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When looking with the debugger we saw this:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">running = <span style="color: #006600; font-weight: bold;">false</span><span style="color: #339933;">;</span> myrunning = <span style="color: #006600; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>however the loop still looped. But when forcing the line to execute via F7, code terminated. This can be a nightmare to debug, so it is good to know what you should take care of when writing multithreaded programs.</p>
<p>Also something to remember is to check</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Thread</span>.<span style="color: #006633;">interrupted</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">InterruptedException</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>as first code in all methods declaring an <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/InterruptedException.html">InterruptedException</a>.</p>
<p>We learned about <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/CompletionService.html">CompletionService</a> looks like an interesting interface for mass processing of asynchronous work. So, who needs closures? <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Day 2</strong></p>
<p>We started with <a href="http://java.sun.com/j2se/1.4.2/docs/guide/nio/">Java new (yet another new?) IO</a>, which brings quite a lot of new features, but somehow is not as widely used as it should be. One reason might be that it can easily get much more complicated to use. Perhaps one should try easy examples before writing an Async nonblocking server (which you can after attending the course <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ).</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">FileChannel</span> fc = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">RandomAccessFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.txt&quot;</span>, <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getChannel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">MappedByteBuffer</span> buffer = fc.<span style="color: #006633;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">FileChannel.<span style="color: #006633;">MapMode</span></span>.<span style="color: #006633;">READ_ONLY</span>, <span style="color: #cc66cc;">0</span>, fc.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Second half was on understanding Java memory management. This of course is less often really applicable, but understanding it is quite critical to solving problems. We had a look at stuff like caching and pooling, and why this creates leaks or loitering objects. This reminds me of my older <a href="http://blog.codecentric.de/2009/08/jsp-tag-pooling-memory-leaks/">post about tag pooling</a> in servlet containers. I never understood really why tags are pooled, and even worse, do not have proper lifecycle methods to detect this when using an IDE. We used <a href="https://visualvm.dev.java.net/">jVisualVm</a> and <a href="http://www.javaperformancetuning.com/tools/hpjmeter/index.shtml">HPjMeter</a> to watch the GC at work.</p>
<p><strong>Day 3</strong></p>
<p>On day 3, I learned some interesting inner mechanics of Collection classes I did not use before (like <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html">PriorityQueue</a>), as well as some nasty tricks on classloading. Heinz explained<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Proxy.html"> java.lang.reflect.Proxies</a> really well, and once understood, using them was not that difficult. Actually the best instruction is in the JavaDoc, but you must know how to read it:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">Foo f = <span style="color: #009900;">&#40;</span>Foo<span style="color: #009900;">&#41;</span> <span style="color: #003399; font-weight: bold;">Proxy</span>.<span style="color: #006633;">newProxyInstance</span><span style="color: #009900;">&#40;</span>
		Foo.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Class</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> Foo.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,
		<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">InvocationHandler</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Object</span> invoke<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> foo, <span style="color: #003399; font-weight: bold;">Method</span> method, <span style="color: #003399; font-weight: bold;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arguments<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Throwable</span> <span style="color: #009900;">&#123;</span>
		    <span style="color: #000000; font-weight: bold;">return</span> method.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>foo, arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the afternoon we discussed about Exceptions, and I made up my mind on checked vs unchecked exceptions. Personally I will use unchecked exceptions for developer/programming errors. Catching them is not required, app may crash &#8211; Developers should fix this. However everything which is related to the Environment the app runs ins should work with checked exceptions. Ideally they provide sensible information, not just a message. Also quite important: Just rethrow Exceptions! Found yourself not able to decide what to do with an InterruptedException? Well just rethrow it <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  And handle it in the Thread code (calling interrupted() and exiting a loop). I never did that often, because I don&#8217;t like polluting my method signature, but it should be considered. Do not be afraid of retrowing Exceptions.</p>
<p><strong>Day 4</strong></p>
<p>The last day of the course started with a tough performance optimization exercise. The tough part was that we were not allowed to improve the code until we had all the numbers written down and eliminated any overhead of testing code. I especially liked this, because it thought me how eager I am sometimes fixing issues that I forget proving them first. As kind of side note, we discussed the various modes the JVM can run in and found out how slow java -Xint is.  After having sped up the code down to 10% of its initial runtime, we moved on to Date and Time, which was a bit short chapter. I can recommend using <a href="http://joda-time.sourceforge.net/">jodatime</a> and <a href="http://site.icu-project.org/">icu4j</a>, and try to stay away from java.util.Date. Before the end of the course we covered logging including some nifty tricks. The most important lesson about logging is that you need to use code guards (which was not new to me, but I like the term, I never heard before):</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>log.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span>complexObject.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> + expensive.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Wrap-Up</strong></p>
<p>I can wholeheartedly recommend this course. 4 days packed with lots of information and exercises that are well done so that they are a challenge for every participant. You should have worked with Java already some time. This is definitely not a beginners course. You will rush past topics which you can only grasp when you have experienced the problem before. I can also recommend taking this training in German, because Heinz has a really funny accent <img src='http://blog.codecentric.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="dzone_button" style="float: right; margin: 10px 0;">
<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=2&url=http%3A%2F%2Fblog.codecentric.de%2Fen%2F2010%2F03%2Fjava-specialist-master-course-field-report%2F&title=Java+Specialist+Master+Course+Field+Report" height="25" width="155" scrolling="no" frameborder="0"></iframe>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.codecentric.de/en/2010/03/java-specialist-master-course-field-report/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
