Tuesday, July 29, 2008

Cairngorm and Flash Event

For my Flex project at work, I use Cairgorm as the MVC framework. Not that I like Cairgorn a lot but at the time our project starts it seems to be the de-facto framework for mid-to-big-mess Flex applications. Adobe also stands behind Cairgorm in supporting and consulting it.

The learning curve is not so steep. I pick up the tutorial material available at Adobe website, specially the animated diagram is very helpful and learn to use the framework in less than a day. The second day I already begin to integrate it into our application.

One thing annoys me most about this framework is that there is no way (sort of) for the UI to get notified when a remote call is done getting data and the result is available. I end up use some hack to get around it. For example, use a ChangeWatcher to monitor the model. When the result ready, the command object updates the model, just triggers the ChangeWatcher's propertyChange event.

This is kind of messy and the more I use ChangeWatcher, the more I tend to stay away from it if I could. Until I find a solution...

Remember the event class you must extend from the CairngormEvent (not Flash event)?

You just need to include a function object (yes, a functor) from the UI component you want Cairgorm to notify when the result is ready to the cairgorm event object before dispatching it. The in your command class, when the result come back, just invoke that function object.

Sound complicated? Not so, here it is in code

In your event class:

class SampleEvent extends CairngormEvent


public var someStuff:Object;

public var callbackFunctionObj:Function;


In your Command class

class SampleCommand implements Command, Responder


private var callbackFunction:Function;

public void execute(event:CairgormEvent):void


callbackFunction = event.callbackFunction;


public void result(event:Event):void


// setting your model with the result





In your UI

var event:SampleEvent = new SampleEvent;
event.someStuff = new Stuff()
event.callbackFunctionObj = this.notfyMeWhenDataReady;
public void notfyMeWhenDataReady():void
// do whatever you want when the data is ready here

When the result is ready, the command object will invoke the callback function. Thus in the above example notfyMeWhenDataReady will be called!

Wednesday, February 06, 2008

Guide To Setup A Running WSRP4J - Producer and Consumer

A simple test page with the consumer a portlet in jetspeed 2.1 (Tomcat console above port 8081) and the producer in pluto 1.0.1 release (tomcat console beloew port 8080)

I. Introduction

WSRP is an open standard proposed by OASIS for several years. The spec now is sponsored by a number of
big names like IBM and BEA. There are currently two active implementation of the spec. One is wsrp4j from
Apache foundation (still a incubator project, been developed since 2002). The other one is a subproject of
dev.java.net Open-Portal.

I have been exposed and done lot of development on the Apache's wsrp4j project. Thus, in this guide I will
mainly discuss wsrp4j implementation.

At this point, wsrp4j project is still under heavy development and re-construction. It is almost impossible
to get the trunk snapshot in the project repository and make it work without pulling all your hair out to figure
out how to set it up properly. This mostly caused by the lack of documentation and support from its developers.

Still, there is a stable (enough) revision which we can use to make a perfect wsrp4j environment.
The wsrp4j revison I use here is 440430 along with pluto portal 1.0.1 release for setting up a producer.
Jetspeed 2.1 (latest version currently) will be used as a container for wsrp4j consumer (wsrp4j-proxyportlet).
Of course, you can use pluto to setup wsrp4j consumer as well. But that is very easy to do.
Plus, pluto portal doesn't provide a lot of bell and whistle in the GUI side as Jetspeed portal does.

II. Weapons Needed

- JDK 5
- maven 2.1 for bulding wsrp4j revison 440430
- maven 1.0.2 for bulding pluto 1.0.1
- Tomcat 5 (hosting the wsrp producer)
- Jetspeed 2.1 (hosting the wsrp consumer)

III. The Battle

1. Setting up Pluto 1.0.1

Download the source version of Pluto 1.0.1
Unzip/tar the file and change the build.properties.sample to build.properties
Edit the build.properties file to make sure the path to Tomcat is correct
Maven 1.0.2 is used to build this copy of Pluto so set your MAVEN_HOME accordingly
run 'maven fullDeployment' to build the project.
Once this finish, start your tomcat and point browser to
http://localhost:8080/pluto/portal to test

Shutdown Tomcat before deploying WSRP4J.


2. Obtaining WSRP4J From SVN 440430

Get wsrp4j source in subversion
svn -r 440430 co https://svn.apache.org/repos/asf/portals/wsrp4j/trunk

This version of WSRP4J is built using Maven 2, in our case Maven 2.0.4 was used.

After checking out the source code from Subversion, only a few modifications are needed in order for this version to work correctly.

Enter the source code’s root directory and edit the
build.properties.sample file to include the location of Tomcat:

Then rename this file to

Issue this command to compile WSRP4J:
mvn install

This command will compile and package the consumers and producer as WAR archives.


3. Deploying and Fixing WSRP4J 440430 Producer

The WSRP Test Portlet is located at
this can be deployed via Pluto’s admin interface.

To deploy the producer, copy
producer/target/wsrp4j-producer.war to $TOMCAT/webapps

Only a few fixes need to be implemented in this version of WSRP4J:

There is a missing XML, file copy

This will enable crossContext for the WSRP4J producer. If this is not done the logs show an error
Unable to find dispatcher for context wsrp4j producer

There is also a jar file that needs removing
This causes an exception about a class not being found org.exolab.castor.mapping.Mapping....
Leave the pluto-portal-1.0.1.jar alone.

From the installed version of wsrp, located in


This file needs editing to match the running environment:

* $TOMCAT/webapps/wsrp4j-producer/wsdl/wsrp_service.wsdl needs to have the correct host and port numbers.

!!!Important: Also copy the wsrp4j-config.properties from the wsrp4j-proxyportlet/WEB-INF to the wsrp4j-producer/WEB-INF


4. Setup a test Portlet in the Producer:

Edit $TOMCAT/webapps/wsrp4j-producer/WEB-INF/data/portletentityregistry.xml
This will add the wsrp4j-testportlet to the producer
<application id="0">
<portlet id="1">

definition-id (for Application) = portlet_WebApp_Dir
definition-id (for portlet) = portlet_name in the portlet application
You can find the portlet name in the portlet.xml file in the portlet application.


Extra step: Do this step if you want to test the producer using the consumer inside pluto

Deploy the wsrp4j-proxyportlet.war using the pluto deployment admin interface.

Edit the
The file name can be different. But it alwaays ends with ProducerImp****
Change the port number to match your producer listen port. It is 8080 if you follow this guide from the beginning.

Create a file in TOMCAT/conf/Catalina/localhost/wsrp4j-proxyportlet.xml
This is the content:

<context path="/WSRP4JResourceProxy" docbase="wsrp4j-proxyportlet" crosscontext="true">

Edit $TOMCAT/webapps/pluto/WEB-INF/data/portletentityregistry.xml
Locate the application id for wsrp4j-proxyportlet you deployed earlier. And modify it so that it look similar to this

<application id="7">
<portlet id="0">

There are two important parameters:
The producer id: this is what you get from the file

The portlet handle: this is what you get from the file
$TOMCAT/webapps/wsrp4j-producer/WEB-INF/data/portletentityregistry.xml with
application id is 0 and portlet handle is 1. Hence it's 0.1!!!

One last thing, to display the remote portlet on pluto:
Location the wsrp4j-proxyportlet fragment and make it similar to this

<fragment name="wsrp4j-proxyportlet" type="page">
<fragment name="row1" type="row">
<fragment name="col1" type="column">
<fragment name="p1" type="portlet">
<property name="portlet" value="7.0">
</fragment><!-- end of portlet frag -->
</fragment><!-- end of col frag -->
</fragment><!-- end of row frag -->
</fragment><!-- end of 'page' frag -->

Pay attention to the line
in which 7.0 is what you get from
$TOMCAT/webapps/pluto/WEB-INF/data/portletentityregistry.xml edited earlier above.
Again, application = 7 and portlet = 0. Hence, it's 7.0!!!

Att his point , start TOMCAT and go to
Click on wsrp4j-proxyportlet link. You should be able to see the remote portlet.
If you succeed, congrats and you can move on to setup consumer in Jetspeed 2.1
If you don't ,then please go back and examine the steps above.
Missing one minor step and you could mess up the whole dang thing.


5. Install Jetspeed-2

Download the jetspeed 2.1 installer JAR from
This comes without any demo.

Install the jetspeed by running
java -jar jetspeed-2.1.3-installer.jar

Note: If you install both tomcat producer and jetspeed in the same PC, make sure you have them run on different ports!!!

During the installation, make sure you DO NOT select "Save PSML to Database". Theoretically, you can still can use this option
but I haven't had any chance to learn how to create/edit a page using the database yet.

After the installation, copy these files in your producer TOMCAT/common/endorsed/ to your jetspeed/common/endorsed
xercesImpl.jar, xml-apis.jar

In your jetspeed/shared/lib, make sure you have:
pluto-1.0.1.jar and portlet-api-1.0.jar

Next, deploy the wsrp4j-proxyportlet.war to Jetspeed by copying that file to

You may need to bounce JetSpeed a time or two to get the wsrp4j-proxyportlet exploded

After the wsrp4j-proxyportlet.war get exploded in jetspeed/webapps/wsrp4j-proxyportlet, we need to edit the producer info in this file

Change the port number to the correct one of your producer.

Create a file in TOMCAT/conf/Catalina/localhost/wsrp4j-proxyportlet.xml
This is the content:

<Context path="/WSRP4JResourceProxy" docBase="wsrp4j-proxyportlet"

Now, let create a page in Jetspeed to display a remote portlet

Create a simple page

You can copy the content here:

<?xml version="1.0" encoding="UTF-8"?>
<page id="/wsrp4j.psml" hidden="false">
<title>Welcome to Jetspeed 2</title>
<short-title>Welcome to Jetspeed 2</short-title>
<defaults skin="blue" decorator="tigris" decorator="tigris">
<fragment id="dp-1" type="layout" name="jetspeed-layouts::VelocityOneColumn">
<fragment id="dp-12" type="portlet" name="j2-admin::LoginPortlet">
<property name="row" value="3">
<property name="column" value="0">
<fragment id="P-117c25c3b64-10000" type="portlet" name="wsrp4j-proxyportlet::WSRP4JConsumer">
<property name="row" value="0">
<property name="column" value="0">
<preference name="wsrp_producer_id" readonly="false">
<preference name="wsrp_portlet_handle" readonly="false">
<metadata name="title" lang="fr">Bienvenue a Jetspeed</metadata>
<metadata name="title" lang="ja">Jetspeed 2 ?????</metadata>
<metadata name="title" lang="es">¡Bienvenido a Jetspeed 2!</metadata>
<metadata name="title" lang="hu">Köszönti a Jetspeed 2!</metadata>
<metadata name="title" lang="zh">????Jetspeed 2</metadata>
<metadata name="title" lang="zh_TW">????Jetspeed 2</metadata>
<metadata name="title" lang="ko">Jetspeed 2 ? ?? ?? ?????</metadata>

Next, bounce JetSPeed server and point your browser to

You should see your remote portlet get render.

To build wsrp4j producer I get the guide from http://www.acet.rdg.ac.uk/projects/vre/wsrpinst.php

Monday, December 17, 2007


Recent intruder shooting incidents around Houston reminds us about Texas gun law. In the state of Texas it is legal to own permitted firearms within your property's perimeter. Not only that there will be no charge for firing at the intruders also within your property's perimeter if you feel your life, your loved ones or your properties are in harm. No question asked.

Joe Horn shot 2 buglers in Pasadena Nov 14th. Bad thing is he shot those guys while they're committing the crime in his neighbor property, not his! His action is still under grand jury review.
Second case is the shooting occurred in north of Houston Dec 16, 2AM. This time the bugler broke into a house thru a window and got shot to death by the owner. The third shooting was at a grocery store. The armed robber demanded money but as soon as he turned around, the store owner shot him to death.

I know legally the second case would be a sole self defense action and would not be returned with any charge. I'm not too sure about the first and the third case. Both of those shooters' lives probably were not in danger at that time since those thugs had turned around and left. Even if it's legal to shoot them, I wouldn't think I want to take their life either. Somehow, I think these two unfortunate shooters have probably witnessed this more than once in their life. And since the police couldn't do anything they wanted to take matter in their own hands and teach those thugs a moral lesion.

So remember, even though you can shoot, please think careful before you pull the trigger. A human life is more precious than anything else. A co-worker of mine is a gun supporter and he likes going shooting a lot. He told me to take a conceal handgun license even if I don't want to carry a firearm. The class in fact goes thru a lot of shoot non-shoot situation and what the traumatic it will get when you shoot someone, even if you're legally correct.

Tuesday, December 12, 2006

Happy Birthday - Edvard Munch

"I was walking along a path with two friends—the sun was setting—suddenly the sky turned blood red—I paused, feeling exhausted, and leaned on the fence—there was blood and tongues of fire above the blue-black fjord and the city—my friends walked on, and I stood there trembling with anxiety—and I sensed an infinite scream passing through nature."

Edvard Munch

Friday, November 03, 2006

Happy Birthday

Happy Birthday to me, Happy Birthday to me.

Wednesday, October 25, 2006

Firefox 2 Out or Internet Explorer 7 Down

The long-waited Firefox version 2.0 is out!
Enhanced or added cool new features include:
  • Improved Tabbed Browsing

  • Spell Checking

  • Integrated Search Suggestions

  • Phishing Protection

And many many more.

So get rid of IE now and get some Firefox people.

Go here for more info


Sunday, October 22, 2006

Wings Over Houston 2006 - Airshow

This year wings over Houston airshow features the remarkable highlight of the F-16 Fighting Falcon team the Thunderbirds from USAF. Last year performance was schedule for the Blue Angels (F/A 18 Super Hornet) of the navy but was finally cancelled due to the weather condition.

I think the turn-over rate of this year is also higher than that of the last. Probably because of the weather condition too.

For those who never come to an airshow, here is the routine schedule:

- You arrive at the field around 9 to see stationary aircrafts. Some of them are pretty famous like P-51, B-17 from WW2 or the B-52, F-4 from the Vietnam, Korea war.
- The around 10:30 there is a single flight performance from a modern fighter jet. Today it is the F-16.
- Next comes some super maneuver of acrobatic aircrafts normally sponsored by big company like Oracle for this year.
- Around 1:00 PM there is an amazing reenactment of Pearl harbor with real machine guns and explosive. Those are triggered on the ground, not actually dropped from the aircrafts.
- Wrap up by the super performance of the top team in the nation: Blue Angels, Thunderbirds...

You would want to get up and leave around 4:00 PM since then the traffic is not that *terrible*.

Posted by Picasa

Monday, October 16, 2006