<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Programming</title>
	
	<link>http://programming.manessinger.com</link>
	<description>Andreas Manessinger On Software And How To Make It</description>
	<lastBuildDate>Mon, 23 May 2011 09:17:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/manessinger/dBES" /><feedburner:info uri="manessinger/dbes" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>11 – Welcome To Azzyzt JEE Tools</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/uvcKHUt8wpo/</link>
		<comments>http://programming.manessinger.com/2011/05/22/11-welcome-to-azzyzt-jee-tools/#comments</comments>
		<pubDate>Sun, 22 May 2011 21:18:37 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Azzyzt JEE Tools]]></category>
		<category><![CDATA[Code Generators]]></category>
		<category><![CDATA[Corba/IIOP]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Model Driven Design]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=634</guid>
		<description><![CDATA[I have already hinted at it in the answers to comments, but now it is official. Azzyzt JEE Tools are available as open source. Azzyzt JEE Tools are based on my Eclipse / GlassFish / Java EE 6 Tutorial and on a subsequent internal class that I held in October/November 2010 and that was based <a href='http://programming.manessinger.com/2011/05/22/11-welcome-to-azzyzt-jee-tools/' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2010/20100920_181925_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2010/20100920_181925_ps.jpg" alt="" border="0" /></a> </p>
<p>I have already hinted at it in the answers to comments, but now it is official.</p>
<p><a target="_blank" href="http://www.azzyzt.org/">Azzyzt JEE Tools</a> are available as open source. </p>
<p>Azzyzt JEE Tools are based on my <a href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/" target="_blank">Eclipse / GlassFish / Java EE 6 Tutorial</a> and on a subsequent internal class that I held in October/November 2010 and that was based on the tutorial as well. The code generated by Azzyzt JEE Tools is basically a refinement of the code presented in the tutorial, with some very interesting features added.</p>
<p>For your convenience, here is the announcement again:</p>
<p>Version 1.0.0 has been available since end of March, but I had not announced it. Thus 1.1.0 is the first version that&#8217;s really open to the public.</p>
<p>Azzyzt JEE Tools is a collection of software tools helping software developers to create software using Java Enterprise Edition 6. It is designed to be integrated into popular Java IDEs, and at the moment this means it is an Eclipse plugin.</p>
<blockquote><p>
<i>Azzyzt JEE Tools is a set of Eclipse plugins for creating a so-called <b>azzyzted project</b>, and for <b>creating code</b> from a model. Azzyzt uses <b>Java JPA entities as a model</b>, and from that model it creates an enterprise application, ready to be deployed in a <b>Java EE 6</b> application server like GlassFish 3.1, ready to be accessed via <b>CORBA</b>, <b>SOAP</b> and <b>REST</b>. Thus the generated application is a set of web services, providing all that you need in a typical CRUD application.</i><br />
<i>Generated enterprise applications have separate source folders for generated and developer-supplied content. Add your own functionality to a well-engineered base project.</i><br />
<i>Azzyzt JEE Tools is not about user interfaces. It is expected that the generated application is accessed by a RIA frontend (Flex/Flash, Silverlight, Java FX, &#8230;) or by a fat client. </i></p></blockquote>
<p>If you just want to use Azzyzt JEE Tools (as opposed to modify and build them), the recommended way to install the software is via an Eclipse update site. As of release 1.1.0, there are two update site URLs, one for the edition used by the Municipiality of Vienna, Austria, the other a generic version. The URLs are</p>
<p><a href="http://azzyzt.manessinger.com/azzyzt_generic/" target="_blank">http://azzyzt.manessinger.com/azzyzt_generic/</a></p>
<p><a href="http://azzyzt.manessinger.com/azzyzt_magwien/" target="_blank">http://azzyzt.manessinger.com/azzyzt_magwien/</a></p>
<p>If you want to look into the source code, modify Azzyzt JEE Tools for your own use or if you even want to contribute, then you can fork the project from GitHub under the URL</p>
<p><a href="https://github.com/amanessinger/azzyzt_jee_tools" target="_blank">https://github.com/amanessinger/azzyzt_jee_tools</a></p>
<p>So far the project lacks reference documentation, though a tutorial under </p>
<p><a href="http://azzyzt.manessinger.com/doc/using_azzyzt.html" target="_blank">http://azzyzt.manessinger.com/doc/using_azzyzt.html</a></p>
<p>should give you a fairly good impression of what Azzyzt JEE Tools are about, how to get started and how to go on. The process of building/modifying the tools and of how to contribute to the code base currently lacks documentation.</p>
<p>All announcements of new versions will be published on</p>
<p><a href="http://www.azzyzt.org/" target="_blank">http://www.azzyzt.org</a></p>
<p>Discussion of the architecture, of interesting details of the implementation, and in general of things I&#8217;ve learned in the process, will happen on my programming blog</p>
<p><a href="http://programming.manessinger.com/" target="_blank">http://programming.manessinger.com/</a></p>
<p>If you want to be kept up-to-date, I suggest that you subscribe to the feeds of both sites, <a href="http://www.azzyzt.org/feeds/posts/default" target="_blank">azzyzt.org</a> and <a href="http://feeds.feedburner.com/manessinger/dBES" target="_blank">programming.manessinger.com</a>, in the feed reader of your choice.</p>
<p>The next post will give you an overview of how the code generated by Azzyzt JEE Tools differs from the <a href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/" target="_blank">Eclipse / GlassFish / Java EE 6 Tutorial</a>. Until then I suggest you have a look at the new tutorial <a href="http://azzyzt.manessinger.com/doc/using_azzyzt.html" target="_blank">Using Azzyzt JEE Tools</a>.</p>
<p>Azzyzt JEE Tools are copyright (c) 2011, Municipiality of Vienna, Austria, licensed under the EUPL, version 1.1 or subsequent versions.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/uvcKHUt8wpo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2011/05/22/11-welcome-to-azzyzt-jee-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2011/05/22/11-welcome-to-azzyzt-jee-tools/</feedburner:origLink></item>
		<item>
		<title>10 – That’s Why They Call It Stateless</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/u2_iUw6pH_w/</link>
		<comments>http://programming.manessinger.com/2010/08/15/10-thats-why-they-call-it-stateless/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 16:43:45 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Advice]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>
		<category><![CDATA[Multi-Threading]]></category>
		<category><![CDATA[Stateless Session Bean]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=558</guid>
		<description><![CDATA[Have you ever wondered how stateless an EJB3 Stateless Session Bean is? Well, I have, I wrote a test program and I got some interesting and &#8211; for me &#8211; surprising results, that I wanted to share. My original understanding (or let&#8217;s call it mis-understanding) was, that the JEE server has a pool of EJB <a href='http://programming.manessinger.com/2010/08/15/10-thats-why-they-call-it-stateless/' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2006/20061116_222950.JPG"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2006/20061116_222950.JPG" alt="" border="0" /></a> </p>
<p>Have you ever wondered how stateless an EJB3 <span class="term">Stateless Session Bean</span> is? Well, I have, I wrote a test program and I got some interesting and &#8211; for me &#8211; surprising results, that I wanted to share.</p>
<p>My original understanding (or let&#8217;s call it mis-understanding) was, that the JEE server has a pool of EJB instances for each bean class, that you get one of those beans injected for each <code>@EJB</code> annotation, and that all those injections happen immediately upon entrance into the container via a top-level call.</p>
<p>A call to a service bean via SOAP is such a top-level call. I expected, that the injections not only happen in the called bean, but also somehow happen along the whole call graph, meaning that not only EJB references in the top-level service bean would be satisfied via injection, but also in beans referenced by that bean and so on. </p>
<p>Finally I expected that if two beans reference the same type of bean, they would actually get the same instance. I really have never thought the whole thing through, I simply expected some diffuse sort of magic. </p>
<p>The idea was, that some <code>ServiceBean</code> would get a value, either via parameters or from elsewhere (actually I thought of HTTP headers), store that information in some <code>StorageBean</code>,  and then call a <code>WorkerBean</code>. The <code>WorkerBean</code> or some other code down the call graph would then retrieve that information from the <code>StorageBean</code>. In order for this to work, the <code>StorageBean</code> injected into the <code>ServiceBean</code> would have to be the same instance as the <code>StorageBean</code> injected into the <code>WorkerBean</code>, and the <code>StorageBean</code> would have to be exclusively allocated to that one thread for the whole duration of the top-level call, or else there would be a time interval between when the value gets being set and the time when it is read in the <code>WorkerBean</code>, leading to the usual multi-threading troubles.</p>
<p>I wanted a <code>StorageBean</code> to have some instance variables, wanted to fill them somewhere in the program, and wanted to read them elsewhere, without having to pass them around as parameters. In other words, I wanted a Stateless Session Bean to have <strong>some state</strong>, and I hoped that the container would guarantee consistency of this state for the time of one top-level call.</p>
<p>I&#8217;m pretty sure this is still not clear, so let&#8217;s look at some code. Here is a <span class="term">Singleton</span> that generates random numbers:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.test.stateless.backing</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Singleton</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.LocalBean</span><span style="color: #339933;">;</span>
&nbsp;
@LocalBean
@Singleton
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RandomGen <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Random</span> r<span style="color: #339933;">;</span>
&nbsp;
    @PostConstruct
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> nextInt<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;">return</span> r.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<p>The <code>StorageBean</code> could be something like</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.test.stateless.backing</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.LocalBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Stateless</span><span style="color: #339933;">;</span>
&nbsp;
@LocalBean
@Stateless
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StorageBean <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setValue<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getValue<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;">return</span> value<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A first shot at the <code>ServiceBean</code> could be</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.test.stateless.service</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.EJB</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Stateless</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jws.WebService</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.test.stateless.backing.RandomGen</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.test.stateless.backing.StorageBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.test.stateless.backing.WorkerBean</span><span style="color: #339933;">;</span>
&nbsp;
@Stateless
@WebService
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ServiceBean <span style="color: #009900;">&#123;</span>
&nbsp;
    @EJB StorageBean s<span style="color: #339933;">;</span>
    @EJB WorkerBean  w<span style="color: #339933;">;</span>
    @EJB RandomGen   rand<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> test1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> rand.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        s.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> w.<span style="color: #006633;">verify1</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and here is finally the worker:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.test.stateless.backing</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.EJB</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.LocalBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Stateless</span><span style="color: #339933;">;</span>
&nbsp;
@LocalBean
@Stateless
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WorkerBean <span style="color: #009900;">&#123;</span>
&nbsp;
    @EJB StorageBean s<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> verify1<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> value <span style="color: #339933;">=</span> s.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> i<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>isCorrect<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: expected %d, got %d&quot;</span>, value, i<span style="color: #009900;">&#41;</span><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> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Thus the <code>ServiceBean</code> retrieves a random value, uses it to set the value of the <code>StorageBean</code>, and then passes the value into a <code>verify()</code> method of the worker. The worker retrieves the value from the <code>StorageBean</code>, compares it with its parameter, and returns <code>true</code> if they are the same value.</p>
<p>Try it for yourself: call the <code>ServiceBean</code> from the web service tester in the <span class="gui">GlassFish Administration Console</span> and it will just work. It&#8217;s EJB3 and EJBs are just POJOs after all, right?</p>
<p>Wrong. Sure, it does work, but now try to call the test method from a load testing application like Apache Jakarta JMeter. Try a thread group with 15 threads, a ramp-up period of one second, and 50 iterations. This makes for a total of 750 calls with a high degree of parallelity. Now look at the server log and you will see lines like</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">...
<span style="color: #006633;">SEVERE</span><span style="color: #339933;">:</span> <span style="color: #003399;">Error</span><span style="color: #339933;">:</span> expected <span style="color: #cc66cc;">781730157</span>, got <span style="color: #339933;">-</span><span style="color: #cc66cc;">1784951881</span>
SEVERE<span style="color: #339933;">:</span> <span style="color: #003399;">Error</span><span style="color: #339933;">:</span> expected <span style="color: #cc66cc;">781730157</span>, got <span style="color: #339933;">-</span><span style="color: #cc66cc;">1093939097</span>
SEVERE<span style="color: #339933;">:</span> <span style="color: #003399;">Error</span><span style="color: #339933;">:</span> expected <span style="color: #339933;">-</span><span style="color: #cc66cc;">1093939097</span>, got <span style="color: #cc66cc;">540930629</span>
SEVERE<span style="color: #339933;">:</span> <span style="color: #003399;">Error</span><span style="color: #339933;">:</span> expected <span style="color: #339933;">-</span><span style="color: #cc66cc;">1093939097</span>, got <span style="color: #cc66cc;">1481982330</span>
...</pre></td></tr></table></div>

<p>Funny, huh? And look at the numbers: this is a typical effect in a program that is not thread-safe. Consecutive calls get mixed up.</p>
<p>My next idea was a variant:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> test2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> rand.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        s.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> w.<span style="color: #006633;">verify2</span><span style="color: #009900;">&#40;</span>i, s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> verify2<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i, StorageBean sParam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> value <span style="color: #339933;">=</span> sParam.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> i<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>isCorrect<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: expected %d, got %d&quot;</span>, value, i<span style="color: #009900;">&#41;</span><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> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This means that I don&#8217;t let the <code>StorageBean</code> be injected into the worker, instead I pass it down as a parameter. Funnily enough, this did not work either. Under load it showed the same effect. Only when I finally passed the value in something that was really only a POJO, it did work:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.test.stateless.backing</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StorageNonBean <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setValue<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getValue<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;">return</span> value<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> test3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> rand.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        StorageNonBean snb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StorageNonBean<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        snb.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> w.<span style="color: #006633;">verify3</span><span style="color: #009900;">&#40;</span>i, snb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> verify3<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i, StorageNonBean snbParam<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> value <span style="color: #339933;">=</span> snbParam.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> isCorrect <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> i<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>isCorrect<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error: expected %d, got %d&quot;</span>, value, i<span style="color: #009900;">&#41;</span><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> isCorrect<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Of course the latter is trivial, but the consequences of this little test are clear:</p>
<p>Stateless Session Beans are really meant to be stateless. In fact the EJB 3.0 final specification says in section 4.5 that:<br />
<blockquote><em>Because all instances of a stateless session bean are equivalent, the container can choose to delegate a client-invoked method to any available instance. This means, for example, that the container may delegate the requests from the same client within the same transaction to different instances, and that the container may interleave requests from multiple transactions to the same instance.</em></p></blockquote>
<p>The only thing that the container guarantees, is that one bean will be exclusively allocated to a transaction (and therefore a thread) for the time of the invocation of one of <strong>its own methods</strong>. This does not extend to other EJBs that it calls. There is no guarantee that we call the same instance of <code>StorageBean</code>, if we call <code>storage.setValue()</code> and <code>storage.getValue()</code> even consecutively from the same <code>ServiceBean</code>, one call immediately after the other, and even if it were the same instance, there is no guarantee, that the storage has not been modified by another instance of the service bean.</p>
<p>Why did I ever get the idea that this construct could work? Well, probably it&#8217;s the fact, that the injection of a persistence context always gives you access to the same context (or at least the same data). I don&#8217;t know, but in any case I found it important to clarify things, because I have the impression that my mis-understanding is not completely uncommon, and when you fall into that pit, you may not recognize it until your system is under heavy load.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/u2_iUw6pH_w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/08/15/10-thats-why-they-call-it-stateless/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/08/15/10-thats-why-they-call-it-stateless/</feedburner:origLink></item>
		<item>
		<title>9 – Erratum: How I Shot Myself</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/Yv6waDtYBoE/</link>
		<comments>http://programming.manessinger.com/2010/08/13/9-%e2%80%93-erratum-how-i-shot-myself/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 16:16:57 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Erratum]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=540</guid>
		<description><![CDATA[One more error: In a comment to my Eclipse / GlassFish / Java EE 6 tutorial, FMora said: One detail &#8211; if you annotate a constraint with @NotNull and then insert a null value via SoapUI, one gets a NPE instead of a constraint violation. Oh dear, that&#8217;s so true and it is a typical <a href='http://programming.manessinger.com/2010/08/13/9-%e2%80%93-erratum-how-i-shot-myself/' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2010/20100301_165625_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2010/20100301_165625_ps.jpg" alt="" border="0" /></a> </p>
<p>One more error: In a comment to my <a target="_blank" href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/">Eclipse / GlassFish / Java EE 6 tutorial</a>, FMora said:</p>
<blockquote style="width: 300px"><p><em>One detail &#8211; if you annotate a constraint with @NotNull and then insert a null value via SoapUI, one gets a NPE instead of a constraint violation.</em></p></blockquote>
<p>Oh dear, that&#8217;s so true and it is a typical case of untested code. Have you ever seen untested code that did not break? I haven&#8217;t <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The problem was in the ValidationInterceptor in that line, where I took the invalid value and called &#8220;toString()&#8221; on it.</p>
<p>The tutorial is already updated, and from now on the tutorial begins with a version number. The current version is version 1.2, last updated August 13, 2010 – 17:06. The <a href="http://manessinger.com/data/playground.zip">ZIP file with the sources</a> was updated as well.</p>
<p>For your convenience, here is the updated <code>ValidationInterceptor</code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.manessinger.cookbook.util</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Set</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.interceptor.AroundInvoke</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.interceptor.Interceptor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.interceptor.InvocationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.validation.ConstraintViolation</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.validation.Validation</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.validation.Validator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.validation.ValidatorFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.validation.groups.Default</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.cookbook.exception.ConstraintProperty</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.cookbook.exception.ValidationException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.manessinger.cookbook.exception.ViolationDetail</span><span style="color: #339933;">;</span>
&nbsp;
@Interceptor
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ValidationInterceptor <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// the factory is expensive but thread-safe</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> ValidatorFactory factory <span style="color: #339933;">=</span> Validation.<span style="color: #006633;">buildDefaultValidatorFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    @AroundInvoke
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> intercept<span style="color: #009900;">&#40;</span>InvocationContext ctx<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        Validator v <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getValidator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// for all parameters</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> p <span style="color: #339933;">:</span> ctx.<span style="color: #006633;">getParameters</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: #666666; font-style: italic;">// validate parameter</span>
            Set<span style="color: #339933;">&lt;</span>ConstraintViolation<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;&gt;</span> violations <span style="color: #339933;">=</span> v.<span style="color: #006633;">validate</span><span style="color: #009900;">&#40;</span>p, <span style="color: #000000; font-weight: bold;">Default</span>.<span style="color: #000000; font-weight: bold;">class</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><span style="color: #339933;">!</span>violations.<span style="color: #006633;">isEmpty</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: #666666; font-style: italic;">// validation failed, gather details and throw an exception</span>
                List<span style="color: #339933;">&lt;</span>ViolationDetail<span style="color: #339933;">&gt;</span> details <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>ViolationDetail<span style="color: #339933;">&gt;</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;">for</span> <span style="color: #009900;">&#40;</span>ConstraintViolation<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span> violation <span style="color: #339933;">:</span> violations<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    ViolationDetail d <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ViolationDetail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// path to violated constraint</span>
                    d.<span style="color: #006633;">setAttributedItem</span><span style="color: #009900;">&#40;</span>violation.<span style="color: #006633;">getPropertyPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<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: #666666; font-style: italic;">// what type of constraint, e.g. &quot;Min&quot; or &quot;Pattern&quot;</span>
                    d.<span style="color: #006633;">setConstraintName</span><span style="color: #009900;">&#40;</span>
                        violation.<span style="color: #006633;">getConstraintDescriptor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                            .<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">annotationType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSimpleName</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: #666666; font-style: italic;">// construct list of constraint properties</span>
                    Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> violationAttributes 
                        <span style="color: #339933;">=</span> violation.<span style="color: #006633;">getConstraintDescriptor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    List<span style="color: #339933;">&lt;</span>ConstraintProperty<span style="color: #339933;">&gt;</span> properties <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>ConstraintProperty<span style="color: #339933;">&gt;</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> propertyName <span style="color: #339933;">:</span> violationAttributes.<span style="color: #006633;">keySet</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;">if</span> <span style="color: #009900;">&#40;</span>propertyName.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^(message|payload|groups|flags)$&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #666666; font-style: italic;">// skip unwanted property</span>
                            <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                        ConstraintProperty a <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ConstraintProperty<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        a.<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span>propertyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        a.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span>violationAttributes.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>propertyName<span style="color: #009900;">&#41;</span>.<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>
                        properties.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                    d.<span style="color: #006633;">setConstraintProperties</span><span style="color: #009900;">&#40;</span>properties<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// the value that violated the constraint</span>
                    <span style="color: #003399;">Object</span> invalidValue <span style="color: #339933;">=</span> violation.<span style="color: #006633;">getInvalidValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    d.<span style="color: #006633;">setInvalidItemValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>invalidValue <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> 
                                           invalidValue.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    details.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ValidationException<span style="color: #009900;">&#40;</span>details<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: #000000; font-weight: bold;">return</span> ctx.<span style="color: #006633;">proceed</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/Yv6waDtYBoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/08/13/9-%e2%80%93-erratum-how-i-shot-myself/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/08/13/9-%e2%80%93-erratum-how-i-shot-myself/</feedburner:origLink></item>
		<item>
		<title>8 – Erratum: Accessing HTTP headers from an interceptor</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/WnhgW4S4koA/</link>
		<comments>http://programming.manessinger.com/2010/07/26/8-erratum-accessing-http-headers-from-an-interceptor/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 22:37:53 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Erratum]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Interceptors]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=514</guid>
		<description><![CDATA[In my Eclipse / GlassFish / Java EE 6 Cookbook I have mentioned how to access HTTP headers from an interceptor. Unfortunately the code contained an error and here is an update.]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2010/20100302_075845_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2010/20100302_075845_ps.jpg" alt="" border="0" /></a> If you have followed my <a target="_blank" href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/">Eclipse / GlassFish / Java EE 6 Cookbook</a>, you have seen one single section, where the sample code was only sketched and never compiled. This was the &#8220;hypothetical security interceptor&#8221;. And of course when one writes down code from memory, it is invariably buggy.</p>
<p>Last week I wanted to use the code as base of the security interceptor of a system that we just develop, naturally it crashed, and it did so in a not exactly obvious way, thus I thought I should give you an update.</p>
<p>The security interceptor as shown in the cookbook is not really what I would use anyway, and I intend to write a follow-up tutorial explaining some of the things that I learned during our current project. There you will find a more detailed discussion of access control, and along with it, a more useful <span class="tt">SecurityInterceptor</span>.</p>
<p>Until that point, let me show you what the problem with the original code was. Here it is:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">@Interceptor
@Stateless
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SecurityInterceptor <span style="color: #009900;">&#123;</span>
&nbsp;
    @EJB SecurityEao sec<span style="color: #339933;">;</span>
    @EJB SecurityGuard guard<span style="color: #339933;">;</span>
&nbsp;
    @AroundInvoke
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> intercept<span style="color: #009900;">&#40;</span>InvocationContext ctx<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> contextData <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">getContextData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> headers <span style="color: #339933;">=</span> contextData.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.xml.ws.http.request.headers&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> secKey <span style="color: #339933;">=</span> headers.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X-Portal-SecKey&quot;</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>secKey <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</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> SecurityNoKeyException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        SecInfo secInfo <span style="color: #339933;">=</span> eao.<span style="color: #006633;">secInfoBySecKey</span><span style="color: #009900;">&#40;</span>secKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Method</span> invokedMethod <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">getMethod</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;">if</span> <span style="color: #009900;">&#40;</span>guard.<span style="color: #006633;">isInvocationForbidden</span><span style="color: #009900;">&#40;</span>invokedMethod, secInfo<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> SecurityViolationException<span style="color: #009900;">&#40;</span><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> ctx.<span style="color: #006633;">proceed</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<p>The wrong assumption is that <code>contextData.get("javax.xml.ws.http.request.headers");</code> yields a <code>Map&lt;String, String></code>. That&#8217;s wrong, but it compiles. The method really yields a <code>Map&lt;String, List&lt;String>></code>, because you can have more than one header of a certain name. Thus the correct code is something like</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">@Interceptor
@Stateless
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SecurityInterceptor <span style="color: #009900;">&#123;</span>
&nbsp;
    @EJB SecurityEao sec<span style="color: #339933;">;</span>
    @EJB SecurityGuard guard<span style="color: #339933;">;</span>
&nbsp;
    @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
    @AroundInvoke
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> intercept<span style="color: #009900;">&#40;</span>InvocationContext ctx<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> contextData <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">getContextData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span> headers 
             <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#41;</span> contextData.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.xml.ws.http.request.headers&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> secCredentials <span style="color: #339933;">=</span> headers.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X-Portal-Credentials&quot;</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>secCredentials <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> secCredentials.<span style="color: #006633;">isEmpty</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> SecurityNoCredentialsException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        SecInfo secInfo <span style="color: #339933;">=</span> sec.<span style="color: #006633;">secInfoBySecCredentials</span><span style="color: #009900;">&#40;</span>secCredentials<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Method</span> invokedMethod <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">getMethod</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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>guard.<span style="color: #006633;">isInvocationAllowed</span><span style="color: #009900;">&#40;</span>invokedMethod, secInfo<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> SecurityViolationException<span style="color: #009900;">&#40;</span><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> ctx.<span style="color: #006633;">proceed</span><span style="color: #009900;">&#40;</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></td></tr></table></div>

<p>I have already updated the tutorial.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/WnhgW4S4koA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/07/26/8-erratum-accessing-http-headers-from-an-interceptor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/07/26/8-erratum-accessing-http-headers-from-an-interceptor/</feedburner:origLink></item>
		<item>
		<title>7 – Eclipse 3.6 “Helios” and GlassFish 3.01</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/aEpUI-U9Rqk/</link>
		<comments>http://programming.manessinger.com/2010/07/09/7-eclipse-3-6-helios-and-glassfish-3-01/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 18:42:23 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Advice]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=494</guid>
		<description><![CDATA[Since I published my Eclipse / GlassFish / Java EE 6 tutorial, Oracle has published a bugfix release to GlassFish v3, their reference implementation of Java EE 6, and Eclipse 3.6, code name "Helios", has arrived. The last two days I had a deeper look into the combination, and in this post I explain what has changed.]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2010/20100523_200425_2_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2010/20100523_200425_2_ps.jpg" alt="" border="0" /></a> It&#8217;s only a few days since I&#8217;ve posted my <a target="_blank" href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/">Eclipse / GlassFish / Java EE 6 Tutorial</a>, but due to the fact that it took me so long to write it, the toolset that I used is already outdated. </p>
<p>In the meantime Oracle has published a bugfix release to GlassFish v3, their reference implementation of Java EE 6 (and still the only implementation available), and of course Eclipse 3.6, code name &#8220;Helios&#8221;, has arrived. The last two days I had a deeper look into the combination, and I can tell that it works <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4 class="section">Overall Impressions</h4>
<p>Some bugs have been fixed, for example it is no problem now to restart the server, and the bug with libraries having been added to an EAR&#8217;s <code>lib</code> directory being &#8220;forgotten&#8221;, is gone as well.</p>
<p>At the moment I see only one major annoyance, and that is that re-publishing an application to the server tends to fail. The workaround is, to not manually re-publish, but instead use <span class="gui">Add and Remove</span> from the server&#8217;s context menu, <span class="gui">Remove</span> the application, <span class="gui">Finish</span>, followed by <span class="gui">Add and Remove / Add / Finish</span>. The bug has been reported on <a target="_blank" href="http://forums.java.net/jive/thread.jspa?messageID=476668&#038;tstart=0">Java.net</a>, but so far the guys responsible for the GlassFish plugin claim, that it is a bug in Eclipse. I fully expect some ping pong between the two development teams until the bug gets fixed <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>At work, under Linux, I have played once through my whole tutorial and found no showstopper. Thus, when I begin to teach Java EE 6 from next week, this is the combination that I&#8217;ll use. </p>
<h4 class="section">Software versions and installation</h4>
<p>I have used the following software versions:</p>
<ul>
<li><a target="_blank" href="http://java.sun.com/javase/downloads/">JDK 6 Update 21 (JDK!!!)</a>: There are 32 bit and 64 bit versions, under Linux I have used the 32 bit version, on my laptop, where I&#8217;m just writing this, I run the 64 bit version. No problem with either.</li>
<li><a target="_blank" href="http://java.sun.com/javaee/downloads/">Java EE 6 SDK</a>: There is only one version, but the SDK is mostly JARs anyway. This time there is no &#8220;GlassFish Tools Bundle for Eclipse&#8221;, so be sure to download the right package. On the download page is a matrix that shows, which packages include what version. You will want the full Java EE 6 SDK, not the &#8220;Web Profile&#8221;.</li>
<li><a target="_blank" href="http://www.eclipse.org/downloads/">Eclipse IDE for Java EE Developers</a> is available for 32 bit and 64 bit as well. Under Linux I have used 32 bits, under Windows 7 the 64 bit version.</li>
<li>The <a target="_blank" href="http://blogs.sun.com/theaquarium/entry/eclipse_3_6_helios_glassfish">Aquarium</a> blog lists a temporary Eclipse update site for the GlassFish plugin, that&#8217;s how I have installed it. In the long run, the GlassFish plugin will be merged into the Oracle Enterprise Pack for Eclipse, the plugin that covers Oracle&#8217;s commercial application servers.</li>
</ul>
<p>First thing to install is the JDK. Under Windows I have installed it to the default location. The JDK installs a JRE (runtime only) as well.</p>
<p>When you install the Java EE 6 SDK, you are asked to choose the JDK to be used. Unfortunately the stupid <span class="term">updatetool</span> installation still has not been fixed. The installer asks you if it should be installed and you really ought to do that. Included with the installer is only a bootstrap version. Unfortunately (and unlike the full version) the bootstrap version can&#8217;t easily cope with authenticating proxies. At work under Linux, I had to supply username/password as part of the <code>http_proxy</code> environment variable, and because our proxy needs a Windows domain name in front of the user name, with a backslash as separator, I was in quoting hell <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What I did after installing to <code>~/Applications/GlassFish_v3.01</code> was this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sh" style="font-family:monospace;">cd ~/Applications/GlassFish_v3.01/bin
sh
http_proxy='http://DOMAIN\\\\USER:PASSWORD@PROXYSERVER:PROXYPORT' ./updatetool
http_proxy='http://DOMAIN\\\\USER:PASSWORD@PROXYSERVER:PROXYPORT' ./updatetool
^D</pre></td></tr></table></div>

<p>Starting <code>sh</code> disables the commandline history. Passwords don&#8217;t belong into histories <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The first call to <code>updatetool</code> actually calls the bootstrap tool, the second call is to the real thing, a GUI tool, and there I&#8217;ve installed the two updates that are currently available, and then I have disabled automatic updates.</p>
<p>The four backslashes are necessary, because the bootstrap tool is a shell script, and the value is obviously evaluated two times. Whatever.</p>
<p>This was only a problem under Linux, because our fabulous proxy understands NTLM, and the Windows machine at work where I tried it, automatically authenticated via NTLM.</p>
<p>After the Java EE 6 SDK is installed (and with it GlassFish v3.01), don&#8217;t start the server. In your develpoment environment you will want to start it from Eclipse.</p>
<p>Next thing to install is Eclipse Helios. Simply unpack the ZIP where you want it. Start Eclipse, go to the <span class="gui">Workbench</span>, use <span class="gui">Window > Preferences > Install/Update > Available Software Sites > Add</span> to add the location <span class="tt">http://download.java.net/glassfish/eclipse/helios</span>, for instance under the name <span class="tt">GlassFish Plugin</span>. </p>
<p>Close the <span class="gui">Preferences</span> dialog and use <span class="gui">Help > Install New Software</span>. Make sure that <span class="gui">Group items by category</span> is not checked, at the top under <span class="gui">Work with</span> select the site you&#8217;ve just added, and now you should see three entries in the list, <span class="gui">Oracle GlassFish Server Tools</span> and the documentations for Java EE 5 and Java EE 6. Install all three. After the installation, Eclipse will prompt you to restart the application. Do so, and after marveling at the changed intro screen, go to the <span class="gui">Workbench</span> again.</p>
<p>Now we need to make sure, that we use the right JDK. Use <span class="gui">Window > Preferences > Java > Installed JREs</span> and check, that the path really points to the JDK that you&#8217;ve just installed, and not to the JRE, that was installed along with it.</p>
<p>Finally you can go to the <span class="gui">Servers</span> view and from its context menu add a server. As server type choose <span class="gui">GlassFish Server Open Source Edition 3 (Java EE 6)</span>. Supply the directory, where you&#8217;ve installed the server (actually the <code>glassfish</code> directory within the directory, where you&#8217;ve instaleld the Java EE 6 SDK).</p>
<p>From then on, you can start the server via Eclipse and <a href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/">follow the tutorial</a>. </p>
<p>Within the next days I will adapt the tutorial to the new versions and remove the discussion of bugs that have been fixed, but I will keep the old version for those people, who can&#8217;t update yet.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/aEpUI-U9Rqk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/07/09/7-eclipse-3-6-helios-and-glassfish-3-01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/07/09/7-eclipse-3-6-helios-and-glassfish-3-01/</feedburner:origLink></item>
		<item>
		<title>6 – An Eclipse / GlassFish / Java EE 6 Cookbook</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/oL82fSiddaY/</link>
		<comments>http://programming.manessinger.com/2010/04/06/6-an-eclipse-glassfish-java-ee-6-cookbook/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 13:27:59 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Advice]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Atom]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Corba/IIOP]]></category>
		<category><![CDATA[Derby]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[In-Server Testing]]></category>
		<category><![CDATA[Interceptors]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>
		<category><![CDATA[JNDI]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Out-of-Server Testing]]></category>
		<category><![CDATA[Persistence]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[ROME]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Service]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[SoapUI]]></category>
		<category><![CDATA[Syndicated Feed]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=189</guid>
		<description><![CDATA[This is a tutorial about using Eclipse and the GlassFish v3 Java application server to implement Java EE 6 applications. I will show how to use different Eclipse project types for different purposes, will show how to do manual tests and how to implement automatic unit tests. We will not create a complete application, but more a vertical slice through an application. The idea is to just touch all relevant areas, not to finish a project.

The tutorial assumes the existence of a relational database, and it concentrates on the Java application used as a backend. Using JSF or another server-based GUI framework is definitely out of scope.]]></description>
				<content:encoded><![CDATA[<p>Version 1.4, last updated May 23, 2011 &#8211; 11:10</p>
<div class="caution">The content of this tutorial is still relevant, but you may also consider my new open source <a target="_blank" href="http://www.azzyzt.org/">Azzyzt JEE Tools</a>, a set of Eclipse plugins that greatly simplify the process of creating a Java Enterprise application using the patterns outlined in this tutorial. See the <a target="_blank" href="http://www.azzyzt.org/">Azzyzt JEE Tools home page</a> and especially the tutorial &#8220;<a target="_blank" href="http://azzyzt.manessinger.com/doc/using_azzyzt.html">Using Azzyzt JEE Tools</a>&#8220;.</div>
<p>In &#8220;<a target="_blank" href="http://programming.manessinger.com/2010/03/30/4-equipment/">4 – Equipment</a>&#8221; I have committed myself to using Eclipse and the Java Enterprise Edition as my tools, while in  &#8220;<a target="_blank" href="http://programming.manessinger.com/2010/04/04/5-patterns-and-languages/">5 – Patterns And Languages</a>&#8221; I&#8217;ve declared my high-level goals for implementing a next step of design pattern-based tools. Now, for a deeper understanding of design patterns, you first have to use them. This post in the form of a tutorial shows some very basic project setups using Eclipse and GlassFish.</p>
<p><a target="_blank" rel="none" href="http://manessinger.com/display.php/1024x1024/2010/20100404_080937_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2010/20100404_080937_ps.jpg" alt="" border="0" /></a> I am no expert in this field, some important things may be missing, so just take the following as a set of things that work for me. </p>
<p>As I am not immune to learning, and as I am going the use these things a lot, it is inevitable that my understanding of certain aspects will change. I suppose that means, I will have to make changes to this post whenever it happens. If I ever do so, I will post a short notice.</p>
<h5 class="subsection">Applicability</h5>
<p>This is a tutorial about using Eclipse and the GlassFish v3 Java application server to implement Java EE 6 applications. I will show how to use different Eclipse project types for different purposes, will show how to do manual tests and how to implement automatic unit tests. We will not create a complete application, but more a vertical slice through an application. The idea is to just touch all relevant areas, not to finish a project.</p>
<p>The tutorial assumes the existence of a relational database, and it concentrates on the Java application used as a backend. Using JSF or another server-based GUI framework is definitely out of scope.</p>
<h5 class="subsection">Where&#8217;s the beef?</h5>
<p>At an equivalent of approximately 80 printed pages, the full tutorial is much too long for a regular blog post. It would break the size limit of feeds syndicated via Google&#8217;s Feedburner server. In fact it did. I had no choice but to move the text to a separate page. On the other hand, that&#8217;s quite OK, I want my tutorials (this won&#8217;t be the last) to be available as pages from a tutorial menu anyway.</p>
<p>Unfortunately I noticed the feed problems only after I had already published the URL of this post a few times. Thus, if you arrive here from a link, please go on to the actual page containing the full <a href="http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/">Eclipse / GlassFish / Java EE 6 tutorial</a>. Sorry for the inconvenience.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/oL82fSiddaY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/04/06/6-an-eclipse-glassfish-java-ee-6-cookbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/04/06/6-an-eclipse-glassfish-java-ee-6-cookbook/</feedburner:origLink></item>
		<item>
		<title>5 – Patterns And Languages</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/9nbc2k0gq3g/</link>
		<comments>http://programming.manessinger.com/2010/04/04/5-patterns-and-languages/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 22:30:42 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Code Generators]]></category>
		<category><![CDATA[Code Reuse]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Model Driven Design]]></category>
		<category><![CDATA[Pattern Languages]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=146</guid>
		<description><![CDATA[The Pattern Movement in Software Engineering has become very popular and has produced many books, some of them arguably extremely good, but apart from automatic refactoring in modern IDEs, the number of supporting tools is surprisingly low. This post shows what is missing and how code generation is really the logical way to implement pattern support.]]></description>
				<content:encoded><![CDATA[<p>The Pattern Movement in Software Engineering has become very popular and has produced many books, some of them arguably extremely good, but apart from automatic refactoring in modern IDEs, the number of supporting tools is surprisingly low.</p>
<h4 class="section">What Is A Pattern Anyway</h4>
<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2007/20070125_215547_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2007/20070125_215547_ps.jpg" alt="" border="0" /></a> You can get a good overview about Design Patterns at the <a target="_blank" href="http://c2.com/cgi/wiki?DesignPatterns">Portland Pattern Repository</a>. For the purpose of this article we just take the classic definition from the Gang Of Four book:</p>
<div style="margin: 0pt 15px 10pt 15px" ><em>A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples. The solution is a general arrangement of objects and classes that solve the problem. The solution is customized and implemented to solve the problem in a particular context.</em></div>
<p>The crucial bit is the last sentence: Design patterns need to be implemented specifically for each particular problem. The classes in an object-oriented design pattern are no classes at all. They are archetypes, and for the particular situation real classes have to be crafted after those archetypes.</p>
<p><iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=99AADD&#038;t=thedailphotof-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0201633612" style="margin: 0pt 10px 0pt 0px; float: left; width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> To put it in other words, a design pattern is an archetypical solution to an archetypical problem, and that&#8217;s also the reason why you can&#8217;t press patterns into libraries. If you compare two instances of the pattern, i.e. two cases where the pattern has been used to solve the problem, you&#8217;ll find almost no code that could be factored out. The pattern is not code, the pattern is a way the code is structured. Lexically two instances of a pattern have nothing in common, everything is only similar, nothing is the same.</p>
<p>In some cases it is even possible to put a pattern into a library, but when you begin to do so, you quickly find out that the result is not useful. Too much varies, the result are endless parameter lists or endlessly overloaded variations of the same methods. Those libraries are hard to implement and they don&#8217;t feel natural. </p>
<p>Generics (templates in C++) are a step in the right direction, but although they make creating archetypical libraries easier, those libraries are not necessarily easy to understand and use, much less to implement.</p>
<h4 class="section">The Most Simple Patterns</h4>
<p>Design patterns don&#8217;t come only at the level of class interaction in object-oriented systems. Just look at programming languages. In the beginning there was only assembly language. We basically wrote machine instructions, but after a while it turned out, that we did similar things over and again. </p>
<p>One of those things was to build loops of code. People did completely different things in the bodies of their loops, but there were only a few patterns for how the loop was entered, exited, and how often it was executed. With the advent of higher programming languages, those patterns were cast in basic language constructs such as &#8220;WHILE-DO&#8221;, &#8220;DO-UNTIL&#8221;, &#8220;FOR&#8221; or &#8220;FOREACH&#8221;, and these language constructs are still with us.</p>
<p>Assembly language did not have those high-level loops, but it had a conditional branch. Loops had to be implemented with conditional branches. The direct equivalent to that is the combination of the &#8220;IF&#8221; and &#8220;GOTO&#8221; statements in programming languages, and of course you can use those to implement all your loops. It&#8217;s only more verbose, the intent is less clear, and that is, because you don&#8217;t express your intent by naming it. Patterns are much about naming.</p>
<h4 class="section">Pattern Languages</h4>
<p>Interestingly enough, an &#8220;IF&#8221; statement is also a pattern. Just look at the infinite number of conditions. This brings us to another important fact, the fact that patterns are not all born equal. They come in hierarchies. There are base patterns and composite patterns. Just like with &#8220;IF-GOTO&#8221;, you can use patterns to build other, more complex patterns.</p>
<p><iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=99AADD&#038;t=thedailphotof-20&#038;o=1&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=10FE9736YVPPT7A0FBG2&#038;asins=0195019199" style="margin: 0pt 0px 0pt 10px; float: right; width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> Now, if you look at where the pattern movement came from, being initiated by the architect Christopher Alexander, and if you read his books, you see that he clearly understood the hierarchical nature of design patterns. That&#8217;s why he called it a <a target="_blank" href="http://www.patternlanguage.com/">Pattern Language</a>.</p>
<p>Well, I&#8217;ve never tried to build a house, and if I were to build one, I&#8217;d probably not apply all of his patterns. Many of them I agree with, some I don&#8217;t, and for most there are alternatives that he does not cover. But that again coincides nicely with the notion of languages.</p>
<p>My native language is German, I regularly use English, have some low level, basic and spotty understanding of some of the languages originating in Latin, but that&#8217;s it. No idea of Chinese, no idea of any African language, no idea of anything else. And still, all those languages, that I don&#8217;t have a clue of, can express exactly the same things that German or English can. They use only different patterns to solve the same problems.</p>
<p>So I guess we can agree that it is possible to build different houses, houses that don&#8217;t fit into Christopher Alexander&#8217;s language, and we may still be able to live in them and stay sane.</p>
<p>For the adoption of Alexander&#8217;s method, this may really have been detrimental. It is much too obvious that, although it makes sense as a system, you may not be able to use it and build your dream. It would be Alexander&#8217;s dream instead, and when it comes to our dreams, we really dislike any intrusion.</p>
<p>This may explain Alexander&#8217;s limited success (and I don&#8217;t want to belittle him, he is really one of my heroes, even if he has not taken over the world), but it would not be in our way building programs, would it? After all, houses are for individuals, and individuals care for their individuality, but <a target="_blank" href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> is just CRUD, ain&#8217;t it?</p>
<p>Maybe not. People seem to have a tendency to willingly and knowingly reinvent the wheel. Look at me: I could be satisfied using the tools I have, using them to create the things I&#8217;m paid for, and otherwise have a life. Or else just join the development of the Eclipse Modeling tools. In a way there&#8217;s so much already out there, I can&#8217;t have much hope to make a valuable contribution. And still I do what I do, knowing that I&#8217;m bound to reinvent, willingly accepting it. And why? Because it&#8217;s fun <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I don&#8217;t know if this explains anything, but fact is, that the Design Pattern movement in computer science has not produced anything that even remotely comes close to Alexander&#8217;s hierarchical completeness. With Alexander&#8217;s language you can build a house, a street, a village, a town, a region, and in the other direction you can go down to details like the actual building materials.</p>
<p>You can&#8217;t do that with design patterns in computer programming. The high-level patterns are all missing. The discipline has evolved to the point where it has become possible to talk to each other using design patterns, but it&#8217;s only at that certain level of detail where we talk about basic object interaction.</p>
<h4 class="section">The Necessary Next Step</h4>
<p>Looking into some very simple patterns of repeated assembly code, we found that these patterns became the loop constructs of modern programming languages. Those loop patterns describe arrangements of assembly instructions, but the important thing to note here is, that today nobody arranges those instructions themselves. We use compilers for that. This is very different from how we work with Gang-Of-Four patterns, because they have to be instantiated by hand.</p>
<p>A compiler can do what it does, because it has a complete model of the program. All variables, that the built-in patterns like loop constructs refer to, are also defined in the same model. The whole semantic is defined in terms of the language and its patterns, and where this is not the case, the semantics are defined by standardized libraries. So, actually what this boils down to is, that a programming language allows us to express the desired semantics by constructing a model. The compiler than applies its patterns to this model and this way constructs either code or calls into supporting libraries.</p>
<p>That&#8217;s exactly what code generators do. They take a model and translate it into code of a different, simpler language, and where it makes sense, they generate not code but calls into external libraries. In this context, libraries have two purposes: </p>
<ol>
<li>they avoid code duplication</li>
<li>they allow us to express semantics that can&#8217;t be expressed in the language&#8217;s patterns</li>
</ol>
<p>#1 is nice to have, but #2 is really important, because it means that we can generate code, even when our patterns are not a complete, self-sufficiant system. What we can&#8217;t express in our language, we simply assume implemented in libraries.</p>
<p>This is the way to go. We have to build higher-order languages, languages that implement recurring patterns just the way as today&#8217;s programming languages implement assembly loop patterns. Once we have such languages, we can translate them automatically into code. Just like with conventional programming languages, those things will be the more powerful, the more self-sufficient they are, but that does not mean that small and incomplete steps can&#8217;t be incredibly useful in their own right.</p>
<p>What I want to implement as my project are three things:</p>
<ol>
<li>an environment to specify models,</li>
<li>a set of patterns that, when applied to such a model, turns the model into an<br />
             application, and finally</li>
<li>a code generator, that makes this process automatic</li>
</ol>
<p>That&#8217;s it. Easy, huh?</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/9nbc2k0gq3g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/04/04/5-patterns-and-languages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/04/04/5-patterns-and-languages/</feedburner:origLink></item>
		<item>
		<title>4 – Equipment</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/lBxpspCcovE/</link>
		<comments>http://programming.manessinger.com/2010/03/30/4-equipment/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 00:13:48 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Advice]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GlassFish v3]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=138</guid>
		<description><![CDATA[My original plan was to work on Linux. The only problem is, that my private computers in Vienna and Carinthia, as well as the laptop run Windows 7. This is mostly because two crucial pieces of my software don&#8217;t run on Linux: my image database IMatch and of course Photoshop. Normally when I need Linux <a href='http://programming.manessinger.com/2010/03/30/4-equipment/' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2009/20091016_153832_ps.jpg"><img style="margin: 0pt 15px 0pt 0px; float: left;" src="http://manessinger.com/images/0400x0400/2009/20091016_153832_ps.jpg" alt="" border="0" /></a> My original plan was to work on Linux. The only problem is, that my private computers in Vienna and Carinthia, as well as the laptop run Windows 7. This is mostly because two crucial pieces of my software don&#8217;t run on Linux: my image database IMatch and of course Photoshop. </p>
<p>Normally when I need Linux on my computers, I fire up <a target="_blank" href="http://www.kubuntu.org/">Kubuntu</a> in a <a target="_blank" href="http://www.virtualbox.org/">VirtualBox</a>, and while this works fine for my image upload scripts and the like, it is not such a good idea to run Eclipse and the GlassFish v3 application server in that environment. It&#8217;s not that it doesn&#8217;t work, but I don&#8217;t want to give the virtual box more than 1 GB of memory, and that&#8217;s definitely no environment that&#8217;s fun to work in. </p>
<p>On the other hand, when I tried to install the <a target="_blank" href="http://download.java.net/glassfish/eclipse/">GlassFish Tools Bundle for Eclipse v1.2</a> (exactly what I use at work on Linux) under Windows 7, I quickly ran into a problem: Although everything installed just fine, I couldn&#8217;t start the integrated GlassFish v3 server from Eclipse. Some stack traces rushed by in the console view, and then a dialog told me that</p>
<blockquote><p><em>Starting bundled GlassFish v3 Java EE 6 has encountered a problem. Wrong user name or password.</em></p></blockquote>
<p>WTF?? This normally just works. Inspecting the console log revealed the real problem:</p>
<blockquote><p><em>java.net.BindException: Address family not supported by protocol family</em></p></blockquote>
<p>Also not exactly self-explanatory, especially along with that username/password dialog. Well, searching for the quote literally brought me to <a target="_blank" href="http://old.nabble.com/Error-while-starting-glassfish-v3-in-netbeans-6.8-java.net.BindException:-Address-family-not-supported-by-protocol-family:-bind:-44202%3Dcom.sun.enterprise.v3.services.impl.ServiceInitializerHandler@94aa42-td27388907.html">this discussion thread</a>, and there I found the solution.</p>
<p>In Windows 7 (and seemingly Vista as well), the definition of localhost in Windows\System32\drivers\etc\hosts is in IPv6 notation, i.e. ::1 instead of 127.0.0.1, but trying to bind to localhost, GlassFish seemingly expects the IPv4 notation. I have no idea if there has been an update to GlassFish v3 in the meantime, but at least the bundle is still what was released on December 12. Hmm &#8230; one would expect such a bug to be highly unlikely to slip through quality control <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyway. If you encounter the problem, just edit Windows\System32\drivers\etc\hosts and change ::1 to 127.0.0.1. I found no problem with Windows so far, and now GlassFish starts up happily. Just thought I&#8217;d have to share that.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/lBxpspCcovE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/03/30/4-equipment/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/03/30/4-equipment/</feedburner:origLink></item>
		<item>
		<title>3 – What Can I Rely On?</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/_pjEfCc1Afw/</link>
		<comments>http://programming.manessinger.com/2010/03/27/3-what-can-i-rely-on/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 07:35:50 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Enterprise Edition]]></category>
		<category><![CDATA[Model Driven Design]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=112</guid>
		<description><![CDATA[In the last post we have seen that it will take me years to finish this project. The question is, what can I rely on, what can I build upon. What are the tools that I can use, without worrying that they are obsolete before my own tool even becomes usable?]]></description>
				<content:encoded><![CDATA[<p>In the last post we have seen that it will take me years to finish this project. The question is, what can I rely on, what can I build upon. What are the tools that I can use, without worrying that they are obsolete before my own tool even becomes usable?</p>
<h4 class="section">Programming Language</h4>
<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2007/20070522_222320_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2007/20070522_222320_ps.jpg" alt="" border="0" /></a> In the case of RPCmagiX I have made a bad choice. I used Itcl 2.2 for implementing the GUI, and as soon as I had finished it, ITcl 3 came out and it was incompatible in some subtle but crucial ways. But even if it had not been so obvious, today Tcl is mostly dead.</p>
<p>Perl was my choice for WADL, and although Perl is still much more alive than Tcl ever was, it is not really dominant any more. Perl 6 has taken too much time, there was a lot of FUD about Perl&#8217;s imminent death, and at the moment Python is king and Ruby the fashionable contender.</p>
<p>I really hate Python. It&#8217;s personal, probably nothing that you&#8217;ll understand, but a language that relies on indentation for structure, c&#8217;mon! That&#8217;s nothing but a bad, tasteless joke. So Python can&#8217;t be it.</p>
<p>Ruby seems to be OK as a language, but I have no idea how it will fare. It could easily be the next Tcl. Remember: we are talking about at least three years before the shelf life of my program even begins!</p>
<p>COBOL would be a good candidate for a language that is guaranteed to never die. But who would want to work in COBOL? Nope, not even joking <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And then there is another thing: I would like to use one language for the tool and for the code it creates. </p>
<p>Currently I work with Java. It took me a time to like it, but now I do. Yes, it&#8217;s a big ecosystem, yes it suffers from the fact that they had to reinvent the wheel and everything else that already was there, but now it is pretty mature and complete. And it has Eclipse. Working with Perl I never missed an IDE. A lot of Emacs windows on a big virtual desktop, some teminal windows, that&#8217;s all I ever needed.</p>
<p>Not so with Java. Java is pretty unusable without an IDE. But when you have something like Eclipse, when you have an integrated, incremental compiler, when you don&#8217;t write texts but actually manipulate parse trees, then all sorts of funny things are possible. Think of the refactoring support, and suddenly Java is a very flexible and dynamic language.</p>
<p>And Java has some other advantages: It won&#8217;t go away. Too much important code depends on it. Java is like Cobol, only a much more likeable language, and one with absolutely superior tools. Java is such an important language, because so much code for banks and insurances is written in it. There is a reason why there is a Java Enterprise Edition.</p>
<p>And for all that reasons my potential users are very, very likely to use Java. When I want to maximize the impact of my tool, Java is an ideal language.</p>
<p>But then, very similar things could be said about C#. Same category of language, same capabilities. A year ago I have written a nice mult-threaded system in it, and as a language I like it. Why not, it&#8217;s Java, deliberately disguised in an incompatible syntax, but there is no essential difference, and some solutions they have come up with, are really, really clever. For instance I like partial classes and miss them in Java.</p>
<p>On the other hand, it&#8217;s a matter of principle. I don&#8217;t like a language that is so tightly controlled by an entity like Microsoft. I don&#8217;t like working on Windows either. Yes, there is Mono, but when you go the Microsoft way, you really want Visual Studio. </p>
<p>Apart from that, it can have actual advantages when your tools are open source. Remember my ill-inspired decision for Itcl? Well, it is open source after all. For more than 10 years we have compiled Itcl 2.2 on all our AIX and Linux systems, and I see no reason why this can&#8217;t go on. A closed source core component would long since have been unsupported. Think of Visual Basic. Sure, Microsoft offered a migration path into .NET, but that&#8217;s only the core language. People often had augmented it with third-party components, and they often were not ported. We sure do have some of those cases.</p>
<h4 class="section">Libraries And Frameworks</h4>
<p>And then there&#8217;s all the stuff other people do. After all, what I&#8217;ll do is basically Model Driven Design. Eclipse has a whole big group of projects under that title. Shall I use them. Can I?</p>
<p>They play a different game. They play a numbers game. The <a target="_blank" href="http://www.eclipse.org/modeling/">Eclipse Modeling Project</a> has seven people only on its Project Management Council. Look at the list of projects on that page. Everything on that list looks interesting and like something that I could need, but I would have to spend all my time, work, free, sleeping, just to follow all that.</p>
<p>And then think of all that constantly changing. Try imagining the hassle with keeping all that in sync. It&#8217;s impossible, and even if I could do that, it would not help me, it would only slow me down.</p>
<p>No. I won&#8217;t do it. It may be possible to catch up with these things later though, for instance at a time when I have some people helping me. If they are interested in the field at all, they would probably have worked with those tools and frameworks. They would probably know how to bridge the gap between EMF and my own core abstractions. After all, whatever I come up with, it must be semantically equivalent to EMF, because if it were not, it couldn&#8217;t be as expressive.</p>
<p>Yes, I know, in a way it&#8217;s a waste of time to re-invent such things, but I simply can&#8217;t tie my own core abstractions to something that is completely out of my control. This would be irresponsible. On the other hand, when my own modeling structures are largely equivalent, when they simply have to, we can always bridge that single gap later, and by doing so, we will gain access to the whole infrastructure. At least that&#8217;s the theory <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h4 class="section">So What&#8217;s Left?</h4>
<p>I consider Java to be a good choice as a language, and I consider the Enterprise Edition in release 6 sufficiently mature. I will use all of that (well, probably not JSF, but who knows), and I won&#8217;t use any other framework.</p>
<p>The whole design will be very abstract, most of it completely oblivious of the environment it runs in. In the end there will be some channels where input comes from, the models will have to be stored, there will be code generators, but all that can be abstracted away, done by primitive stubs in the beginning, done by plugins later. The only things that I have to worry about now are my code abstractions and how expressive they are. </p>
<p>I can and should program away in my simple sandbox, not caring about slick user interfaces and high performance. While I do that, all sorts of things will happen. Computers will get faster, new frameworks, new GUI systems may come up and get mature, and I&#8217;ll connect to them when I need to. Doing it from the beginning would only be a waste of time.</p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/_pjEfCc1Afw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/03/27/3-what-can-i-rely-on/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/03/27/3-what-can-i-rely-on/</feedburner:origLink></item>
		<item>
		<title>2 – How Long Will It Take?</title>
		<link>http://feedproxy.google.com/~r/manessinger/dBES/~3/B9WV6WsES60/</link>
		<comments>http://programming.manessinger.com/2010/03/26/2-how-long-will-it-take/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 18:55:29 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Regular Post]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Market]]></category>
		<category><![CDATA[Time]]></category>

		<guid isPermaLink="false">http://programming.manessinger.com/?p=89</guid>
		<description><![CDATA[Here I try to find answers to two questions: "How high shall I aim?" and "How much time do I have". The higher I aim, the longer it will take me to reach my goal. Where is the sweet spot and is there one at all?]]></description>
				<content:encoded><![CDATA[<p><a target="_blank" href="http://manessinger.com/display.php/1024x1024/2009/20091001_170720_ps.jpg"><img style="margin: 0pt 0px 0pt 15px; float: right;" src="http://manessinger.com/images/0400x0400/2009/20091001_170720_ps.jpg" alt="" border="0" /></a> So far I have not even said what exactly that upcoming project will be, and reality is, that I don&#8217;t know exactly yet, thus of course I can&#8217;t tell how long it will take me to create it. But still, it may be a good idea to think about time. It will take me the longer, the higher I aim. But how high shall I aim? And how much time do I have?</p>
<p>RPCmagiX, the subject of my <a target="_blank" href="http://www.infosys.tuwien.ac.at/teaching/thesis/online/RPCmagiX/mt-release.html">Master&#8217;s Thesis</a>, took me extraordinarily long, two implementations over the course of five or six years. But then, at that time I had not a clue of the whole business, yes I even lacked a clear understanding of where I was heading. I worked in a lab situation, I noticed that some work got repetitive, and I felt the need to do something about it.</p>
<p>WADL, my past project that I wrote about in <a target="_blank" href="http://programming.manessinger.com/2010/03/20/1-libraries-frameworks-code-generators/">the previous post</a>, was created in a completely different situation. It was much bigger, much more advanced, but I had much more experience as well, and generating code already felt natural. Although I needed to implement a lot of infrastructure that today would be supplied by an application server, I was pretty fast. The base architecture and a first implementation took me less than half a year, almost all of the rest was done in the first two years, and all the while I myself was using it in actual projects, and in the second year I was also giving support to other developers.</p>
<p>The current situation is very different again. I have some very precise ideas, I think I mostly know what I need to know, but this time it is not a full-time job, this time it is something that I do in my free time. I may get support, but first I&#8217;ll have to provide something useful, something that people can play with, get excited about.</p>
<p>Well, that can easily put&#8217;s us in the multi-year category again, at least when I aim a little higher. </p>
<p>Let&#8217;s for the moment assume that it will take me a year to produce something that actually can be used. This will be an unstable implementation, no compatibility promises would be made, but the idea is, to have something that could be used as a shortcut in real projects. You would specify something, it would generate something, you would save a lot of time, but you could not hope to use any future version of the tool on that project. It would still be useful though, especially when you are in a hurry.</p>
<p>In order to be at that point in a year, I&#8217;ll have to have a rough implementation sometime next fall, I&#8217;d say October is a good time. One of the problems with code generators is, that you have to use them in order to iron out the bugs. I&#8217;ll have to make an actual project with my tool, and this has the potential to severely slow me down. I think I have a nice solution though. More about that later.</p>
<p>This is not a project schedule, there are no hard limits, it may easily take me even longer, but I think a year is a milestone. If I don&#8217;t have anything substantial in a year, I&#8217;ll cancel the project and don&#8217;t bother you any further.</p>
<p>So, I guess we&#8217;ll see nothing usable this year. I don&#8217;t have all time in the world though. Within a short time I will have committed to a core architecture and a rough feature set. If I want this program to be used (and of course I do, why else would I bother creating it?), I need to create something that is advanced enough to be useful at the time it begins to be usable. It&#8217;s the same problem that game developers face: you can&#8217;t make a new game for current technology, you have to design it with the future ecosystem in mind. </p>
<p>For me that means I should aim rather higher than lower. Not too high though, because if it takes me ten years to finish it, chances are, that other people have come up with pretty clever ideas in the meantime, and my ten year old design will show its age before it&#8217;s even done. I think five years would already be dangerously long, three years wouldn&#8217;t worry me though.</p>
<p>OK, without knowing what exactly I do, I have at least a rough time frame. An architecture and initial code in October, something useable for producing prototypes within a year, a commitment to compatibility in maybe two years, a first release in maybe three years, but not later than in five. Let&#8217;s see how this works out <img src='http://programming.manessinger.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/manessinger/dBES/~4/B9WV6WsES60" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programming.manessinger.com/2010/03/26/2-how-long-will-it-take/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	<feedburner:origLink>http://programming.manessinger.com/2010/03/26/2-how-long-will-it-take/</feedburner:origLink></item>
	</channel>
</rss><!-- This Quick Cache file was built for (  programming.manessinger.com/feed/ ) in 2.18274 seconds, on May 20th, 2013 at 4:44 am UTC. --><!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 20th, 2013 at 5:44 am UTC -->
