Peter Martin: Cairngorm Archives

November 20, 2008

Cairngorm Plugin Available

The Cairngorm Plugin is now available as a public beta on opensource.adobe.com. Please click here for details on how to install the plugin.

I am looking for people to join the Cairngorm Plugin project team, if you are interested please email at pmartin@adobe.com.

Enjoy!

Posted by pmartin at 7:52 AM | Comments (12)

October 28, 2008

Cairngorm Plugin @ MAX

The Cairngorm Plugin has now been launched internally within Adobe Consulting (AC) as a private beta. Eric Garza and myself will be formally launching it as a public beta at our MAX talk.

We also have a cool looking splash screen for the plugin, which was designed by George Neill of AC along with all the other icons (and I thought George was just lazy :)).

CairngormSplash.png

In the run up to MAX I will try and blog some more details about the plugin and some up-to-date screens shots, as it has moved on since my earlier sneak peek.

Posted by pmartin at 7:07 PM | Comments (9)

August 16, 2007

Speaking at MAX 2007 on Cairngorm "Enterprise"

I am going to be at MAX 2007 in Chicago speaking about our ideas and current thinking that is shaping the future release of Cairngorm "Enterprise". The title of my session is "Building Rich Internet Applications with Cairngorm and LiveCycle Data Services. My session is a case study on an Adobe Consulting project that has used Cairngorm "Enterprise". The session will focus on how we have used Data Management Services and take a look inside Cairngorm "Enterprise". I hope to see you there.

Alistair McLeod will be giving the same presentation in Barcelona.

Posted by pmartin at 5:57 PM | Comments (0)

June 30, 2006

Cairngorm 2 + XDoclet2

With the release of Cairngorm on Adobe Labs the package name has changed from org.nevis.cairngorm to com.adobe.cairngorm. I have updated the AS3 plugin for XDoclet2 to reflect the new package name so all generated VOs will now implement com.adobe.cairngorm.vo.ValueObject. You can also download the source from here.

For more information on XDoclet2 please see my earlier blogs:

Posted by at 2:41 PM | Comments (6)

Cairngorm 2 Security

It's great to finally see Cairgorm 2 on Adobe Labs. To mark the occassion I thought I would post some code I developed a while back to allow Cairngorm to use secured server-side destinations.

On the server you can configure security contraints in services-config.xml as per the following example , alternatively you can configure security constraints in-line with your destinations.

<security-constraint id="trusted">
   <auth-method>Custom</auth-method>
   <roles>
      <role>guests</role>
      <role>accountants</role>
      <role>employees</role>
      <role>managers</role>
   </roles>
</security-constraint>

You can then reference your security contraint in your destinations (data-management-config.xml, messaging-config.xml, proxy-config.xml and remoting-config.xml) as per the following example:

<destination id="loginService">
   <properties>
      <source>com.adobe.LoginService</source>
   </properties>
   <security>
      <security-constraint ref="trusted" />
   </security>
</destination>

The ZIP contains the following files:

  • DestinationLocator - subclasses Cairngorm ServiceLocator to support Messaging, Data Management Services and Web Services.
  • SecureDestinationLocator - sublcasses DestinationLocator to support user authentication.

The SecureDestinationLocator class provides two public methods, setCredentials() and logout(). When you call setCredentials() the supplied username and password are set on all configured destinations. When you call logout() the user is logged out from all configured destinations. At present SecureDestinationLocator doesn't support remote credentials or setting credentials on individual destinations.

When you set the user's credentials on a service they are applied to the underlying channel not the individual services i.e. the set of services belonging to the channel share the same credentials.

The SecureDestinationLocator will allow you to create a custom login form in your application and use the underlying J2EE security model. The benefits to your application are that you can apply authentication to your server-side destinations and also use role-based authorization. If you are developing a more complex enterprise application, which may have mid-tier business logic that is held in EJBs the user principal, which is created on authentication will be propagated. This allows you to identify the user and to secure you EJBs. The motivation to secure your server-side services often comes from the need to protect your system from malicious hackers, which forces many enterprise applications to undergo penetration testing before they can enter production.

On a wider enterprise scale many of today's J2EE-application servers support Single Sign On (SSO) and integration with Identity Management Solutions.

Posted by at 10:06 AM | Comments (4)

May 12, 2006

Cairngorm 2 Flex Library Project

Earlier this week Steven Webster announced a new release of Cairngorm 2 for the public release of Flex 2 Beta 3. As Steven said there is very little change and the migration involved little effort. The one thing I have done though is to move Caringorm 2 in to a Flex Library Project.

Before I say any more on the Flex Library Project and wanted to mention some work I have being doing over and above Cairngorm 2. I have extended ServiceLocator to provide a SecureServiceLocator that supports server-side security. The SecureServiceLocator allows you to set a user's credentials on a service(s), which will be used by the server to authenticate the user. The SecureServiceLocator also allow you to log out a user. I have a simple Custom Login example that I will blog about in the future that demonstrates how you use a custom login form in Flex and how you use the SecureServiceLocator to set the user's credentials. On the server, you configure a security constrait and the Web container will authenticate the user against a back-end user store. This integrates you directly in to the J2EE-security model, which allows you to identify the user on the server and to authorize user operations. For example, if your business logic is maintained in Stateless Session Beans (SLSBs) you can have the EJB container authorize user operations, which can help protect your application against malicious attacks. The SecureServiceLocator is not currently part of Cairngorm 2, but I hope it will be in the future.

To use the Cairngorm 2 Flex Library Project follow these steps:

  • Extract the ZIP file into your Flex Builder/Eclipse workspace.
  • In Flex Builder/Eclipse select File > Import and follow the Existing Projects into Workspace wizard.

If you build the project it will create a Cairngorm SWC in the bin folder, which you can then copy in to your Flex Project. Alternatively you can add the Project itself to the library path of a Flex Project.

Posted by at 11:04 AM | Comments (0)

April 28, 2006

XDoclet2 + AS3 + Ant + Cairngorm - Update I

I thought I would follow-up on my last blog entry on XDoclet2. In the last week I have been going head-to-head with XDoclet2 in the hope it will save our team coding Java VOs and AS3 VOs. As the team started using more complex object types in Java it soon became apparent that the generated AS3 VOs weren't going to work. This came as a bit of blow to us so we had to decide whether to drop XDoclet2 and hand-code both sets of VOs, fix XDoclet2 or look for a "home grown" alternative.

The problems we encountered were as follows:

  • A number of the Java to AS3 types mappings were wrong, namely java.util.Collection mx.collection to ArrayCollection. It appears the AS3 codegen is still using the type mappings from Flex 1.5.
  • The AS3 class contained Java import statements - so it wouldn't compile.
  • Java public static final constants were crashing XDoclet2.

We decided to push forward and see if we could fix XDoclet2. I have logged these bugs with XDoclet but you can also download my patched plugin JAR here. It should now implement all the Java to AS3 types mappings as defined in the Developing Flex Applications manual. The latest code in the XDoclet2 repository doesn't appear to have the same issue with imports, although this version will filter out duplicates.

If you want to codegen the Java public static final constants you need to include the Java class files in your XDoclet2 classpath, which is part of the Ant build script, as it uses Java reflection to obtain the value of the constant.

We added our Ant build script as a builder on the project, by default this runs in the same Java VM as Eclipse but it caused memory issues (XDoclet2 appears to be memory intensive) that ultimately crash Eclipse. As a result we ended up configuring our builder to run in a separate JVM and setting the maximum heap size to 64MB.

My updated Ant build script is below, the location of our Java VO classes is now included in the <path> element:

<project name="XDocletExample" default="main">

	
	<property
		name="xdoclet.plugin.install.dir"
		value="C:/apps/java/xdoclet-plugins-1.0.3"/>
	
	
	<property
		name="xdoclet.output.dir"
		value="${basedir}/as"/>

	
	<path id="xdoclet.task.classpath">
 		
  		<fileset dir="${xdoclet.plugin.install.dir}/lib">
    		<include name="**/*.jar" />
  		</fileset>

		
  		<pathelement
			location="${xdoclet.plugin.install.dir}/plugins/xdoclet-plugin-actionscript-1.0.4-SNAPSHOT.jar"/>
 	
		
		<pathelement location="${basedir}/bin"/>
	</path>

 	
 	<taskdef
    	name="xdoclet"
 		classname="org.xdoclet.ant.XDocletTask"
     	classpathref="xdoclet.task.classpath" />

 	<target name="main">
 		
		<delete>
			<fileset dir="${xdoclet.output.dir}">
 				<include name="**/*.*"/>
 			</fileset>
 		</delete>
 		
  		<xdoclet>       
   			
  			<fileset dir="src">
	            <include name="**/*.java"/>
  		  	</fileset>

   			
   			<component
  				classname="org.xdoclet.plugin.actionscript.ActionScript3Plugin"
   				destdir="${xdoclet.output.dir}" />
  		</xdoclet>
	</target>
  			
</project>

Where does this leave us? I don't like patching open-source libraries, but I saw little choice here. Given time I would like to create an AS3 plugin for XDoclet (v1.x), while XDoclet2 may be architecturally better it seems to lack the support given to XDoclet. XDoclet has better documentation and there are a number of books available. For me though the biggest benefit to XDoclet is the Eclipse tooling support.

Resources

Posted by at 4:48 PM | Comments (3)

April 22, 2006

XDoclet2 + AS3 + Ant + Cairngorm

I recently wanted to generate Cairngorm VOs (a.k.a. DTOs) from Java VOs. I had a quick search on Google and quickly came across XDoclet2. The current version of XDoclet2 is v1.0.3. I have to confess I struggled to get it running due to the sparse documentation. However, my attempts to get it running were in vain as it wouldn’t generate VOs that I could use in Remote Procedure Calls (RPC). This is because v1.0.3 of the XDoclet2 plugins was released before features such as the metadata used by Flex Data Services (FDS) were known. In particular it doesn’t support the RemoteClass metadata.

The AS3 plugin was contributed by Joe Berkovitz and I noted on the Allurent web site that the latest version of the AS3 plugin code in CVS did indeed have the support. The downside was you had to get the latest source and build the plugin yourself, which is time consuming as you need to check-out the code, install Maven, etc. but I thought a worthy topic of my first blog entry due to the time saved by auto-generating AS3 VOs. However, at the time of writing this entry I note that Joe has released a new version of the plugin on his blog, which supports the new FDS metadata. Hmm, so where does that leave my blog entry?

All is not lost. I still think it is a worthwhile exercise to work through a practical example of installing the XDoclet2 plugins with Joe’s new AS3 plugin and to consider Cairngorm along the way.

Requirements

  • Download the XDoclet2 plugins (v1.0.3) from Codehaus.
  • Download the new AS3 plugin from Joe Berkoviz’s blog.
  • Download Log4j – XDoclet2 uses Commons Logging and requires a logging implementation.

Software Installation

  • Extract the XDoclet2 plugins distribution.
  • Extract the Log4j distribution.
  • Copy the Log4j (I used v1.12.13) JAR, <your_log4j_directory>\dist\lib\log4j-1.2.13.jar, to <your_xdoclet_directory>\lib.
  • Delete the shipped AS3 plugin, xdoclet-plugin-actionscript-1.0.3.jar, from <your_xdoclet_directory>\plugins.
  • Copy Joe’s AS3 plugin, xdoclet-plugin-actionscript-1.0.3.20060414.jar, to <your_xdoclet_directory>\plugins.

Example

I created a Java Project in my Eclipse workspace (which you can download here and import into your workspace – extract the file into your workspace and in Eclipse select File > Import and follow the Existing Projects into Workspace wizard).

To start with I created a Java VO (PersonVO) which I annotated for the AS3 codegen:

package com.adobe.example;

/**
 * Example Java VO with XDOclet2 annotation for AS3 codegen.
 * 
 * @actionscript.class
 * 		bindable = true
 */
public class PersonVO
{
	private String forename;
	private String surname;
	
	public String getForename()
	{
		return forename;
	}
	
	public void setForename( final String firstName )
	{
		forename = firstName;
	}
	
	public String getSurname()
	{
		return surname;
	}
	
	public void setSurname( final String lastName )
	{
		surname = lastName;
	}
}

I then created the following Ant build script (build.xml) in the root of my project. You will need to change the value of the xdoclet.plugin.install.dir property to the location of your XDoclet2 installation (remember to use forwarded slashes).

<project name="xdoclet2-example" default="main">

	<property
		name="xdoclet.plugin.install.dir"
		value="C:/apps/java/xdoclet-plugins-1.0.3"/>

	<path id="xdoclet.task.classpath">

 		
  		<fileset dir="${xdoclet.plugin.install.dir}/lib">
    		<include name="**/*.jar" />
  		</fileset>

  		
  		<pathelement
  			location="${xdoclet.plugin.install.dir}/plugins/xdoclet-plugin-actionscript-1.0.3.20060414.jar"/>
	 
 	</path>

 	
 	<taskdef
    	name="xdoclet"
 		classname="org.xdoclet.ant.XDocletTask"
     	classpathref="xdoclet.task.classpath" />

 	<target name="main">
  		<xdoclet>       
   			
  			<fileset dir="src">
	            <include name="**/*.java"/>
  		  	</fileset> 	   

   				
   			<component
  				classname="org.xdoclet.plugin.actionscript.ActionScript3Plugin"
   				destdir="." />
  		</xdoclet>
	</target>
  			
</project>

To run the Ant build script in your Eclipse workspace right-click on build.xml and select Run As > Ant Build…. Click the Main tab and then click the Browse Workspace button under the Base Directory field and select your project (XDocletExample). When you have finished click the Run button.

The console view will show the output of the Ant build script. When it’s finished you will need to right-click the project and select Refresh to see your generated AS3 class, as shown below:

// Generated file. Do not edit.
// Generated by org.xdoclet.plugin.actionscript.ActionScript3Plugin from com.adobe.example.PersonVO

package com.adobe.example
{

  import org.nevis.cairngorm.vo.ValueObject;

  /** Example Java VO with XDOclet2 annotation for AS3 codegen. */

  [Bindable]
  [RemoteClass(alias="com.adobe.example.PersonVO")]

  public class PersonVO implements ValueObject
  {


    public var forename:String;

    public var surname:String;

  }
}

If you don’t use Eclipse, you will need to download and install Ant. If you add the Ant bin directory to your path you can open a command prompt and change directory to your project. To run the Ant build script just type ant at the command prompt.

In a real project you could run the Ant build script automatically by adding it as a builder to your project; this would also refresh your project automatically. Let me know if you want to see the detail.

Cairngorm

When we use VOs in a Cairngorm-based application we implement the org.nevis.cairngorm.vo.ValueObject interface. This is not strictly required as it is only a marker interface. However, my preference is to provide the interface on generated VOs. If this is your preference you can download a modified Velocity template that will add the Cairngorm VO interface to your generated AS3 classes.

  • Extract Joe’s AS3 plugin, you can do this using WinZip but you will need to change the extension to .zip.
  • Overwrite the AS3 template (ActionScript3Plugin.vm) in <your_extracted_plugin_directory>\org\xdoclet\plugin\actionscript with the one you downloaded.
  • Zip the plugin back-up and rename the extension to .jar.
  • Copy your modified plugin JAR to <your_xdoclet_director>\plugins and overwrite the existing JAR.

If you run your Ant build script again you should get a Cairngorm VO, as below:

// Generated file. Do not edit.
// Generated by org.xdoclet.plugin.actionscript.ActionScript3Plugin from com.adobe.example.PersonVO

package com.adobe.example
{

  import org.nevis.cairngorm.vo.ValueObject;

  /** Example Java VO with XDOclet2 annotation for AS3 codegen. */

  [Bindable]
  [RemoteClass(alias="com.adobe.example.PersonVO")]

  public class PersonVO implements ValueObject
  {


    public var forename:String;

    public var surname:String;

  }
}

Please also see my recent follow-up blog on XDoclet2 that covers some of the more practical issues I have encountered and a patch to the AS3 plugin.

Posted by at 9:28 PM | Comments (3)