Pages

Wednesday, 7 March 2012

Configuring flex for Blaze DS

Linking Flex and Java can be achieved by BlazeDS.BlazeDS is a server-based Java remoting and web messaging technology that allows you to connect to back-end distributed data and push data to Adobe Flex and Adobe Integrated Runtime (AIR) Rich Internet applications (RIA). Because of its open licensing, BlazeDS is not precluded from being used with other client platforms, such as JavaScript/Ajax.



The Message Service provides a complete publish/subscribe infrastructure allowing Flex clients and the server to exchange messages in real time. Remoting allows a Flex application to directly invoke methods of Java objects deployed in an application server.

configuring BlazeDS isn't that much tough.it can be done by the following simple steps. We can attach the BlazeDS

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

Step 2 :
Extract the content in downloaded file. You will find blazeds.war file.

Step 3:
Copy the blazeds.war file in your tomcat server under /webapps folder. Then start your tomcat.Usually it is at this location on Windows Operating System “C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps”.

Step4:
Create a web application named login. You do this by just creating folder named login under webapps folder. 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
login – this is the folder created in Step 4
Step 5:
Copy all .jar files from blazeds/WEB-INF/lib to login/WEB-INF/lib
Step 6:
Copy blazeds/WEB-INF/flex folder to login/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

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

    <display-name>sample</display-name>
    <description>BlazeDS Application</description>

    <context-param>
        <param-name>flex.class.path</param-name>
        <param-value>
            /WEB-INF/flex/hotfixes,/WEB-INF/flex/jars
        </param-value>
    </context-param>

    <!-- 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>
    <!--
       
       
        <servlet>
        <servlet-name>headerinfo</servlet-name>
        <servlet-class>header.HeaderInformation</servlet-class>
       
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
        <servlet-name>headerinfo</servlet-name>
        <url-pattern>/siteminder.htm</url-pattern>
        </servlet-mapping>
       
    -->
    <welcome-file-list>
        <welcome-file>test.html</welcome-file>

    </welcome-file-list>

    <!-- for WebSphere deployment, please uncomment -->
    <!--
        <resource-ref>
        <description>Flex Messaging WorkManager</description>
        <res-ref-name>wm/MessagingWorkManager</res-ref-name>
        <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>
    -->

</web-app>








That’s it you have BlazeDS setup for your web application


Following things need to taken care while creating flex project


a) Application server type should be 'J2EE'

b) Checked the option for Use remote object access.

c) Set the root folder, root url, context root and click on 'validate configuration' to validate the inputs

d)Set the output folder where your compiled application will be stored

e) Then click on finish button.

f) While creating Employee.AS object which is similar to Employee.java object, make sure you used [RemoteClass (alias="Employee")] in .AS class

No comments:

Post a Comment