Friday, October 05, 2007

Using spring's webflow package

As an architect I get a lot of challenging questions.
Like this week, a team of the company I am currently working for needs to migrate a number of simple applications written in PHP to a J2EE environment.
In addition to this, the first release will run as standalone web applications while in the (near) future they need to be incorporated into the soon to be released company web portal.
So I needed to come up with a way that simplifies the transition of a web application into a portlet application.
Since almost any web application can be in different states, as is the case with these applications, I thought of Spring's webflow package.
Spring's webflow uses either Spring Web MVC or Spring Portlet MVC underneath, so is it possible to easily swap either of them without changing the code?

Let's find out...

Wednesday, September 26, 2007

Java coding tips

This page, 7 Top Tips for Quality Java Software, contains some really useful tips. Although most of it seems common sense to me, it did reactivate the associated neurons in my brain.
Good piece Jason!

Monday, July 16, 2007

Using Alfresco's WCM

Alfresco is supplying a nicely looking evaluation guide for using their Web Content Management package.
After briefly giving an overview of the Web Content Management Package, a scenario can be followed along while reading.
The scenario describes using Alfresco WCM with a couple of different users, each having a different role in the system.

I followed this scenario from creating new users and assigning roles to them, creating a new web project, creating new web forms for the project, etc. until I came to the point of creating new web content. When trying expand the list of web forms next to my sandbox, I stumbled into a NullPointerException:

So a good citizen of the open source world, I immediately went to Alfresco's issue tracker and found a report about this issue (WCM-486).

Sadly this prevents me from finishing the scenario, So today I will see if the issue report can help me fix this on my system.

Thursday, July 12, 2007

How to setup a WCMS

OK I am going to try to setup alfresco 2.0 WCM on JBoss AS using Hypersonic SQL as database.
I am using HSQL because the can easily be zipped and distributed to fellow developers.

As usual I'll first create a dedicated server configuration and name it alfresco20, this instance can be started using <jboss-root>/bin/ -c alfresco20.

Upfront I know that the alfresco.war must be deployed exploded in JBoss. So the war file is unzipped into <jboss-root>/server/alfresco20/deploy/alfresco.war.

Two issue's arise immediately:
  1. Alfresco has a version of log4j packaged in the war, this generates ClassCastExceptions, so the log4j is removed from alfresco.war/WEB-INF/lib.
  2. The log4j configuration in JBoss lacks a root logger, and alfresco generates a lot log messages, so I opened <jboss-root>/server/alfresco20/conf/log4j.xml, and added <level value="warn"/> to the <root> element.
Configuring HSQL as database for alfresco is properly documented at the alfresco wiki, I know because I did it myself ;-)

When starting JBoss, after quite a while and a lot of warn and info log messages on the console, the server is started. Checking the base functionality at http://localhost:8080/alfresco shows the login page.
But this merrily is alfresco's CMS not the WCM version, so stop the server again, either via the jmx-console or using Ctrl-C.
According to the readme that comes with alfresco's WCM, the wcm-bootstrap-context.xml file needs to be placed in the <jboss-root>/server/alfresco20/conf/alfresco/extension directory.

That should be it, unless the website preview feature is needed. For now lets first try if this works as suggested. After starting JBoss again using the above command, the server starts without a problem, and when browsing to the alfresco page, I get presented with the login screen. So the JBoss server appears to be working fine.
Now lets start the virtualization server.

Out of the box, the virtualization server did not need any configuration and it started without any problem. Great.

Now I want to evaluate the functionality supplied, but that'll have to wait till next time.

Wednesday, July 11, 2007

Alfresco Content Package

One of my colleague suggested to look at ACP, Alfresco's content package. This could be useful in the publication of content from one repository into the other, but we have a JCR compliant repository on the published end, not necessarily an Alfresco repository.

An ACP package is a zipped directory structure, that has the extension '.acp'.
When doing an export, an acp file is created inside alfresco itself, in a space that can be arbitrarily chosen.
Besides the target space, the package name must be provided.
The acp file, assuming package as package name, has the following structure:

The package.xml has a proprietary XML structure and looks like:
<?xml version="1.0" encoding="UTF-8"?>
<view:view xmlns:view="">
<view:exporterVersion>2.0.0 (build-185)</view:exporterVersion>
<cm:content xmlns:nt="" xmlns:alf="" xmlns:d="" xmlns:view="" xmlns:act="" xmlns:wf="" xmlns:app="" xmlns:ver="" xmlns:usr="" xmlns:cm="" xmlns:sv="" xmlns:mix="" xmlns:jcr="" xmlns:wcm="" xmlns:wca="" xmlns:sys="" xmlns:wcmwf="" xmlns:rule="" xmlns:fm="" xmlns:bpm="" xmlns:custom="custom.model" xmlns="" view:childName="cm:index.html">
<cm:description>Index page for books</cm:description>
<cm:author>Stephen King</cm:author>
<cm:content xmlns:nt="" xmlns:alf="" xmlns:d="" xmlns:view="" xmlns:act="" xmlns:wf="" xmlns:app="" xmlns:ver="" xmlns:usr="" xmlns:cm="" xmlns:sv="" xmlns:mix="" xmlns:jcr="" xmlns:wcm="" xmlns:wca="" xmlns:sys="" xmlns:wcmwf="" xmlns:rule="" xmlns:fm="" xmlns:bpm="" xmlns:custom="custom.model" xmlns="" view:childName="cm:DarkTower.pdf">
<cm:author>Stephen King</cm:author>
<cm:content xmlns:nt="" xmlns:alf="" xmlns:d="" xmlns:view="" xmlns:act="" xmlns:wf="" xmlns:app="" xmlns:ver="" xmlns:usr="" xmlns:cm="" xmlns:sv="" xmlns:mix="" xmlns:jcr="" xmlns:wcm="" xmlns:wca="" xmlns:sys="" xmlns:wcmwf="" xmlns:rule="" xmlns:fm="" xmlns:bpm="" xmlns:custom="custom.model" xmlns="" view:childName="cm:Cover.jpg">
<cm:author>Stephen King</cm:author>

This view does contain most of the information I need. The jcr system view as exported by alfresco, lacks the mime type, which is included in alfresco's acp descriptor:

Maybe I am overseeing something, but shouldn't the mime type info be part of JCR's system view as well?

Thursday, July 05, 2007

Custom JCR node types in Alfresco

With the document "Working with Custom Content Types" on my desk, I started to develop my own content model to be used in alfresco.
Naive as I can be, I tried to convert the jackrabbit based cnd into alfresco's content definition. Obviously that failed, alfresco does not support multiple inheritance. Alright, that one can be circumvented.
After deploying, correcting and re-deploying the model until satisfied, I tried to add the model to the web client user interface, but it was not accepted. It appears that if you want to expose your custom content model to the web client user interface, the defined types must extend cm:content or one of its descendants. Sadly this is not mentioned in the named document.

Tuesday, June 19, 2007

Problems exporting content

The export process seemed to work fine, until I took a close look at the actual exported XML.

It appears that the actual content is stored in a binary format, which prevents adjustments within the actual HTML itself, like references to content stored in the same repository.

To try to circumvent this, I changed the cm:content property of the cm:content type, as defined in alfresco's contentModel.xml, to d:text instead of d:content, but this gave the following error:

11:11:58,926 ERROR [Utils] A system error happened during the operation: The node property must be of type content:
  node: workspace://SpacesStore/221a7c69-1e45-11dc-a1bf-4985acca4591
  property name: {}content
  property type: {}text

So its time to create our own model for alfresco.

Monday, June 11, 2007

Exporting content from Alfresco

The JCR defines a standard format for importing/exporting content: the system view mapping. So how can I export a particular node from alfresco as final part of a work flow?

First I need to create a simple work flow in alfresco that allows me to edit content and then mark that content for publication. In alfresco I created a space to contain draft content and a space to contain to be published content. I added a rule to the draft content space that allows the author to submit content for publication, this rule copies the selected content item to the publish space.

I added another rule, this time to the publish space, that activates the publication process. For this a custom alfresco 'action' is developed that exports the selected node to an XML stream that complies to the JCR system view.

The resulting XML stream must be converted because it contains e.g. node types that are not supported on the serving repository. So these node types must be converted into supported node types.

The conversion is implemented using the Java rules engine API (JSR-94). This API defines how rules engines can be acquired and used, it does not describe how rules are defined.

Using the Java rule engine API allows changing the rules engine without the need to change the code. For starters I chose JBossRules as rule engine.

Publishing content

The company I am currently working for wants its new website implemented using a JBoss Portal system.
The current website uses Apache Lenya as CMS but with a nightly export to static HTML pages. This prevents instant publishing of single items.
Some of the entry pages contain lists showing recently changed items, news items etc. These lists are handcrafted while based on certain criteria, these lists could be generated automagically.

Other area's of the companies presence on the internet provided web applications like my.epoline and esp@cenet, these applications, and others, need to be part of the main website, hence a portal solution is chosen.
Based on some demo content, portlets have been developed that shows the content and provides means of navigating through the content.

In the architecture it has been chosen that each portal server instance will have its own dedicated read only JCR compliant repository (A.K.A. the rendering repository), physically separated from the CMS's repository (A.K.A. the authoring repository).

Since content written by authors in the end will have to enter the rendering repositopry, we need a process that takes care of that, the publication process. Currently I am working on that publication process.

As CMS system we have chosen alfresco. So my first task is to get alfresco up and running on JBoss on my dev box.

Since I don't like prepackaged downloads, I downloaded the war file package of alfresco 2.0, the alfresco sdk and the alfresco WCM package.
I wanted to create a dedicated JBoss server instance for alfresco so I copied the default server configuration and named it alfresco. I dumped the war file in JBoss's deploy directory, changed the database configuration following the database configuration topic at alfresco wiki.

The app server started up fine, so far so good...

Next thing, exporting content, is the subject of a future posting.

CU then

Thursday, May 10, 2007

Naming conventions

Naming conventions are a good thing, there's no doubt abou that.

But its usually quite difficult to establish a proper naming convention, so its far eassier to use an existing naming convention that can be ammended if needed. On a project exists that establishes such a naming convention for J2EE projects, very handy!

Friday, April 20, 2007

Using JConsole

I updated my eclipse to version 3.2.2, lucky me did not remove the previous version just yet, and run into a crashing system that seems to run out of memory. So I decided to connect jconsole to eclipse to view its memory consumption.
To do so I needed to start eclipse using JDK 5, with the system property
Now JConsole is able to connect to the eclipse process and show its memory consumption.

After playing a while with eclipse the OOM exception hapened again, but saidly JConsole has lost its connection, so nothing to see what/.where had happened.

The story continues...

Tuesday, April 03, 2007

Mocking a base class

The next problem that arose when trying to unit test my portlet, is that my portlet implementation calls some methods of its base class, javax.portlet.GenericPortlet. How can these method calls be mocked?

In the unit test implementation an inner class is defined that extends the class under test.
This inner class can then mock any base class method called from the class under test:
public class MyPortletTest extends TestCase {

private PortletContext portletContext = EasyMock.createMock(PortletContext.class);

protected void setUp() throws Exception {

// Use the inner class derived from the actual CUT that provides
// overrides for the base class methods.
testObject = new TestObject();

// Additional methods removed for clarity...

* Need to extend the portlet under test for overriding base class methods.
private class TestObject extends MetaInfoPortlet {

* A mock needs to be returned
public PortletContext getPortletContext() {
return portletContext;
Using this scheme one can override any of the base classes methods used in the class under test (CUT), and provide a mock based implementation.

Thursday, March 29, 2007

EasyMock and IllegalStateException

When writing a portlet and trying to unit test it, you definitly need somekind of mock implementation. I chose to use EasyMock 2.2 for that purpose because I think its easier to use. I will not explain nor defend this decision.

I have been using EasyMock for some time now, and every now and then I stumble over the problem IllegalStateException problem. Sometimes this is caused by not having 'replay'ed the mocks, but now its different. The stack look s like this:
java.lang.IllegalStateException: 2 matchers expected, 1 recorded.
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(
at org.easymock.internal.ExpectedInvocation.(
at org.easymock.internal.ExpectedInvocation.(
at org.easymock.internal.RecordState.invoke(
at org.easymock.internal.MockInvocationHandler.invoke(
at org.easymock.internal.ObjectMethodsFilter.invoke(
This exception is thrown when executing request.setAttribute(MetaInfoPortlet.BEAN_ATTR, EasyMock.anyObject());.

So why is this excpetion being thrown at me? The message gives a hint, 2 matchers expected, recorded 1. So it lacks a matcher...

If I now change the code to request.setAttribute(EasyMock.matches(MetaInfoPortlet.BEAN_ATTR), EasyMock.anyObject());, it works fine. Now why is this? If I change the code to request.setAttribute(MetaInfoPortlet.BEAN_ATTR, "something");, it works as well, but now I get the following:
Unexpected method call setAttribute("bean", {test=Let's see if this tst value comes through?}):
setAttribute("bean", "something"): expected: 1, actual: 0
So it looks like the you either have to supply your mock with fixed values or you have to supply it with matchers, as it says in EasyMocks documentation: "If you would like to use matchers in a call, you have to specify matchers for all
arguments of the method call.

Bottom line: read the documentation.

Wednesday, March 21, 2007

JSTL and JSP Expression Language used in JSP 2.0

The release of the JSP 2.0 and servlet 2.4 specification has changed the way expressions are used within JSP pages.
From now on you can use expressions throughout the whole JSP page.
There appeared to be some limitations though, when mixing expressions with tags, you can only use expressions within tag attribute values.
So name is ${}. is perfectly legal, as well as href="${link.url}" />But ${attrName} is not.

When trying to figure this out, I stumbled over several issues before I got the desired output. First you must declare your application as a 2.4 webapp using the following declaration:

<web-app xmlns=""
xsi:schemaLocation=" web-app_2_4.xsd"
version="2.4" />

When using the JSTL taglibrary, you must be aware that the taglib url is different, jsp is added prior to jstl within the URL.

For 2.3 webapps you should use taglib <%@taglib uri="" prefix="c"%> while for 2.4 webapps you use <%@taglib uri="" prefix="c" %> />

Using Performancing when blogging

Today I figured out how the performancing firefox extension must be configured, so this will be the very first post I do from firefox.

I think this can become a very handy tool that eases posting to my blog!

Some interesting features are the use of a rich text editor.

See ya next time.