Integrating BlazeDS with JBoss

BlazeDS is, quite probably, one of the most efficient ways to glue your RIA interface to a J2EE based application server for data and messaging access. BlazeDS allows one to use the power of Adobe’s AMF binary data transfer format for remoting from within a Java web server back-end. This post shows how to use BlazeDS with JBoss AS.

Getting JBoss Ready

  • Download JBoss AS 6.0 (jboss-as-distribution-6.0.0.Final.zip)
  • Extract the downloaded and compressed zip file into your working workspace (e.g. C:\RIADev\JBoss)

Preparing the Web Archive (war)

  • Create a web archive folder in your JBoss server configuration (e.g. JBOSS_HOME\server\default\deploy\blazedstest.war)
  • Start your JBoss server
  • Download the binary distribution of BlazeDS
  • Decompress the downloaded file
  • Decompress the blazeds.war file
  • Copy the WEB-INF directory from the the war file into your web archive folder (e.g.  JBOSS_HOME\server\default\deploy\blazedstest.war)
  • Start Flash Builder 4 (if using the Flash Builder 4 plugin for eclipse ignore this step)
  • Create a new Flex Project
  • Set the project name and ensure that the application type is set to web
  • Click on Next
  • On Server Settings set application server type to J2EE
  • Select BlazeDS
  • Set the Root Folder to your web archive directory (e.g. JBOSS_HOME\server\default\deploy\blazedstest.war)
  • Click on Validate Configuration
  • Set the Output Folder to your web archive directory
  • Click on Next
  • Click on Finish

Prepare your J2EE project

  • In Eclipse, create a new Java Project (e.g. blazedstest)
  • Once created, right click on the project and select properties
  • Select the Java Build Path options
  • Select the Source tab
  • Expand the Source Folder for you new project (e.g. blazedstest/test)
  • Check the box to Allow output folders for source folders (you should now see the Output Folder option)
  • Select the Output Folder option for your src folder and click on edit
  • Select Specific Output Folder and set it to your classes directory in your web archive directory (e.g. JBOSS_HOME\server\default\deploy\blazedstest.war/WEB-INF/classes)
  • Click OK
  • Click OK again to close the project properties panels

BlazeDS Remoting (Java side)

Add the following class to your java project src directory:

package org.riaconnection.remoting;

import java.util.ArrayList;
import java.util.List;

public class FlexRemoting {

	public List listPortugueseSpeakingCountries() {
		  List countries = new ArrayList();
		  countries.add("Portugal");
		  countries.add("Brazil");
		  countries.add("Angola");
		  countries.add("East Timor");
		  countries.add("Mozambique");
		  countries.add("Guinea-Bissau");
		  countries.add("Cape Verde");
		  countries.add("Macau");
		  countries.add("Sao Tome and Principe");
		  countries.add("Andorra");
		  countries.add("Goa (India)");
		  return countries;
	}

}

Add new destination to your BlazeDS remoting-config.xml file. You should find it under
JBOSS_HOME\server\default\deploy\blazedstest.war\WEB-INF\flex.

    <destination id="flexRemoting" >
        <properties>
            <source>org.riaconnection.remoting.FlexRemoting</source>
            <scope>application</scope>
        </properties>
    </destination>

You can find more details about the destination properties in here

In the end your remoting-config.xml file should look something like:

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>
    
    <destination id="flexRemoting" >
        <properties>
            <source>org.riaconnection.remoting.FlexRemoting</source>
            <scope>application</scope>
        </properties>
    </destination>

</service>

BlazeDS Remoting (Flex side)

Here is a very simple example application that calls the Java method:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
    <fx:Declarations>
        <s:RemoteObject id="remoteObject" destination="flexRemoting"/>
    </fx:Declarations>

    <s:List id="countriesList" x="71" y="14" width="183" height="180" dataProvider="{remoteObject.listPortugueseSpeakingRegions.lastResult}"/>

    <s:Button x="45" y="202" label="Show Portuguese Speaking Regions" click="remoteObject.listPortugueseSpeakingRegions()"/>

</s:Application>

Run JBoss and test Web App

Start the JBoss server (JBOSS_HOME/bin/run.sh) and point your browser to http://localhost:8080/blazedstest/blazedstest.html and you should see the following application come up in your browser:

BlazeDS remoting example 1

Screenshot of Sample Application

Advertisements

About CrazyPenguin

Software Engineer
This entry was posted in BlazeDS, Flex 3, Flex 4 (Spark). Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s