This article explains how to setup BlazeDS for your J2EE web application.
BlazeDS adds a lot of power to your web applications. You can expose your Java classes as Remoting services. You can use the Messaging service of BlazeDS to expose publish subscribe messaging destinations and also use the Proxy service to invoke other services.
More details about BlazeDS can be found at this URL http://opensource.adobe.com/wiki/display/blazeds/BlazeDS
Updated: Free AIR based Tool to generate Flex code for consuming/exposing Java classes as BlazeDS Remoting services. Visit this URL for more details http://sujitreddyg.wordpress.com/2009/05/07/blazemonster/
Just follow the steps below you will have BlazeDS setup in no time
Getting BlazeDS
Step 1:
Download release build of BlazeDS. BlazeDS release builds are available at this URL http://opensource.adobe.com/wiki/display/blazeds/Release+Builds Click on “Download the BlazeDS binary distribution” to download the binary distribution. Binary distribution has just jar files and other configuration files required.
Step 2:
Go to folder where you saved the downloaded file in Step 1. You would have downloaded a file named blazeds-bin-3.2.0.3978.zip. Extract the content in this file to a folder named blazeds-bin-3.2.0.3978
Step 3:
In the blazeds-bin-3.2.0.3978 folder you will find a file named blazeds.war and blazeds-bin-readme.htm. blazeds-bin-readme.htm contains terms and conditions and license details. blazeds.war contains required jar files and configuration files for setting up BlazeDS.
Extract the content in blazeds.war file into a folder called blazeds. You can extract the content using tools like winzip.
Now we have downloaded and have the required files extracted to setup BlazeDS for a web application. Let’s create a web application.
Creating web application
If you don’t have Tomcat installed, install Tomcat from http://tomcat.apache.org/
Step 4:
In your Tomcat installation directory, you will find a folder named webapps. Usually it is at this location on Windows Operating System “C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps”
Create a web application named samplewebapp. You do this by just creating folder named samplewebapp under webapps folder.
Setting up BlazeDS
We will setup BlazeDS for the web application created in the previous step.
blazeds – this is the folder in which we have blazeds.war content extracted into in Step 3
samplewebapp – this is the folder created in Step 4
Step 5:
Copy all .jar files from blazeds/WEB-INF/lib to samplewebapp/WEB-INF/lib
Step 6:
Copy blazeds/WEB-INF/flex folder to samplewebapp/WEB-INF
This folder (blazeds/WEB-INF/flex) contains BlazeDS configuration files. Use these files to configure Remoting/Messaging/Proxy services.
Step 7:
Now we will add Servlet mapping for BlazeDS Servlet named MessageBrokerServlet, so that BlazeDS is invoked when you send request for a Remoting/Messaging/Proxy destination using any of the channels supported.
Copy blazeds/WEB-INF/web.xml to samplewebapp/WEB-INF
If you already have a web.xml configured, then you can just copy the Servlet mapping for MessageBrokerServlet and the session listener. You can either copy the content below or copy it from the blazeds/WEB-INF/web.xml
<!-- Http Flex Session attribute and binding listener support -->
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- MessageBroker Servlet -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
That’s it you have BlazeDS setup for your web application.
Now that you have BlazeDS set up you can try invoking Java methods from your Flex applications or create a simple chat application. You can find articles at the URLs below.
http://sujitreddyg.wordpress.com/2008/01/14/invoking-java-methods-from-adobe-flex/
http://sujitreddyg.wordpress.com/2008/01/17/messaging-using-flex-and-blaze-ds/
http://sujitreddyg.wordpress.com/2008/02/12/handling-java-exceptions-in-flex-application/
Adobe Rocks!!!


April 7, 2009 at 9:52 pm
Thanks.it is very helpful.
Mark
April 7, 2009 at 10:08 pm
There is also a good tutorial in the product documentation that shows how to configure BlazeDS for other platforms including ColdFusion:
http://opensource.adobe.com/wiki/display/blazeds/Installation+Guide
April 8, 2009 at 7:15 am
Thanks for the nice article. I am new for the Flex. Can you please help me on this?
http://localhost:8080/samplewebapp/bin-debug/FlexJava.html
Getting the following error. Please note even if run thr flexbuilder i am getting the same error.
Error: Cannot assign operations into an RPC Service (destionation)
at mx.rpc::AbstractService/http://www.adobe.com/2006/actionscript/flash/proxy::setProperty()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractService.as:282]
at FlexJava/_FlexJava_RemoteObject1_i()[E:\Adobe\RK\adobeFlexTraining\FlexJava\src\FlexJava.mxml:13]
at FlexJava()[E:\Adobe\RK\adobeFlexTraining\FlexJava\src\FlexJava.mxml:12]
at _FlexJava_mx_managers_SystemManager/create()
at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3188]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3064]
at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2916]
April 9, 2009 at 8:57 pm
Hi RK,
Please share code to reproduce this.
April 17, 2009 at 4:54 am
Thanks for your help.
Bam
April 29, 2009 at 5:31 pm
Hi Sujit,
Getting the below error in Tomcat console during startup and not able to sort it out, would be a great favour if you shed some light on this. Thanks.
Error:
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
[Fatal Error] :13:18: Invalid byte 1 of 1-byte UTF-8 sequence.
**** MessageBrokerServlet failed to initialize due to runtime exception: Exception: flex.messaging
.config.ConfigurationException: Configuration error encountered on line 13, column 18: ‘Invalid byte
1 of 1-byte UTF-8 sequence.’
at flex.messaging.config.AbstractConfigurationParser.loadDocument(AbstractConfigurationParse
r.java:131)
at flex.messaging.config.ServerConfigurationParser.serviceInclude(ServerConfigurationParser.
java:489)
at flex.messaging.config.ServerConfigurationParser.services(ServerConfigurationParser.java:4
68)
at flex.messaging.config.ServerConfigurationParser.parseTopLevelConfig(ServerConfigurationPa
rser.java:63)
at flex.messaging.config.AbstractConfigurationParser.parse(AbstractConfigurationParser.java:
69)
at flex.messaging.config.FlexConfigurationManager.getMessagingConfiguration(FlexConfiguratio
nManager.java:79)
at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:106)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
> Thangaraj M.
April 29, 2009 at 7:57 pm
Hi Thangaraj,
Looks like there is a problem with one of your configuration files. Please make sure services-config.xml/remoting-config.xml and messaging-config.xml are well formed. Please try opening/parsing those files using Mozilla or IE.
Hope this helps.
May 4, 2009 at 6:30 pm
Thanks Sujit, when I opened “remoting-config.xml” in IE, there were errors with double quotes at some places and rectified it.
May 7, 2009 at 4:40 pm
[...] Blaze DSHandling Java Exceptions in Flex applicationRendering PDF content in Adobe AIR applicationSetting up BlazeDSSpeaking at FUG, Blore on using Flex with BlazeDS [...]
May 14, 2009 at 8:34 am
Hi Sujit,
Thanks for the very informative post. I am researching into using BlazeDS to wrap my calls around Rest service and web services. I have some Action Script object in the client that map to Remote Classes on the BlazeDS side. Right now I am converting the xml response (Remote Class XML objects) that I get from the web/rest service call and use JAXB to convert it to java objects so that blazeds can convert it to AMF3 stream and then to Action Script objects on the client side.
My question is, Can I avoid creating the java objects before and directly convert the XML into AMF3 stream?
Suresh
May 18, 2009 at 4:43 pm
Hi Suresh,
Try the HTTP channel in BlazeDS.
May 23, 2009 at 3:29 am
The problem with HTTP channel is that I need to manually convert the xml to Action Script object. I wanted to see if there is any way I can invoke a Http Service and use an API that would convert the response into Action Script objects.
May 24, 2009 at 12:08 am
SatMay23 09 @ 11:37 PT
(First, thanks for doing this app; its sorely needed).
Just curious… will your ‘app’ work with the ‘turnkey’ Blaze ds (which I think is just Tomcat/BlazeDs preconfigured?) Since this is what I am currently playing with, I did not want to change my configuration it needlessly…
TIA //GH
May 24, 2009 at 4:03 am
Hi, you can ignore my prior post as I found the link & explanation (above) to your BlazeMonster post. Cheers //GH
June 15, 2009 at 2:20 pm
Thank you very much for your material
June 15, 2009 at 5:34 pm
Hi Suresh,
Please try SimpleXMLDecoder class. More details at the URL below.
http://livedocs.adobe.com/flex/3/langref/mx/rpc/xml/SimpleXMLDecoder.html
Hope this helps.
October 16, 2009 at 5:47 pm
Hi Sujit,
I have followed the given steps to configure blazeds to WebApp along with that i have created the RemotehandlerClass in my webApp and deployed it to tomcat6.0 server which is configured at Eclipse IDE
After that i created Flex Project to test the remoting by giving
destination=”CreatingRpc” in MyApplication.mxml but when i try to run the mxml file as Flex application shows the Button “Remote Service” if i click the button its giving the following message
[MessagingError message='Destination 'CreatingRpc' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']
Can you help me in fixing this out?
Regards,
Sundar
October 29, 2009 at 4:02 pm
Hi Sujit, i tried as you given in the above and was able to do it successfully. Appreciate your knowledge and goodwill to share it…
November 4, 2009 at 5:44 pm
Hi Sujit,am new to flex & Balzeds,i have a doubt ,how to configure jsp as backend,instead of one simple java class,if we configure a simple java class this class cant be a singleton class,then how this class is suitable for web application,unless it extended from Httpservlet.please reply me,and suggest me which component i must use as backend servlet or Jsp for webapplication.
November 5, 2009 at 6:18 pm
Hi. Just re: Tomcat when selecting a download version there are a whole lot of options, eg. core, deployer, embedded…just wasn’t sure which was right…thx.