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

<channel>
	<title>Stephen J. Houston &#187; Stephen Houston</title>
	<atom:link href="http://www.stephenhouston.com/author/stephen/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stephenhouston.com</link>
	<description>Just another J2EE developer</description>
	<lastBuildDate>Mon, 09 Mar 2009 08:45:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring, Portlets and Annotation Configuration</title>
		<link>http://www.stephenhouston.com/20090309/spring-portlets-and-annotation-configuration/</link>
		<comments>http://www.stephenhouston.com/20090309/spring-portlets-and-annotation-configuration/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 08:45:51 +0000</pubDate>
		<dc:creator>Stephen Houston</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JBoss Portal]]></category>

		<guid isPermaLink="false">http://www.stephenhouston.com/?p=30</guid>
		<description><![CDATA[There&#8217;s one thing that is easy to miss when setting up a Portlet using Spring MVC and Annotation configuration, and that is the correct placement of the &#60;context:annotation-config /&#62; elements. In the examples that I found, the element is only located in the applicationContext.xml file, unfortunately this doesn&#8217;t always work as you might expect.
In Spring [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s one thing that is easy to miss when setting up a Portlet using Spring MVC and Annotation configuration, and that is the correct placement of the &lt;context:annotation-config /&gt; elements. In the examples that I found, the element is only located in the applicationContext.xml file, unfortunately this doesn&#8217;t always work as you might expect.</p>
<p>In Spring MVC Portlets, the applicationContext file is used to define beans that should be available to all the portlets in that portlet application (or WAR). Similarly it also makes these beans available to any servlets that are defined in the WAR. So far so good, this is working correctly, and is exactly how you would expect it to work.</p>
<p>The problem arises when using Annotation Configuration, and it can be difficult to trace back to exactly what might be causing it. If you define &lt;context:annotation-config /&gt; in just the applicationContext.xml file, then the annotation configuration will appear to work (portlet initialization will work, and they should start up appearing to be fully wired). However when the portlets are used, they will start to throw NullPointerExceptions due to beans not being wired. It appears that @Autowired and @Resource are not being interogated when the portlet is running, but worked fine when it was being initialized.</p>
<p>Attempting to diagnoise this issue will have you looking at classpaths, ensuring that there are no duplicated JARs loaded by parent and child classloaders, tracing the spring logs for wiring errors, validating the presence of spring-aspects.jar, etc, etc, etc. While these are all valid approachs, and can be a good way to clean up an application, in all likelyhood what is wrong is that the &lt;context:annotation-config /&gt; element is missing from the individual portlet&#8217;s configuration file. Leaving this element out means that the spring autowiring won&#8217;t be enabled when the portlet is using the portal server&#8217;s classloader, but was enabled when the portlet was initialially loaded by the application server&#8217;s classloader. At least, this appears to be what&#8217;s happening in JBoss Portal Server, your miliage may vary with other servers.</p>
<p>How do you ensure that your annotated portlet will be wired correctly? Simple, add these to both your applicationContext.xml and xxx-Portlet.xml files:</p>
<p>&lt;context:annotation-config /&gt;<br />
&lt;context:spring-configured /&gt;<br />
&lt;aop:aspectj-autoproxy/&gt;</p>
<p>Note: In the case of the xxx-Portlet.xml files, its a good idea to create a common.xml file, then import that in each of the individual portlet files. This allows for commonality between all the portlets, even though they will get their own instance of any beans defined in it.<br />
&lt;import resource=&#8221;classpath:/com/foo/bar/context/common.xml&#8221;/&gt;</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> c1c694ecf7b1a1f6c941688692febd22)</small>]]></content:encoded>
			<wfw:commentRss>http://www.stephenhouston.com/20090309/spring-portlets-and-annotation-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log at the correct level</title>
		<link>http://www.stephenhouston.com/20090303/log-at-the-correct-level/</link>
		<comments>http://www.stephenhouston.com/20090303/log-at-the-correct-level/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:31:47 +0000</pubDate>
		<dc:creator>Stephen Houston</dc:creator>
				<category><![CDATA[JBoss Portal]]></category>

		<guid isPermaLink="false">http://www.stephenhouston.com/20090303/log-at-the-correct-level/</guid>
		<description><![CDATA[We all know the importance of having good, clear, and useful log messages in our applications (if not then I suggest you read &#34;Release It&#34; from the Pragmatic bookshelf). However it is not always apparent that log messages are written at the correct level.
For example, Log4J has a number of log levels; trace, debug, info, [...]]]></description>
			<content:encoded><![CDATA[<p>We all know the importance of having good, clear, and useful log messages in our applications (if not then I suggest you read &quot;<a href="http://www.pragprog.com/titles/mnee/release-it">Release It</a>&quot; from the Pragmatic bookshelf). However it is not always apparent that log messages are written at the correct level.</p>
<p>For example, Log4J has a number of log levels; trace, debug, info, warn, error and fatal. While it looks like its clear what you should log at each level, some major players get it wrong.</p>
<p>I&#8217;ve spent the last day looking into issues in JBoss Portal where my custom login module wasn&#8217;t working correctly. There was nothing unusual in the log, nor were any errors written to the screen, no indication as to what the problem might have been. After much staring at the config files, it turned out that the package name was wrong, resulting in a ClassNotFoundException. 2 seconds to fix and a few minutes to start the portal and we&#8217;re elected.</p>
<p>However, all of this could have been avoided if JBoss was logging something as important as a ClassNotFoundException at a level other than TRACE (see JIRA, TWITTER). At least ERROR, and probably even FATAL (given the severity of not having a login module) would have been appropriate.</p>
<p>The same issue can be seen with exceptions from the portlets themselves. JBoss logs these at INFO level, which is inappropriate as an exception emitting from the portlet&#8217;s execution stack will have resulted in the user experiencing an error.</p>
<p>So what are appropriate uses of the log levels?</p>
<p><strong>TRACE</strong> &#8211; method entry/exit points, logging of method parameters, any other information that is only useful when tracing why something has gone wrong. This level will generate orders of magnitude more data than the other levels, so should only be enabled selectively on classes when diagnosing issues. Of course, that is not to say that it should only be written selectively, it should be everywhere (introduced using Aspects for the majority of cases), and it must be wrapped by if (logger.isTraceEnabled() when using string concatenation for performance reasons).</p>
<p><strong>DEBUG</strong> &#8211; information relevant for the majority of debug cases, where we aim to get to the bottom of the problem without resorting to TRACE logging. E.g. database access information, generated SQL statements, etc. As with TRACE, these messages must be wrapped in if (logger.isDebugEnabled()).</p>
<p><strong>INFO</strong> &#8211; informative messages from the application. e.g. Database insert took 500 ms, or HTTP POST received containing 600 bytes. These messages should be wrapped in if (logger.isInfoEnabled()).</p>
<p><strong>WARN</strong> &#8211; something MAY be going wrong, but we&#8217;ve managed to recover from it for now. e.g. HTTP connection dropped, retrying.</p>
<p><strong>ERROR</strong> &#8211; something HAS gone wrong, but its limited to the scope of a single user, or single operation. e.g. Database constraint violation, key already exists.</p>
<p><strong>FATAL</strong> &#8211; something HAS SERIOUSLY went wrong. These errors affect multiple users, or multiple operations on the system. They usually need immediate action as the system may no longer be in operation. e.g. Database error: Database has gone away.</p>
<p>Using these simple rules, its not difficult to choose the correct level to log at. By doing so you&#8217;ll make life easier for the next guy.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> c1c694ecf7b1a1f6c941688692febd22)</small>]]></content:encoded>
			<wfw:commentRss>http://www.stephenhouston.com/20090303/log-at-the-correct-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What the Spring template should really do</title>
		<link>http://www.stephenhouston.com/20090227/what-the-spring-template-should-really-do/</link>
		<comments>http://www.stephenhouston.com/20090227/what-the-spring-template-should-really-do/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 12:31:03 +0000</pubDate>
		<dc:creator>Stephen Houston</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.stephenhouston.com/?p=22</guid>
		<description><![CDATA[Spring provides a wonderful mechanism to standard the way that connections to an underlying database are managed. The JDBC Template abstracts the developer from having to understand any particular vendor, and provides a neat way to translate vendor specific SQL errors into a standardised format.
It doesn&#8217;t go far enough. SQL can no longer be treated [...]]]></description>
			<content:encoded><![CDATA[<p>Spring provides a wonderful mechanism to standard the way that connections to an underlying database are managed. The JDBC Template abstracts the developer from having to understand any particular vendor, and provides a neat way to translate vendor specific SQL errors into a standardised format.</p>
<p>It doesn&#8217;t go far enough. SQL can no longer be treated as a standard, but instead should be viewed as a recommendation. The differences in SQL dialects between vendors is unbelievable, and inexcusable. However there isn&#8217;t a standardised translation service available. In an earlier example I outlined the different SQL statements required to allow MySQL and Oracle to update the same row in the database:</p>
<p>MySQL</p>
<pre lang="sql">
UPDATE TABLE1(date, username)
VALUES ("2009-01-01", "fred");
</pre>
<p>Oracle</p>
<pre lang="sql">
UPDATE TABLE1(date, username)
VALUES(TO_DATE("01-JAN-2009"), "fred")
</pre>
<p>Clearly this it is undesirable to have to write these different SQL statements in an application, there is too much scope for error and poor testing to let a faulty statement through. We could use Hibernate, represent the whole thing in objects, mapping files and HQL, but that&#8217;s the programming equivalent of taking a sledgehammer to a nut. It would work (usually) but it will certainly not be pretty, nor light weight.</p>
<p>What is really needed is a translator, similar to the concept of Hibernate&#8217;s dialects. The translator could be part of the template, either determined automatically from the database, or wired in by configuration. Developers would then simply execute statements on the template as normal, with it handling the conversion to the relevant dialect for the database:</p>
<pre lang="java">
template.update(
    "UPDATE TABLE1(date, username) "
    + "VALUES (\"2009-01-01\", \"fred\");");
</pre>
<p>This would make the JDBC template a universal fit for accessing databases.</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> c1c694ecf7b1a1f6c941688692febd22)</small>]]></content:encoded>
			<wfw:commentRss>http://www.stephenhouston.com/20090227/what-the-spring-template-should-really-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL is English</title>
		<link>http://www.stephenhouston.com/20090226/sql-is-english/</link>
		<comments>http://www.stephenhouston.com/20090226/sql-is-english/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 20:42:48 +0000</pubDate>
		<dc:creator>Stephen Houston</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.stephenhouston.com/20090226/sql-is-english/</guid>
		<description><![CDATA[As we all know, the ANSI SQL standard is now the computer equivalent of English. Its claimed to be universal, major databases claim to speak it; but alas much like English has now splintered into several derivative langauges, SQL has many dialects.
I recently hit this issue when I tried to migrate a simple application from [...]]]></description>
			<content:encoded><![CDATA[<p>As we all know, the ANSI SQL standard is now the computer equivalent of English. Its claimed to be universal, major databases claim to speak it; but alas much like English has now splintered into several derivative langauges, SQL has many dialects.</p>
<p>I recently hit this issue when I tried to migrate a simple application from using MySQL to Oracle. Yes I know its going backwards, the reasons for the move were beyond my control. This application made the simplest of simple calls to the database, e.g.</p>
<pre lang="sql">INSERT INTO TABLE1(date, username)
VALUES ("2009-01-01", "fred");</pre>
<p>Yes its that basic. One would assume that this would work on all major databases that claim to speak SQL, but you would be wrong. Running this on Oracle (using the thin client) produced an error. Aparently the ; at the end of the statement is not recognised. Hmm&#8230; Ever seen the ANSI SQL-92 standard Oracle? So remove it and we move to iteration 1 of the conversion to Oracle</p>
<pre lang="sql">INSERT INTO TABLE1(date, username)
VALUES ("2009-01-01", "fred")</pre>
<p>Does it run? No.</p>
<p>What&#8217;s wrong this time? The date. Lets see, the date is in ISO 8601 format, so it must need something else. Aha, the TO_DATE function, ok</p>
<pre lang="sql">INSERT INTO TABLE1(date, username)
VALUES (TO_DATE("2009-01-01"), "fred")</pre>
<p>Invalid month.</p>
<p>What? 01 is an invalid month? January anyone? Revert to google. Ok, different format for dates. Seems like ISO 8601 dates are not welcome in the land of Oracle.</p>
<pre lang="sql">INSERT INTO TABLE1(date, username)
VALUES (TO_DATE("01-JAN-2009"), "fred")</pre>
<p>Success! Unbelievably 3 iterations of this simple SQL statement were required to get it to work on Oracle, when it was previously working on MySQL.</p>
<p>I&#8217;ve left out the other example which made use of an autoincrement column in MySQL. Selecting from a sequence from some table named DUAL just makes no sense. Why DUAL? How did the Oracle guys come up with this? It breaks my heart.</p>
<p>Seriously database people, this is the equivalent of me going up to the Queen of England and saying &#8220;I CAN HAS CHEEZBURGER?&#8221;</p>
<hr /><small>Copyright &copy; 2009<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> c1c694ecf7b1a1f6c941688692febd22)</small>]]></content:encoded>
			<wfw:commentRss>http://www.stephenhouston.com/20090226/sql-is-english/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
