<?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>UnderworldLabs.org &#187; java</title>
	<atom:link href="http://underworldlabs.org/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://underworldlabs.org</link>
	<description>My Dropbox</description>
	<lastBuildDate>Tue, 20 Mar 2012 23:54:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>SOAP Response Codes</title>
		<link>http://underworldlabs.org/blog/soap-response-codes/</link>
		<comments>http://underworldlabs.org/blog/soap-response-codes/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 11:47:04 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=192</guid>
		<description><![CDATA[I recently had an issue where as a part of a SOAP fault response I wanted to return a HTML response code that better represented...]]></description>
			<content:encoded><![CDATA[<p>I recently had an issue where as a part of a SOAP fault response I wanted to return a HTML response code that better represented what the error was &#8211; in this case that a particular record requested via the service did not exist for the supplied identifier.</p>
<p>This sort of request might return a response code of 200 in a more typical web request with perhaps a relevant error message or similar. It felt that within a service &#8211; no human action, intervention or response &#8211; something a little more informative or appropriate was required such as <em>422 Unprocessable Entity</em>.</p>
<p>To achieve this I defined an out fault interceptor as follows.</p>
<pre>
        &lt;jaxws:outFaultInterceptors&gt;
            &lt;bean class="mypackage.MyServiceOutInterceptor"/&gt;
        &lt;/jaxws:outFaultInterceptors&gt;
</pre>
<p>The implementation was rather simple in the end:</p>
<pre>
public class MyServiceOutInterceptor extends AbstractSoapInterceptor {

    public MyServiceOutInterceptor() {
        super(Phase.SEND);
    }

    public void handleMessage(SoapMessage soapMessage) throws Fault {

        Set&lt;Class&lt;?&gt;&gt; formats = soapMessage.getContentFormats();
        for (Class&lt;?&gt; format : formats) {

            Object content = soapMessage.getContent(format);
            if (isServiceError(content)) {
                ServiceFaultException exception = asServiceError(content);
                soapMessage.put(org.apache.cxf.message.Message.RESPONSE_CODE, exception.getResponseCode());
                break;
            }

        }

    }

    private ServiceFaultException asServiceError(Object content) {
        return (ServiceFaultException) ((Fault) content).getCause();
    }

    private boolean isServiceError(Object content) {
        return (content.getClass().isAssignableFrom(SoapFault.class))
                &#038;&#038; (((Fault) content).getCause() instanceof ServiceFaultException);
    }

}
</pre>
<p>We check that we have a valid error, and then deliberately set the response code for the SOAP message.</p>
<p>The ServiceFaultException class shown above is defined as a web fault using @WebFault and the relevant error message and code is set as required.</p>
<p>So, the merits of returning 422 for an entity that can not be found aside, the above demonstrates how to change the response code returned as a part of a SOAP fault to anything you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/soap-response-codes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UUID and PostgreSQL</title>
		<link>http://underworldlabs.org/blog/uuid-and-postgresql/</link>
		<comments>http://underworldlabs.org/blog/uuid-and-postgresql/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 05:57:10 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=162</guid>
		<description><![CDATA[I often use UUID values as secondary identifiers for my domain objects. This is usually generated for my domain entity very simply as follows: java.util.UUID.randomUUID().toString();...]]></description>
			<content:encoded><![CDATA[<p>I often use UUID values as secondary identifiers for my domain objects. This is usually generated for my domain entity very simply as follows:</p>
<pre>java.util.UUID.randomUUID().toString();</pre>
<p>and set directly either as a field variable on instantiation or sometimes in an interceptor on save.</p>
<p>On a recent project we had to migrate some data across some new entities and needed something outside the application to generate the UUID values for each record. I knew that PostgreSQL supported UUID generation &#8211; though I had never used this before &#8211; and even has a <code>UUID</code> data type. Getting to the function itself proved a little more challenging as it isn&#8217;t actually included on a typical installation and is found within the <code>postgres-contrib</code> package. So, to install&#8230;</p>
<pre>
apt-get install postgresql-contrib
sudo su -c "psql pdrivers < /usr/share/postgresql/8.4/contrib/uuid-ossp.sql" postgres
</pre>
<p>The above installs the relevant <code>contrib</code> package, and creates the UUID functions from the script within the unpacked <code>contrib</code> directory (substitute version as required). We are also installing the function as a superuser (<code>postgres</code> in this case) as we need a user with the ability to install functions using <code>C</code> code.</p>
<p>To generate UUID values execute as follows:</p>
<pre>SELECT uuid_generate_v1();

c1b84d24-90c9-11e0-aa50-33cd7e76d901
e9e3b374-90c9-11e0-8f0f-df46bcf47f20
eea6fba0-90c9-11e0-9ce0-a33175edde97
</pre>
<p>Some good references on the available functions can be found <a href="http://www.postgresql.org/docs/9.0/static/uuid-ossp.html">here</a> with some further info on the package <a href="http://www.ossp.org/">OSSP</a> UUID pages <a href="http://www.ossp.org/pkg/lib/uuid/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/uuid-and-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache 2.2.3-x with mod_jk</title>
		<link>http://underworldlabs.org/blog/apache-2-2-3-x-with-mod_jk/</link>
		<comments>http://underworldlabs.org/blog/apache-2-2-3-x-with-mod_jk/#comments</comments>
		<pubDate>Tue, 10 May 2011 00:03:37 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=145</guid>
		<description><![CDATA[Running CentOS 5 on one of my personal (playpen) servers, i recently performed a simple yum update which brought in the package httpd-2.2.3-45.el5.centos.1.i386 and its...]]></description>
			<content:encoded><![CDATA[<p>Running CentOS 5 on one of my personal (playpen) servers, i recently performed a simple yum update which brought in the package <code>httpd-2.2.3-45.el5.centos.1.i386</code> and its dependents in addition to some others including some python and selinux updates. So no biggie so far &#8211; but restarting apache brought me a world of pain as I spent the next 24 hours trying to diagnose why any http request to <em>any</em> domain on that server would never complete and [seemingly] never timeout.</p>
<p>Frankly, I don&#8217;t know for sure which particular package was the culprit. There was nothing logged that pointed to any issues &#8211; indeed any and all logs I went through indicated all was well. I also could not find a single thing online that resembled what I was experiencing. I have managed my own servers for about 10 years now. I&#8217;m far from a competent Linux admin but I usually know enough to get by or just enough to get out of trouble, so I became severely frustrated when a seemingly simple upgrade could result in all my sites being made unavailable.</p>
<p>I started by stripping back my Apache install to next to nothing &#8211; which brought back a single <em>static</em> site i set up as a test. Then line-by-line I reintroduced various modules, includes and various directive lines. At the very bottom I had my mod_jk include &#8211; which by the way serves over half of my sites. </p>
<p>As soon as I reintroduced mod_jk it dumped. After much fiddling, rebuilding mod_jk, installing from rpm, downgrading packages, tinkering with various mod_jk parameters, using <code>strace</code> on startup (great article on debugging with <code>strace</code> <a href="http://linuxgazette.net/132/vishnu.html">here</a>) I finally put it down to the inclusion of the following:</p>
<pre>
&lt;Location /*/META-INF/*&gt;
    Deny From All
&lt;/Location&gt;
&lt;Location /*/WEB-INF/*&gt;
    Deny From All
&lt;/Location&gt;
</pre>
<p>The above tells Apache as a global directive to disallow any access to the protected Java web application directories <code>WEB-INF</code> and <code>META-INF</code>. </p>
<p>The lines above have been a part of my apache/mod_jk config for as long as I remember. I haven&#8217;t yet had a good look as to why the above is no longer acceptable &#8211; I&#8217;m just relieved to have everything back up. I would have expected Apache to complain about configuration errors, issue the relevant message and fail to start just like it does for most other issues. Not so in this case and furthermore it silently takes down the whole server instance.</p>
<p>I didn&#8217;t find any references to this anywhere &#8211; perhaps this will help someone equally confused as I was <img src='http://underworldlabs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/apache-2-2-3-x-with-mod_jk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building with Hudson</title>
		<link>http://underworldlabs.org/blog/building-with-hudson/</link>
		<comments>http://underworldlabs.org/blog/building-with-hudson/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 00:50:26 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=101</guid>
		<description><![CDATA[I&#8217;ve used a few build servers now including Continuum, CruiseControl and Bamboo. I recently started using Hudson and immediately found it easier to set up...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used a few build servers now including <a href="http://continuum.apache.org/" target="_blank">Continuum</a>, <a href="http://cruisecontrol.sourceforge.net/" target="_blank">CruiseControl</a> and <a href="http://www.atlassian.com/software/bamboo/" target="_blank">Bamboo</a>. I recently started using <a href="https://hudson.dev.java.net/" target="_blank">Hudson</a> and immediately found it easier to set up and use than any of the others. It supports <a href="http://ant.apache.org/" target="_blank">Ant</a> and <a href="http://http://maven.apache.org/" target="_blank">Maven</a> builds very nicely as well allowing any sort of script or batch execution. Build notifications can be configured using email and RSS.</p>
<p><img class="aligncenter size-full wp-image-107" title="hudson-screenshot1" src="http://underworldlabs.org/wp-content/files/2009/02/hudson-screenshot1.png" alt="hudson-screenshot1" width="402" height="274" /></p>
<p><a href="http://blog.objectmentor.com/articles/category/uncle-bobs-blatherings" target="_blank">Uncle Bob</a> of <a href="http://objectmentor.com/" target="_blank">ObjectMentor</a> has posted a quick demo <a href="http://blog.objectmentor.com/articles/2008/12/11/hudson-a-very-quick-demo" target="_blank">here</a>.</p>
<p>You can download either a WAR file or pre-packaged for your distro including RPMs and Debian packages. Well worth a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/building-with-hudson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;By installing Java, you will be able to experience the power of Java&#8221;</title>
		<link>http://underworldlabs.org/blog/by-installing-java-you-will-be-able-to-experience-the-power-of-java/</link>
		<comments>http://underworldlabs.org/blog/by-installing-java-you-will-be-able-to-experience-the-power-of-java/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 05:04:12 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=97</guid>
		<description><![CDATA[As my 2 year-old would say &#8211; &#8216;thats a little bit funny&#8217;&#8230; From a post with the same name, check out this entry from Joel...]]></description>
			<content:encoded><![CDATA[<p>As my 2 year-old would say &#8211; <em>&#8216;thats a little bit funny&#8217;</em>&#8230;</p>
<p>From a post with the same name, check out <a href="http://www.joelonsoftware.com/items/2009/01/12.html" target="_blank">this</a> entry from <a href="http://www.joelonsoftware.com" target="_blank">Joel on Software</a>.</p>
<p>Cracker!</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/by-installing-java-you-will-be-able-to-experience-the-power-of-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Assemblers</title>
		<link>http://underworldlabs.org/blog/object-assemblers/</link>
		<comments>http://underworldlabs.org/blog/object-assemblers/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:22:00 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[assemblers]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=39</guid>
		<description><![CDATA[Object assemblers for domain to DTO transformations are perhaps one of the more tedious components of your typical n-tier application. They&#8217;re rather boring to write,...]]></description>
			<content:encoded><![CDATA[<p>Object assemblers for domain to DTO transformations are perhaps one of the more tedious components of your typical <em>n</em>-tier application. They&#8217;re rather boring to write, ridiculously laborious and for whatever reason I always seem to need to defend their use &#8211; especially in this apparent age of <em>rapid application development</em>.</p>
<p>Frankly, the case for DTOs is well and truly closed &#8211; take a look at Martin Fowler&#8217;s <a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html" target="_blank">entry</a> for a good description of the pattern from his book <a href="http://martinfowler.com/books.html#eaa" target="_blank">Patterns of Enterprise Application Architecture</a>. There&#8217;s a heap of other references from a simple <a href="http://www.google.com.au/search?q=data+transfer+objects+and+assemblers" target="_blank">Google search</a>.</p>
<p>In this light, I was recently directed to a new assembler library by Rob Monie that he described on <a href="http://backtofront.squarespace.com/blog/2008/12/30/a-simple-object-assembler.html" target="_blank">Back to Front</a>. Its very easy to use and allows you to manage the process of traversing the object graph quite easily relying on <em>convention over configuration</em> techniques. It goes a long way to taking most of the tedioum of providing an assembler and transformation mechanism for your domain and DTO objects. The project is free and open source on <a href="http://code.google.com/p/simple-object-assembler/" target="_blank">Google Code</a>. Definately worth a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/object-assemblers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Execute Query</title>
		<link>http://underworldlabs.org/blog/execute-query/</link>
		<comments>http://underworldlabs.org/blog/execute-query/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 23:03:03 +0000</pubDate>
		<dc:creator>Takis Diakoumis</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://underworldlabs.org/?p=13</guid>
		<description><![CDATA[After quite the long slog (over 12 months) and following pesky little things like baby, work and life getting in the way, i&#8217;ve finally managed...]]></description>
			<content:encoded><![CDATA[<p>After quite the long slog (over 12 months) and following pesky little things like baby, work and life getting in the way, i&#8217;ve finally managed to release a new version of Execute Query &#8211; a universal database query (and much more&#8230;) tool.</p>
<p>Check out version 3.1.0 here <a href="http://executequery.org/" target="_blank">http://executequery.org</a><br />
Feedback most welcome. Contributions most welcome.</p>
<p>I do plan for future releases to be more incremental and frequent.</p>
]]></content:encoded>
			<wfw:commentRss>http://underworldlabs.org/blog/execute-query/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

