An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

AIR and Groovy via Spring

August 10, 2008 ·

As a fun way to while away a Saturday evening, I decided to look at Joe's Behavioral Analytics backend code to see if I could create a Flex-based AIR application that talked to services written in Groovy. There's not really much documentation out there to help so it was a very hit and miss experience but eventually I had a simple AIR application making a RemoteObject call to a Groovy class and getting data back. I'm going to have to talk to Joe about cleaning up the installation I've ended up with but here are the highlights (and I'll blog more about this once I have all the pieces cleaned up):
  • JBoss 4.2.3 GA installed as a Server in Eclipse (using the Web Tool Platform JEE stuff)
  • Spring framework 2.5.5
  • A Spring-based Flex factory that allows Flex Remoting to talk to objects via Spring (author Jeff Vroom)
  • Groovy - set up per Joe's recent instructions
  • BlazeDS providing the Flex Remoting service
Create a Dynamic Web Project in Eclipse and then unzip BlazeDS into it (per the BlazeDS installation docs). Add Spring and the flex.samples.factories.SpringFactory Java class. Configure Flex Remoting according to Lin's instructions to add the Spring factory:
<factories>
      <factory id="spring" class="flex.samples.factories.SpringFactory"/>
   </factories>
and the context loader:
<!-- Spring -->
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
   </context-param>
   
   <!-- load Spring's WebApplicationContext -->
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
and the destination for the RemoteObject:
<destination id="place">
      <properties>
         <factory>spring</factory>
         <source>placeholder</source>
      </properties>
</destination>
Create a Flex AIR project and define a RemoteObject that refers to the destination you just defined:
<mx:RemoteObject id="bcp"
         destination="place"
         endpoint="http://127.0.0.1:8080/bcpbackend/messagebroker/amf"
         >

      <mx:method name="test" result="testResult(event)" fault="testFault(event)"/>
   </mx:RemoteObject>
Add the placeholder bean definition to your applicationContext.xml file:
<bean id="placeholder" class="com.broadchoice.bcp.Placeholder"/>
com.broadchoice.bcp.Placeholder is a Groovy class that contains a test method (for testing it just takes a string and returns that string plus some additional text).

Tags: air · flex · grails

0 responses