Friday, 3 October 2008


@BeforeClass on a setup ensures Spring has bootstrapped properly.

Wednesday, 1 October 2008


@Test(groups= { "unit" }, expectedExceptions = { AnException.class } )

Saturday, 5 April 2008

Saturday, 15 March 2008

Dynamic Java Applications

I am investigating best ways of deploying new functionality to my running application at runtime, without having to restart my application.

OSGi framework is the way to go! (Feel free to read other options below, but OSGi seems to be the way to go - if you can)...

- OSGi framework - Have any of the framework implementations been used for any significant sized systems?

OSGi Wikipedia

- OSGi implementations

Equinox OSGi
Embeded Server Equinox OSGi

OSGI, SCA and Spring

- Creating/recreating a Classloader. You can do this by hand with Java but I would prefer to not have to play with this. Weblogic 9/10 has a ChangeAwareClassLoader which could be of use, but in general, dropping / recreating the class loader is too heavy weight for my requirements, I just want to make available small units of change, maybe sometimes just a new class or a single code line change ie. to fix a bug. If I ditch the classloader, my calling threads will have to block until the application has sorted itself out.

- Hotswapping (Java Rebel or Weblogic 10.3 has FastSwap)

Much of the motivation behind hotswapping so far appears to be around speeding up development cycles. The hotswapping revolves around deploying your app as (ie. an exploded WAR file and compiling up source directly into the WEB-INF/classes dir where the new class will be picked up.

Weblogic 10 is offering FastSwap, but it only works if weblogic server is running in development mode.

Java Rebel will run in Weblogic 9 and 10 (plus a bunch of other app servers). Java Rebel is not recommended for production use at present though. JavaRebel dev team are aiming for Q4 2008 to getting out a beta version.

So hotswapping, for the time being, does not work reliably for production servers.

- Deploy new service on another server? - I could leverage a SOA principle 'discoverability' to discover a new service on the fly. However, I don't want the overhead of making a remote call (which this would have to be using this approach, unless I was running with SCA and OSGi for example), I still have SLA's on round trip times to support regardless, and making a remote call is not going to help.

- COTS support for adaptability?

IBM bought BowStreet in 2005 who offer an adaptable framework, although I cannot seem to find any info on the product.

- Academic research

There are a few papers written on adaptive middleware platforms. These appear to be largely academic excerices though.

- Java 7

JSR-292 talks about support for dynamic typed languages, specifically scripting languages, but does mention hotswapping as well. JSR-292 The main motivation behind this appears to be for adding support to call scriping languages.

- Beanshell could be used, in fact there are a number of different scripting options available, jython etc.. But I am not sure whether they allow change at runtime and whether they will compile on the fly or whether the scripts are all interpreted?

- Java Assist. There is a nice clean API available for bytecode instrumentation, which will the job, you could even point the classpath to point to a jar file sitting on a remote web server, (although I am sure security would have a thing to say about that!).. Once Java has loaded a class, it will not reoad it (unless running with JPDA switched on), but you can change the class at runtime so this would be fine for my purposes. I could even publish a JMX api with appropriate authentication to allow ops to remotely deploy new classes in a stream. But if OSGi really does the job, I am not sure it is worth rolling my own framework for this.

Source article summarising the current state of play

Weblogic FastAwap

Java Rebel

Friday, 7 March 2008

Parallel Processing in Java EE 5

There are a number of options. It depends on your situation as to which is the right choice:

- Use JMS and message driven pojo's/beans

This is a strategy that is often used. You have a choice over whether you want to make the JMS persistent or not. If your JMS queue is not persistent and the server fails, you can lose messages and therefore some of your processing is not guaranteed to complete. So if you want guarantees that all the processing will be performed then you should make your queue persistent.

- Java 5 Concurrency API

The concurrency API is an addition in Java 5. It will allow you to execute work in parallel safely within a J2EE container, however, for typical Master/Worker pattern processing the API does expose you to more complexity than you need.

- Work Manager API - JSR 237

Weblogic has a work manager API (available in Weblogic 9). I like the API as it is clean and simple to use. If you are a J2EE purist however, and you want your J2EE to remain portable, then this is not for you.

- Java EE 6

Java EE 6 will include an evolved version of JSR 237. Doug Lea is working on this:

- Use Terracotta (or Gigaspaces) and distribute your units of work across JVM's. Grid products like these two seem to be gaining rapidly in popularity. The technology is being used in Investment banks where systems are processing high volumes of transactions per second and the technology seems to back the trend of scaling by having more processors doing the work (dual core, quad core etc.). Terracotta works by using bytecode instrumentation (basically taking your java class and inserting some extra logic to allow synchronization etc. across multiple JVM's). Terracotta supports the Master/Worker pattern to allow you to distribute your units of work across multiple JVM's.

- Use business process management software (JBPM / WS-BPEL) which provide parallelism. Webloigc Integration for instance allows you to define a 'flow' which is some processing that can be performed in parallel.

- Parallel processing frameworks like JPPF, Gridgain, Hadoop.

- Spring batch

Sunday, 24 February 2008

Business rules and soa

Soa service API ideal for common services like exchange money.
Service could become industry standard and money houses provide
implementations in their various languages.

Qos elements security, reliable messaging.

Component based philosophy is bring oo concepts to component level,
soa brings these loosely coupled components together.

The components can be built in a layered architecture too so all
bussiness util comes sit in same layer ie address book service can
then be reused by other layers.

Saturday, 23 February 2008

Esoteric, predicates and declarative language

Esoteric - bunch of info only known by select few

Predicates - statements that are true or false

Declarative language the outcome is same whatever order of execution

Nomenclature - proper name

Sent from my iPhone

Sunday, 17 February 2008


SCA defines a mechanism for defining components and how they work with each other.

SCA is language agnostic.

SCA does define its own programming model but you can use other programming models like BPEL or Spring framework for example within a component.

SCA defines common assembly model.



Mojo is a maven plugin.

Historically, MOJO is a play on POJO (Plain-old-Java-object), substituting "Maven" for "Plain". Mojo is also an iteresting word (see definition ). From Wikipedia , a "mojo" is defined as: "...a small bag worn by a person under the clothes (also known as a mojo hand). Such bags were thought to have supernatural powers, such as protecting from evil, bringing good luck, etc."

SOA Design Points

It is good from a design perspective to separate out api from implementation.

SOA and service-orientation are implementation-agnostic paradigms that can be realized with any suitable technology.

Loose coupling - Services maintain a relationship that minimizes dependencies and only require tat they retain an awareness of each other.

Service contract - Services adhere to a communications agreement, a defined collectively by one or more service descriptions and related documents.

Autonomy - Services have control over the logic they encapsulate.

Abstraction - Beyond what is described in the service contract, services hide logic from the outside world

Reusability - Logic is divided into services with the intention of promoting resuse.

Composability - Collections of services can be coordinated and assembled to form composite services.

Statelessness = Services minimize retaining information specific to an entity.

Discoverability - Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms.


Services understand each other through use of service descriptions (ie. wsdl) A service description has a name and location of service. The manner in which services use service descriptions results in a relationship classified as loose coupling.


SOA is a term that represents a model in which automation logic is decomposed into smaller, distinct unit of logic. Collectively, these units comprise a larger piece of business automation logic. Individually, these units can be distributed. (Note: City scenario, lots of businesses some offer same services etc.. but agree on common language, common currency..)


The concern addressed by a service can be small or large


Asus laptop


Sunday, 27 January 2008

Why I ditched Seam 2

I recently started using Seam to help develop a web application running under Weblogic. In the end I ended up ditching it and going with myfaces JSF.

Reasons for ditching Seam included:

I was not using EJB3 so did not benefit from the tight integration between JSF and EJB programming models.

There were 2 files controlling navigation faces-config.xml (myfaces) and pages.xml (Seam) which seemed a little confusing. I think in practice you should keep the faces-config.xml pretty empty and just use the Seam pages.xml.

Seam 2 does not run under jetty as there is an EL library mismatch.

The test framework is great if you use test NG. If you have to use JUnit, then you need to port the test ng classes to use junit 4 annotations and then try and get the test framework / Seam to bootstrap itself which seems to involve getting an embeddable EJB runtime up and running as Seam uses Stateful session beans to help support its conversational state.

When plugging in a custom JAAS module The security mechanism employed by Seam led me to believe it might plugin nicely with JAAS, but reports on the web led me to believe getting this to work with a Weblogic JAAS module might not work.


I did have to spend time producing maven pom to get it to build under maven too. This is documented here
so did not take too long, just another thing to consider.

The support on the Seam forum was not great. I posted a couple of questions and got no response. My feeling towards open source is that I know people do it for free but if they are actively going to encourage people to use their frameworks then they should support them properly.

I am not saying Seam is bad at all, but I was not getting much benefit from using it over JSF apart from a couple of nice annotations.

Friday, 25 January 2008

JPA Mapping Tips

Personally I prefer the annotations on the fields as it makes it easy to locate the annotation and change it.

JPA Tips

Interestingly (or not as the case may be), how the JPA implementation decides whether to look for a annotation on a method or a field is how you annotate the @Id. If the id is annotated on the field, then the JPA implementation expects to find the rest of the annotations on the fields. This is interesting because if you have a class with two attributes and you choose (for some bizarre reason) to put the annotation for field a on the attribute and for field b on the method, then chances are your annotation for field b will be ignored. (Well it will be if you are using Hibernate as your provider at least).

Maven dependency browser

Dependency Browser

Free maven book

Better builds with maven

Infrastructure software

Maven repository Artifactory
Continous integration server Bamboo
Bug tracking Bug tracking
View Source Repository Fisheye

Switch off javascript in myfaces

In web.xml setup a context-param section and setup parameter name:


Useful maven commands

To download source code into your maven repo:

mvn eclipse:clean eclipse:eclipse –DdownloadSources=true

Another example:

mvn -r -N -U -cpu -fae clean install

-r Execute goals found in the reactor (the reactor is a maven feature whereby maven decides what to build first based on the dependency graph)
-N Do not recurse into sub-projects
-U Update snapshots
-cpu Check plugin updates
-fae Fail at end (ie. keep building if one module or test fails)

Wednesday, 23 January 2008

Remote Debugging with Weblogic 9

Go to your weblogic domain.

Edit file setDomainEnv.cmd inside the bin directory within your domain.

Go to line 80 and type:

set debugFlag=true

Start weblogic and connect to default port 8453 (which is specified in setDomainEnv.cmd if you need to change it).

Remote Debugging with Maven 2

set MAVEN_OPTS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8008,server=y,suspend=y