<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Alan's RamblingsJava</title>
    <link>http://bleaklow.com:80/categories/tech/java/</link>
    <description>My opinions may be incorrect, but they are my own</description>
    <language>en</language>
    <copyright>Alan Burlison</copyright>
    <pubDate>Fri, 29 Mar 2013 18:22:00 GMT</pubDate>
    <dc:creator>Alan Burlison</dc:creator>
    <dc:date>2013-03-29T18:22:00Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>Alan Burlison</dc:rights>
    <image>
      <title>Alan's RamblingsJava</title>
      <url>http://bleaklow.com:80/categories/tech/java/</url>
    </image>
    <item>
      <title>mod-rewrite equivalent for Tomcat</title>
      <link>http://bleaklow.com:80/2010/06/02/mod_rewrite_equivalent_for_tomcat.html</link>
      <content:encoded>&lt;p&gt;
I've migrated and merged my old blogs.sun.com and bleaklow.com blogs into this new one, using &lt;a href="http://pebble.sourceforge.net/"&gt;Pebble&lt;/a&gt;.  As a result, there are a number of links out there on the interwebs to bleaklow.com that are now broken, as everything has moved around - google's &lt;a href="http://www.google.com/webmasters/tools/"&gt;webmaster tools&lt;/a&gt; gives me a comprehensive list.  If I was hosting this blog using &lt;a href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt;, the standard solution would be to use the most excellent &lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html"&gt;mod-rewrite&lt;/a&gt; Apache module to redirect the broken links to somewhere appropriate.  However Pebble is a &lt;a href="http://java.sun.com/javaee/"&gt;J2EE&lt;/a&gt; application and uses &lt;a href="http://tomcat.apache.org/"&gt;Tomcat&lt;/a&gt; instead of Apache.  I've been looking for an equivalent to mod-rewrite for a while and never managed to find anything.  Whilst looking for something else entirely (always the way) I found &lt;a href="http://tuckey.org/urlrewrite/"&gt;Url Rewrite Filter&lt;/a&gt;.  This is functional equivalent to mod-rewrite for J2EE servers, and offers most of the same features as mod-rewrite.  I'm using it and it seems to do the job just fine, and the beta even has a mod-rewrite style configuration option, if you need a security blanket :-)
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/apache/">apache</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/mod-rewrite/">mod-rewrite</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/tomcat/">tomcat</category>
      <category domain="http://bleaklow.com:80/tags/urlrewrite/">urlrewrite</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Wed, 02 Jun 2010 17:15:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-06-02:default/1275498900000</guid>
      <dc:date>2010-06-02T17:15:00Z</dc:date>
    </item>
    <item>
      <title>Simple parser for MovableType exports</title>
      <link>http://bleaklow.com:80/2010/05/23/simple_parser_for_movabletype_exports.html</link>
      <content:encoded>&lt;p&gt;
As part of moving my blog over to &lt;a href="http://pebble.sourceforge.net/" pebble=""&gt;&lt;/a&gt; I needed to be able to transfer the content from my old &lt;a href="http://www.movabletype.com/"&gt;MovableType&lt;/a&gt; blog and my blogs.sun.com blog, which runs on &lt;a href="http://www.movabletype.com/"&gt;Roller&lt;/a&gt;.  Both MT and Roller can export in &lt;a href="http://www.sixapart.com/movabletype/docs/mtimport"&gt;MovableType export format&lt;/a&gt; and Pebble has a MT importer, so it looked relatively straightforward.  However when I looked at the content I was importing it was clear I'd need to munge it on its way into Pebble.  The Pebble MT importer is one-pass and loads the entries into Pebble as it reads them, whereas I wanted to read them in, munge them and only then load them into Pebble, so I wrote a simple parser to read in the MT export.  It's not a thing of great beauty but it got the job done.  I thought it might be useful for other people who want to read MovableType exports from Java, so I've put a copy of it &lt;a href="files/2010/MTParser.tar.gz"&gt;here&lt;/a&gt;.
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/export/">export</category>
      <category domain="http://bleaklow.com:80/tags/import/">import</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/movabletype/">movabletype</category>
      <category domain="http://bleaklow.com:80/tags/pebble/">pebble</category>
      <category domain="http://bleaklow.com:80/tags/roller/">roller</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Sun, 23 May 2010 10:03:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-05-23:default/1274608980000</guid>
      <dc:date>2010-05-23T10:03:00Z</dc:date>
    </item>
    <item>
      <title>Image thumbnailer for Pebble</title>
      <link>http://bleaklow.com:80/2010/05/23/image_thumbnailer_for_pebble.html</link>
      <content:encoded>&lt;p&gt;
This blog uses the &lt;a href="http://pebble.sourceforge.net/"&gt;Pebble&lt;/a&gt; package for delivering content.  Pebble isn't a particularly common blogging package but it fits my purely personal and subjective requirements:
&lt;/p&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Not written in PHP (blegh)
&lt;li&gt;Open source, and something in Java would be nice
&lt;li&gt;Doesn't use a database and uses flat files that I can manage manually if I need to
&lt;li&gt;Good RSS, search, tag and category management
&lt;li&gt;Can be restyled easily
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;The old incarnation of this blog used &lt;a href="http://www.movabletype.com/"&gt;MovableType&lt;/a&gt; but that doesn't really tick the Open Source box any more.  blogs.sun.com  uses &lt;a href="http://rollerweblogger.org/project/"&gt;Roller&lt;/a&gt; but that requires a database back-end.  All these constraints combined to give a pretty short list of candidates, i.e. Pebble.
&lt;/p&gt;
&lt;p&gt;
One thing that Pebble lacks is an image thumbnailer.  I'm not bothered about glossy JavaScript solutions such as &lt;a href="http://www.huddletogether.com/projects/lightbox2/"&gt;Lightbox&lt;/a&gt;, and I'm quite happy to type in HTML table definitions.  All I wanted was something to save me the tedium of manually generating the thumbnails and typing in the HTML to display them and link to the full-size image in a popup window.  MovableType has this feature but Pebble doesn't so I sat down one evening and knocked together an equivalent as a Pebble plugin, using the standard &lt;a href="http://java.sun.com/products/java-media/2D/index.jsp"&gt;Java2D&lt;/a&gt; APIs to do the image manipulation.  All the thumbnails on this site are done with it, and I've submitted this as a &lt;a href="http://open.jira.com/browse/PEBBLE-26"&gt;patch&lt;/a&gt; to Pebble so hopefully it will make it into a future release.
&lt;/p&gt;
&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;
The patch has been accepted and should be appearing in a future version of Pebble.
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/pebble/">pebble</category>
      <category domain="http://bleaklow.com:80/tags/photo/">photo</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/thumbnail/">thumbnail</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <pubDate>Sun, 23 May 2010 08:54:00 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2010-05-23:default/1274604840000</guid>
      <dc:date>2010-05-23T08:54:00Z</dc:date>
    </item>
    <item>
      <title>Why I hate XML configuration files</title>
      <link>http://bleaklow.com:80/2007/04/05/why_i_hate_xml_configuration_files.html</link>
      <content:encoded>&lt;p&gt;I'm working on a reasonably large (1000+ source files) J2EE application that makes extensive (some might say utterly excessive) use of external components - it requires in the order of 50 JAR libraries to run, over and above the standard J2EE ones.&lt;/p&gt;&lt;p&gt;And of course many of those JAR files have their own unique XML files to configure them.&lt;/p&gt;&lt;p&gt;And of course many bits information related to the configuration of the application (URLs, database details etc) have to be repeated in more than one of those XML files.&lt;/p&gt;&lt;p&gt;And there's no global way of doing this.&lt;/p&gt;&lt;p&gt;So the people who originally wrote the application came up with a scheme - they'd store the configuration values in property files.&lt;/p&gt;&lt;p&gt;But that only helped for things that got the values dynamically, for example by using the J2SE &lt;a href="http://java.sun.com/javase/6/docs/api/java/util/Properties.html" target="_blank"&gt;Properties&lt;/a&gt; class. All those external components they'd used didn't know anything about the application's property files, they only knew about their own unique little XML files.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;So the people writing the application came up with another scheme - they'd embed tokens in all those little XML files, then use the Ant &lt;a href="http://ant.apache.org/manual/CoreTasks/filter.html" target="_blank"&gt;Filter&lt;/a&gt; task to replace them at build-time with the values from the property files.&lt;/p&gt;&lt;p&gt;&amp;quot;&lt;a href="http://www.urbandictionary.com/define.php?term=jobs+a+good'un" target="_blank"&gt;Job's a good 'un!&lt;/a&gt;&amp;quot; they doubtless exclaimed, flushed with their extreme cleverness.&lt;/p&gt;&lt;p&gt;Then I came along and had to maintain the beast, when I found:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;There are in excess of 50 of these properties, which makes configuring the application more than a little tedious and more than a little error-prone.&lt;/li&gt;&lt;li&gt;The names of the tokens
processed by the Ant Filter task and the names of the properties used to set their values mostly bear very little relationship to each
other.&lt;/li&gt;&lt;li&gt;There is no consistently-applied property naming scheme. There are in fact several inconsistently-applied naming schemes.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Some of the properties are just renamed versions of other properties. Sometimes they are inconsistently renamed versions of other properties. Sometimes they don't appear to be used at all.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It isn't clear when reading a property file which properties are only used at compile time by the Ant Filter task, and which properties are only used at run time. It's also unclear which ones are used at both compile &lt;i&gt;and&lt;/i&gt; run time.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The compile-time use of properties is a killer because it means the application can't realistically be reconfigured without recompiling it - because the use of the Ant Filter task means the compile-time property file values end up hard-coded in many different places. It's therefore pretty much impossible to produce a version of the application that can be deployed on more than one machine - for example for development or test purposes.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All this means that there's a whole series of bear traps set for anyone who innocently changes any of the properties files of the application, in the mistaken assumption that the application will actually take any notice of them.&lt;/p&gt;&lt;p&gt;I'm sure I'm not the only person to have been hit by this problem - how to configure multiple external components which all have their own XML configuration files - &lt;i&gt;without&lt;/i&gt; having to hand-edit each of the XML files each time every time something changes, and &lt;i&gt;without&lt;/i&gt; hard-coding the configuration at build time. However I'm damned if I know of a good way of doing it - although I can easily think up several not-very-good ways of doing it.&lt;/p&gt;&lt;p&gt;If &lt;b&gt;you&lt;/b&gt; know, please let &lt;b&gt;me&lt;/b&gt; know!&lt;br /&gt;&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/categories/work/">Work</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <category domain="http://bleaklow.com:80/tags/work/">work</category>
      <category domain="http://bleaklow.com:80/tags/xml/">xml</category>
      <pubDate>Thu, 05 Apr 2007 14:38:44 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2007-04-05:default/1175783924000</guid>
      <dc:date>2007-04-05T14:38:44Z</dc:date>
    </item>
    <item>
      <title>Hosting a community website using Solaris and Tomcat</title>
      <link>http://bleaklow.com:80/2006/11/27/hosting_a_community_website_using_solaris_and_tomcat.html</link>
      <content:encoded>&lt;p&gt;
Outside of work I'm also a member of a Community-based Samba band, &lt;a href="http://meninos.org.uk"&gt;Meninos do Morumbi Oldham&lt;/a&gt;, along with my son James.  Like most people in the IT business, once people figure out what you do you inevitably get requests to help with anything related to computers, and I got collared to set up a website for the group.  I started looking around for hosting providers, and my original choice was &lt;a href="http://www.bluehost.com/"&gt;bluehost.com&lt;/a&gt;, based on the recommendation of my colleague &lt;a href="http://blogs.sun.com/pgdh/" title="Phil Harman"&gt;Phil&lt;/a&gt;.  However, the membership management application I'm also developing is written in Java, which mean I really wanted to run &lt;a href="http://tomcat.apache.org/" title="Apache Tomcat"&gt;Tomcat&lt;/a&gt; on the site as well, and bluehost didn't offer that option.  Finding a hosting provider who would host Tomcat at a reasonable price proved incredibly difficult - the costs were way more than a non-profit like us could afford.  Eventually I stumbled across &lt;a href="http://mod3.co.uk/"&gt;mod3&lt;/a&gt;, a UK-based hosting provider who offer a &lt;a title="Solaris" href="http://www.sun.com/software/solaris/"&gt;Solaris 10&lt;/a&gt; zone for the princely sum of £9.95 per year, plus &lt;a title="Zone pricing at mod3" href="http://mod3.co.uk/documentation/solaris-zones/zone-pricing"&gt;pay-as-you-go&lt;/a&gt; for network bandwidth, disk space etc.  The fact that they were running Solaris appealed to me, and I was happy to risk the £10 involved out of my own capacious pocket ;-)  The base hosting package also came with 660Mb of usable disk space, which was plenty for our needs.
&lt;/p&gt;
&lt;p&gt;
After purchasing the site domain name and hosting I started to think about what I wanted to put on the site.  You get 64Mb of RSS memory with a base zone config, which meant I needed to be fairly careful with what I ran on the site.  As I said, I knew I'd probably want use Tomcat at some point, so I began to wonder if I could run the whole thing with Tomcat alone.  From previous experience of setting up similar websites before, I know that setting up the site is relatively easy, the real problem is providing content, then keeping it up-to-date and relevant.  I also didn't want to become the bottleneck for making changes to she site, which pretty much meant that I needed to use some sort of &lt;a href="http://en.wikipedia.org/wiki/Content_management_system"&gt;Content Management System&lt;/a&gt;, so that I could give other members of the group the ability to edit content.  Nearly everyone in the organisation is a non-IT type (one of the attractions of the group for me ;-), so whatever I used had to make editing easy - requiring that people hack on raw HTML was a non-starter.
&lt;/p&gt;
&lt;p&gt;
As part of the day job I'm looking at the possibility of using a &lt;a title="Content Management System" href="http://en.wikipedia.org/wiki/Content_management_system"&gt;CMS&lt;/a&gt; for part of the &lt;a href="http://opensolaris.org/"&gt;OpenSolaris&lt;/a&gt; website, so I'd already been looking around at what was available (and free!).  I didn't need an 'Enterprise level' CMS - features such as versioning, content staging, multilingual support or workflow management weren't necessary, what I needed was something easy for users to understand, and that didn't have huge resource requirements.  And being written in Java was a bonus, as it meant I could then run it under the Tomcat instance I already knew I was going to need for the membership management stuff.
&lt;/p&gt;
&lt;p&gt;
My final choice was &lt;a href="http://www.cromoteca.com/meshcms/index.html"&gt;MeshCMS&lt;/a&gt;, and I've been extremely happy with it.  It hit all the key requirements that I had - simple to deploy (single WAR file, no database required), easy to customise, structures the site using the directory/subdirectory paradigm that any PC user is already familiar with, has an integrated &lt;a title="What You See Is What You Get" href="http://en.wikipedia.org/wiki/WYSIWYG"&gt;WYSIWYG&lt;/a&gt; editor for editing content, and the clincher - has very modest resource requirements and fits inside my 64Mb RSS constraint.  MeshCMS has been exceedingly well thought out - designing the look and feel of the site involves just modifying a single JSP template, which is then applied to all the pages.  The site navigation menus are all automatically generated from the layout of the directory hierarchy used to store the page content, and most-frequently accessed pages bubble to the top of the menus.  Linking to other pages in the site is easy - the integrated editor provides a dynamically-generated list of pages that you can select from.  The editor even provides a list of the styles defined in the site stylesheet for you to select from - a feature that &lt;a href="http://rollerweblogger.org/project/"&gt;Roller&lt;/a&gt; (the package used to run blogs.sun.com) could well do with emulating.
&lt;/p&gt;
&lt;p&gt;
Having decided on the CMS, the next task was to see if I could minimise Tomcat's footprint as far as possible.  Tomcat runs as a normal Unix process, and so doesn't have permission to open low-numbered ports (below 1024), which is why by default it runs on port 8080.  Webservers normally run on port 80, and using that port requires root privilege.  The &lt;a href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt; webserver gets around this problem by starting up as root, opening port 80 then switching user to the webserver user before starting to serve pages.  However Tomcat is written in Java, so Unix-centric mechanisms like switching user aren't an option.  The normal way to get around this is to put Tomcat behind Apache, using the &lt;a href="http://tomcat.apache.org/connectors-doc/howto/apache.html"&gt;mod_jk&lt;/a&gt; module to shunt traffic between the two.  However because of my memory constraints, I wanted to avoid using Apache if at all possible.  There are a number of &lt;a href="http://www.klawitter.de/tomcat80.html"&gt;fairly vile hacks&lt;/a&gt; for doing this for Linux, including stuff such as firewall or userland port redirection, but most of them suffer from various &lt;a href="http://www.mooreds.com/weblog/archives/000223.html"&gt;problems&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
 However because I was running on Solaris, I had a far better option.  I was already intending to run Tomcat as a &lt;a title="Service Management Facility" href="http://www.sun.com/bigadmin/content/selfheal/smf-quickstart.html"&gt;SMF&lt;/a&gt; service, and one of the lesser-known features of SMF is that it is integrated with the Least Privilege mechanism in Solaris 10, which allows you to grant elevated privileges to normal user processes in a controlled way.  This meant that allowing Tomcat to open port 80 simply required granting it the &lt;code&gt;net_privaddr&lt;/code&gt; privilege:
&lt;/p&gt;
&lt;pre&gt;
    &amp;lt;method_credential user='meninos' group='staff' privileges='basic,net_privaddr' /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
The really neat thing is that I didn't have to give the meninos user the &lt;code&gt;net_privaddr&lt;/code&gt; privilege permanently, it only needs it for the duration of the service start method.
&lt;/p&gt;
&lt;p&gt;
So, if you are ever in the Greater Manchester area, check out our &lt;a href="http://meninos.org.uk/performances/"&gt;&lt;span style="text-decoration: underline;"&gt;performances&lt;/span&gt;&lt;/a&gt; page on the &lt;a href="http://meninos.org.uk/" title="Meninos Do Morumbi Oldham"&gt;website&lt;/a&gt; and if you get a chance, pop by and hear us play ;-)  We were out &lt;a href="http://en.wikipedia.org/wiki/Busking"&gt;busking&lt;/a&gt; in Manchester &lt;a href="http://meninos.org.uk/performances/diary/26nov2006.html"&gt;yesterday&lt;/a&gt;, and for once the weather was kind, despite the time of year :-)
&lt;/p&gt;</content:encoded>
      <category domain="http://bleaklow.com:80/categories/tech/solaris/">Solaris</category>
      <category domain="http://bleaklow.com:80/categories/tech/web/">Web</category>
      <category domain="http://bleaklow.com:80/categories/drumming/">Drumming</category>
      <category domain="http://bleaklow.com:80/categories/tech/">Tech</category>
      <category domain="http://bleaklow.com:80/categories/tech/java/">Java</category>
      <category domain="http://bleaklow.com:80/tags/drumming/">drumming</category>
      <category domain="http://bleaklow.com:80/tags/java/">java</category>
      <category domain="http://bleaklow.com:80/tags/least privilege/">least privilege</category>
      <category domain="http://bleaklow.com:80/tags/meshcms/">meshcms</category>
      <category domain="http://bleaklow.com:80/tags/music/">music</category>
      <category domain="http://bleaklow.com:80/tags/solaris/">solaris</category>
      <category domain="http://bleaklow.com:80/tags/tech/">tech</category>
      <category domain="http://bleaklow.com:80/tags/tomcat/">tomcat</category>
      <category domain="http://bleaklow.com:80/tags/web/">web</category>
      <category domain="http://bleaklow.com:80/tags/zones/">zones</category>
      <pubDate>Mon, 27 Nov 2006 02:54:59 GMT</pubDate>
      <guid isPermaLink="false">tag:bleaklow.com,2006-11-27:default/1164596099000</guid>
      <dc:date>2006-11-27T02:54:59Z</dc:date>
    </item>
  </channel>
</rss>

