Setting up BlazeDS

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-4.0.0.14931.zip. Extract the content in this file to a folder named blazeds-bin-4.0.0.14931

Step 3:

In the blazeds-bin-4.0.0.14931 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!!! :)

About these ads

50 Responses to Setting up BlazeDS

  1. Mark says:

    Thanks.it is very helpful.

    Mark

  2. TJ Downes says:

    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

  3. rk says:

    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]

  4. Hi RK,

    Please share code to reproduce this.

  5. BAM says:

    Thanks for your help.

    Bam

  6. Thangaraj says:

    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.

  7. 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.

  8. Thangaraj says:

    Thanks Sujit, when I opened “remoting-config.xml” in IE, there were errors with double quotes at some places and rectified it.

  9. [...] Blaze DSHandling Java Exceptions in Flex applicationRendering PDF content in Adobe AIR applicationSetting up BlazeDSSpeaking at FUG, Blore on using Flex with BlazeDS [...]

  10. Suresh says:

    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

  11. Hi Suresh,

    Try the HTTP channel in BlazeDS.

  12. Suresh says:

    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.

  13. gregh says:

    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

  14. gregh says:

    Hi, you can ignore my prior post as I found the link & explanation (above) to your BlazeMonster post. Cheers //GH

  15. Saidaiah Goud says:

    Thank you very much for your material

  16. 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.

  17. Sundar says:

    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

  18. alexsimi says:

    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… :)

  19. vasu says:

    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.

  20. Jack says:

    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.

  21. Hi Jack,

    Please try the windows service installer. You can find more details at this URL http://tomcat.apache.org/tomcat-6.0-doc/setup.html

    Hope this helps.

  22. Hi Vasu,

    I am sorry, couldn’t understand what exactly you are trying to say. Can you please explain the problem properly.

    Thank you.

  23. Olivier says:

    Hi Sujit,

    What is the advantage between manually setting up the project (the way you do it here) and creating it from the Flex 3 Wizard ?

    Thanks,
    Olivier

  24. Hi Olivier,

    Can you please let us know which wizard you are using to setup BlazeDS. I don’t think there will be any difference.

  25. I Like this site your article is very nice , Thanks, very interesting article, keep up it coming

  26. kjv007 says:

    Thank you for this tutorial, but I’m having some problems:

    I’m getting this error, can you please help me on this?
    thanks in advance

    SEVERE: Servlet /FlexBlazeDSBase threw load() exception
    javax.servlet.UnavailableException: Error instantiating application scoped instance of type ‘MyRemoteClass’ for destination ‘myJavaClass’.
    at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:170)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    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:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

  27. Josh Molina says:

    Hi Sujit,

    First and foremost thank you for a great tutorial.

    Please disregard if this has already been addressed (I haven’t read the latest posts). =)

    When copying/moving the configuration files (xml) from blazeds/flex/ to sampleapp/WEB-INF ***MAKE SURE YOU CHANGE THE LOCATION IN THE web.xml ***

    Currently, the messagebroker looks for services-config.xml in the /flex directory which doesn’t exist in the new app.

    Josh
    Boston, MA

  28. Hi Sujit Reddy,

    I have gone through this tutorial for configuring the BlazeDs for tomcat, but i want to configure it for Web Sphere application server 6.

    Could you please let me know how to configure blazeDS for Webspehre…

    Thanks in advance.

  29. Divya says:

    Hi Sujit,

    Great post!

    I was wondering if you could provide me with some information. Is there any way that i can use blazeds with jdk1.4 without actually modifying the source code of blazeds? The SAP system’s J2EE server is running on 1.4 and so cant change it.

    Thank you :)

  30. Hi Divya,

    Nope, I don’t think so :)

  31. Dimitrios says:

    Hi Sujit ,

    Thanks for your tutorial.I am newbie to Flex and this tutorial is just perfect :)

    Dimitrios from Athens.

  32. sasi kumar says:

    Download the BlazeDS binary distribution not available sujit

  33. Hi Sujit,

    Go stuck at a very initial stage. Not able to extrct blazeds.war file. Please help.

  34. kishore says:

    hi sujit.i have a prblm when trying BlazeDs integreation with websphere for messageservice.i have done all configuration in serverside(web.xml,jar files,services-config.xml and message-config.xml)when i send the request http://revati:9080/MiddleOffice/ws/messagebroker/amf i am getting Error 404: SRVE0190E: File not found: /messagebroker/amf .i stucked for past three days.plz help me out.its very urgent

  35. RAY says:

    When I run this or any other example, I receive an error that says “Service Does Not Support Command Type 0″ and also The ‘Remoting’ service can only process messages of type ‘RemotingMessage’.

    Cant find the solution anywhere. Any ideas ?

  36. Mike says:

    @RAY

    Did you ever find a solution for the Service Does Not Support Command Type 0″ problem? I am seeing the same thing when my client tries to subscribe.

  37. zjank says:

    HEllo,
    thank you very much, it helps!

  38. Moloy says:

    Do you have any article (Step by step) regarding BlazeDS setup with Websphere 7? I installed BlazeDS but having hard time setting up Flex environment . I am getting ( Invalid root. The WEB-INF/flex folder must contain either flex-config.xml or services-config.xml.) error. Any help is appreciated.

    Thanks

  39. Srinivas Vinjamuri says:

    Hi Sujit,

    Does Blaze DS remoting service work with Tomcat 5.5 version (or) do we need any specific setup on this part. Please suggest.

    Regards,
    Srini

  40. Gregg says:

    I’d like to ask you if you have any ideas how to configure BlazeDS with JBoss, not Tomcat. I’ve seen many similar tutorial but all for Tomcat.
    Please let me know
    Thanks

  41. gbofloto says:

    Hi Sujit,
    I tried flex/Java with Blazeds following your tutorial at this page, and it work perfectly.Now, I want to integrate security to my application. I have followed instruction according to BlaseDS developper Guide, but I can’t connect flex to BlazeDS.I tried also spring-securtiy, but I have an error from RDSDispatchServlet.
    Please help me for configure correctly my workspace.
    Thanks

  42. Throstur says:

    I´m having trouble getting connection to a Java class that is not located inside apace/webapps/.. directory. I moved ‘flex’ and ‘lib’ to my WEB-INF folder where my project is located. But I can´t connect to my class. I can only connect to a class that is inside blazeds\WEB-INF\classes. Does anyone have a hint for me ?

  43. ramesh says:

    HI..
    its really a nice article, i am using it for sample application but it gives me error.

    “The value following “version” in the XML declaration must be a quoted string.”

  44. Hi Throstur,

    As long as the class is in application classpath it will work.

  45. gowtham says:

    Hi Sujit,
    Does the tomcat folder goes into blazeds
    because i saw tomcat/webapps/blazeds/WEB-INF/classes
    in invoking java methods.

    i got confused of it

  46. Venkat says:

    Hi Sujit,

    Thanks for the article. I was able to follow all the steps. I have one quick question – Is it possible to keep the BlazeDS.war and custom.war (my application war)
    separate? If so, how do we achieve this?

  47. Hi Gowtham,

    Its the BlazeDS jar files and configuration files that will be deployed in Tomcat.

  48. Hi Venkat,

    Yes, you can. Please change the endpoint URLs to point to where BlazeDS is deployed and place a crossdomain policy file.

  49. Kumar says:

    Hi Sujit,

    Is it mandatory to register the HttpFlexSession listener in web.xml.
    I tried by commenting the listener and I am able to see the data on client as there are now issues on not registering the listener.
    Can you please explain me in detail or give me links which talks on HttpFlexSession listener and its uses.

    Thanks,
    Kumar

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

Follow

Get every new post delivered to your Inbox.

Join 112 other followers

%d bloggers like this: