OpenBD Wiki

From OpenBD
Jump to: navigation, search

OpenBD and BlazeDS

OpenBD + BlazeDS HOWTO

This HOWTO outline the steps necessary to get BlazeDS working with OpenBD. What you wind up with at the end of this process is the BlazeDS sample applications running alongside and hitting CFML pages and CFCs in OpenBD for remote services. These steps are essentially the reverse of the steps outlined by Paul Bonfanti here, and huge thanks again to Paul for writing the OpenBD Adapater that enables communication between Flex and OpenBD.

Current limitations of the OpenBD Adapter are:

  • Query objects are not returned to Flex in the same way they are in ColdFusion. I'm looking at adjusting the adapter to better handle this but didn't want to hold up this HOWTO while I did that.
  • There is no CFC <-> ActionScript class conversion.

If you DON'T want to go through these steps yourself, just grab this zip file that contains a blank slate of OpenBD + BlazeDS preconfigured for you. Note that this is NOT an official OpenBD release with BlazeDS rolled in; this is just OpenBD 1.1 with BlazeDS added manually. True integration between OpenBD and BlazeDS is on our roadmap for a future release. These steps should also be handy if you want to use a later version of either OpenBD or BlazeDS in the future, or if you just prefer doing things manually.

  • Download the BlazeDS binary distribution from http://opensource.adobe.com/wiki/display/blazeds/Release+Builds
    • Unzip the BlazeDS zip file to a directory of your choice. This won't be where things will run from so it doesn't matter where you unzip it.
  • Expand the blazeds.war file (jar xvf blazeds.war). You'll be copying some files from this expanded WAR file to the OpenBD setup.
  • Download the OpenBD WAR distribution from http://openbluedragon.org/download.cfm
    • Expand the openbd.war file (jar xvf openbd.war); again it doesn't matter where. You'll be copying some files out of the BlazeDS WAR into the OpenBD directory. We'll move it to Tomcat or the servlet container of your choice once everything is merged.
  • Copy everything from the {unzipped_blazeds}/WEB-INF/lib directory to the {unzipped_openbd}/WEB-INF/lib directory. As of the time of this writing and with the versions used at the time, there are not any file conflicts between the two.
  • Copy the {unzipped_blazeds}/WEB-INF/flex directory to the {unzipped_openbd}/WEB-INF directory. Note that your'e copying the entire directory over, not only the files within the directory, so you'll wind up with a flex directory inside the {unzipped_opendb}/WEB-INF directory.
  • Copy OpenBDAdapter.jar to the {unzipped_openbd}/WEB-INF/lib directory.
  • Open {unzipped_openbd}/WEB-INF/web.xml as well as {unzipped_blazeds}/WEB-INF/web.xml in a text editor. You will be copying/merging parts of the BlazeDS web.xml file into the OpenBD web.xml file, or at a minimum you'll want both open for reference.
    • Copy the <context-param> node from the BlazeDS web.xml into the OpenBD web.xml file.
    • Add the following <listener-class> node to the <listener> node of the OpenBD web.xml file:
<listener-class>flex.messaging.HttpFlexSession</listener-class>

The entire <listener> node will now look like this:

<listener>
    <listener-class>flex.messaging.HttpFlexSession</listener-class>
    <listener-class>com.naryx.tagfusion.cfm.application.cfHttpSessionListener</listener-class>
</listener>

Next ...

  • Copy the Message Broker <servlet> node from the BlazeDS web.xml file into the OpenBD web.xml file. This can be pasted anywhere inside the webapp (top) node; I just pasted it above the first <servlet> node I found.
  • Copy the Message Broker <servlet-mapping> node from the BlazeDS web.xml file into the OpenBD web.xml file. This can be pasted anywhere inside the webapp (top) node; I just pasted it above the first <servlet-mapping> node I found.
  • Save the web.xml file
  • Open {unzipped_openbd}/WEB-INF/flex/services-config.xml in a text editor.
    • Uncomment the commented-out block that begins with <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel"> and save the file.
  • Open {unzipped_openbd}/WEB-INF/flex/remoting-config.xml in a text editor.
    • Add the following <adapter-definition> node to the <adapters> node:
<adapter-definition id="openbd-object" class="openbd.flash.messaging.OpenBDAdapter"/>
  • Remove default="true" from the JavaAdapter node and add it to the OpenBDAdapter node. The entire <adapters> node will now look like this:
<adapters>
    <adapter-definition id="openbd-object" class="openbd.flash.messaging.OpenBDAdapter" default="true"/>
    <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter"/>
</adapters>

Note that you only really need to worry about the default setting if you have two destinations with the same path and name. How could this happen? Assume you have the Java class "path.to.MyService" in your classpath, and you also have the CFC "path.to.MyService" in the normal path traversal for CFCs. In this case if you have a destination defined as follows:

<destination id="myService">
    <properties>
        <source>path.to.MyService</source>
    </properties>
</destination>

The path.to.MyService object it will use is the one it finds via the default adapter. Pretty rare situation but I thought it would be good to outline the behavior.

At this point you will have a "clean" setup of OpenBD with BlazeDS. To show how you configure your own applications to use this, the following outlines the steps involved with dropping a quick couple of samples I built into this clean OpenBD + BlazeDS setup. You can grab this samples bundle as a zip file, and it includes the source for the two sample Flex apps, and uses an embedded H2 database so there's no setup involved with getting things running other than dropping this onto your servlet container.

As you probably know if you're familiar with Flex, in order to use HTTP services and remote objects you have to configure destinations in the appropriate configuration files. Note that these need to be configured BEFORE you compile your SWFs because these configuration files are NOT read at run time.

Here's what I did to get the two samples, one using an HTTP service and one using a Remote Object, up and running.

  • Open {unzipped_openbd}/WEB-INF/flex/proxy-config.xml in a text editor. Add the following <destination> node to this file:
<destination id="musicians">
<properties> <url>/{context.root}/samples/httpservice/musicians.cfm</url> </properties> </destination>
  • Open {unzipped_openbd}/WEB-INF/flex/remoting-config.xml in a text editor. Add the following <destination> node to this file:
<destination id="musicianService">
   <properties>
       <source>samples.remoteobject.MusicianService</source>
   </properties>
</destination>

Again, if you download the pre-built bundle you do not have to go through these steps. This is really to show you how this is done for your own apps.

And of course to deploy this to your servlet container, you can either WAR this all up or just deploy the directory structure as is to the servlet container of your choice. Then you can hit these URLs to see the samples in action:

These files are also linked from the default index.cfm page.

A final note concerning the sample apps--if you're messing around with them in a context path other than openbd-with-blazeds, the sample SWFs won't work. This is because the context path is set in the SWF at compile time. You can recompile the MXML files with the appropriate settings for your context path, however.

That's all for now--PLEASE let us know or update this information if it's inaccurate. I went through several iterations messing around with all of this so it's possible I missed a step or did something out of order.


Personal tools