Tuesday, February 17, 2009

Seambay modifications to access Seam Annotations

This post extends my last one about accessing Seam from the command line. Here I describe the transition from using EntityManager to using EntityHome.

The first thing I did was to create a new folder for the webSevice sources, which meant that I had to add this directory into the build.xml file and add all of the libraries into the compile path in NetBeans (both of which are obvious, but both of which I always forget to do).

The next was to make my action work similarly to an .xhtml page and interact with a home object rather than directly with the EntityManager
going from:

      
if (fileData == null) {
fileData = new FileData();
// various actions on fileData
entityManager.persist(fileData);
}

to
       
if (fileData == null) {
fileDataHome.create();
fileDataHome.persist(); //side effect of creating the defined instance
fileData = fileDataHome.getDefinedInstance();
// various actions on fileData
fileDataHome.update();
}


which also required adding these lines to components.xml

xmlns:transaction=”http://jboss.com/products/seam/transaction”   
....
<transaction:ejb-transaction/>


None of which was particularly difficult and I was up and running in a hour or so.

Monday, February 2, 2009

Seam From a Command Line

I recently wanted to access some seam derived functionality from a command line java program (something that I could run via cron). I ran into a few minor problems and thought I'd share their solutions.

The first problem was that seam annotations like @Logger won't work. I guess it isn’t that surprising, but the jboss seam annotations are unavailable to a command line program (at least not easily) since the portions of the framework that enables these annotations are designed to operate within a server.

This was disappointing. The @Logger annotation is really useful, but I couldn't come up with a way to get it going.

This pushed me into wanting to use web services as much as possible to take advantage of other annotations that I had built into my system, e.g., the ability to automatically stamp an object with time modified and time created to support temporal data operations.

I did not find the seam documentation about accessing seam web services particularly clear (especially when using netbeans) so I turned to the netbeans tutorial and was quickly up and running with the seambay example.

Note:
    The WSDL for the seambay example is found at (assuming your server is local and you have deployed the seambay example) http://localhost:8080/jboss-seam-bay-jboss-seam-bay/AuctionService?wsdl

    An overview of all services at the host (again, assuming your server is local) appears at
    http://localhost:8080/jbossws/services.