Friday, January 28, 2011

Metawidget: PrimeFaces support

The guys over at Activiti recently expressed an interest in integrating Metawidget into their BPM product. They had a few concerns, most notably PrimeFaces support, so I thought I'd have a go at implementing it.

I'm delighted to say that, thanks to PrimeFaces' solid build quality and outstanding User Guide (over 400 detailed pages!) integration went very smoothly. There were a few minor glitches related to Mojarra which I will be working with that team to get resolved. But MyFaces works great.

I have checked the code into SVN ready for the Metawidget v1.10 release. I have also put together a sample project demonstrating PrimeFaces support which you can download here.

Thursday, January 27, 2011

HttpClient 4: Want To Make It 250x Faster?

I just spent a few hours debugging a performance problem with my app. It came down to a default setting inside Apache HttpClient 4.0.3.

Don't get me wrong, HttpClient is an awesome piece of work and a fantastic contribution to the community - I use it in lots of my projects and it's very useful. So my thanks to the HttpClient team for all their hard work.

However, by default HttpClient 4.0.3 adds a...

Expect: 100-continue

...header to every POST request. This appears to interact badly with Tomcat's (and JBoss', and possibly other containers) FormAuthenticator. Specifically somewhere around...

request.getParameter( Constants.FORM_USERNAME )

...FormAuthenticator disappears into a hole (during Request.parseParameters) for some 2 seconds before emerging with the parameters. It appears to be 'lazy loading' the request body during this time? According to the HTTP spec the header "allows a client that is sending a request message with a request body to determine if the origin server is willing to accept the request before the client sends the request body".

If you're using HttpClient to log in to your Java EE server (say, for black box testing) this can be a significant performance hit. Removing the Expect header logs you in in about 8ms, some 250 times faster.

You can remove the Expect header by doing:

client.removeRequestInterceptorByClass( RequestExpectContinue.class );

I've put together a sample WAR to reproduce the problem, along with deployment instructions, under this issue here.

Update: it appears this is actually a bug in Tomcat 6. Now tracking under this issue here.

Wednesday, January 19, 2011

Metawidget: Dynamic Layouts

I was recently asked whether Metawidget can change layouts dynamically, say from a tab-based layout to a panel-based layout?

The answer is yes! You can call...

metawidget.setLayout( myLayout );

...at any time to dynamically update the layout. The questioner was asking in relation to JSF, and the hardest bit in JSF is actually getting programmatic access to the Metawidget. This requires the binding attribute I've blogged about previously.

But once past that, you can put together something like this:

Note the buttons at the buttom that allow you to select which layout to use. I have put together the complete project you can download from here.

Monday, January 3, 2011

Grokking Seam Forge: Part 1

JBoss have just released Alpha 1 of Seam Forge, their framework for rapid-application development that includes Metawidget support.

You can read more about the release and how to use it here. After that, for those wanting to dive into the code (either out of curiosity or to start contributing) here's a step-by-step guide that may save some trial and error:

Install JBoss Tools

  • Download Eclipse 3.5 SR2 (just the 'Eclipse IDE for Java Developers' version)

  • Download JBoss Tools 3.1.GA

  • Unzip Eclipse, and run eclipse.exe

  • Select a workspace (I'd recommend starting a new one)

  • Use Help > Install New Software. Click Add then Archive (see screenshot):
  • Click OK

  • Check All JBoss Tools - 3.1.1. Click Next and Next again

  • Choose I accept the terms of the license agreements and click Finish
    (NB. there seems to be a bug here: the Finish button will not always be enabled? I found clicking back to the start of the wizard fixed it)

  • Wait for the install to complete. Accept any signing certificates. Restart the IDE
Install EGit

  • Use Help > Install New Software and click Add

  • Enter a Location of http://download.eclipse.org/egit/updates (see screenshot):
  • Check Eclipse Git Team Provider. Click Next

  • Click Finish

  • Wait for the install to complete. Accept any signing certificates. Restart the IDE
Clone the Seam Forge Repository

  • Use File > Import and choose Projects from Git (see screenshot):
  • Click Clone... and enter a URI of git://github.com/seam/forge.git (see screenshot):
  • Click Next, choose the Master branch, click Next (see screenshot):
  • Click Finish. Wait for the Git repository to clone (may take a while). See screenshot:
  • Click Cancel (not Next!)
Install Maven

  • Use Help > Install New Software

  • Choose to Work with the 'Maven Integration for Eclipse Update Site'

  • Check the 'Maven Integration for Eclipse' box (see screenshot):
  • Click Next, Next, accept the license terms and Finish

  • Wait for the install to complete. Accept any signing certificates. Close the IDE (don't restart it)

  • Edit eclipse/eclipse.ini and add the lines in bold:
    --launcher.XXMaxPermSize
    256m
    -vm
    <path to your JDK>\bin\javaw.exe

    -vmargs
    -Dosgi.requiredJavaVersion=1.5

    (Maven needs Eclipse running under a JDK, not a JRE)

  • Relaunch the IDE
Import Maven Projects

  • Use File > Import. Choose Maven > Existing Maven Projects (see screenshot):
  • Browse to the location of the Git clone (see screenshot):
  • Click Finish. Wait for import of Maven projects (may take a while)
All Seam Forge sub-projects should now be listed under the Package Explorer. There should be no compile errors under the Problems tab, though there may be warnings (as this is still an alpha release). See screenshot: