Skip to Content

Building Adobe Flex Application with BlazeDS – Part 2

This is the Part 2 of a 3-Part blog series to explain the details of “Building Adobe Flex Application Using BlazeDS”. In my previos blog “[Building Adobe Flex Application with BlazeDS – Part 1 | Building Adobe Flex Application with BlazeDS – Part 1]” we defined the scenario and downloaded necessary libraries and xml files. In this blog we will create J2EE Application and configure it to make available for calls from Adobe Flex application.

 

I will be
using Netweaver Developer Studio 7.2 and SAP Netweaver CE 7.2. There is not
officially released BlazeDS binary packages build for Java 1.4 but it can also be
built and used on SAP J2EE Engine 7.0.

 

Create an
empty development component “blaze1” of type Web Module.

 

!https://weblogs.sdn.sap.com/weblogs/images/29528/baf2.png|height=426|alt=|width=320|src=https://weblogs.sdn.sap.com/weblogs/images/29528/baf2.png!

 

After you’ve successfully created an empty project, copy all jar files that we extracted from blazeds.war into *WEB-INF/lib* folder.

 

It is time to create xml files to build the communication with Adobe Flex application. Create a new folder “flex” in WEB-INF and then copy xml files that we extracted from blazeds.war file. I have only made little changes to keep them simple and the final xml files should look like:

 

*services-config.xml*

<?xml version=”1.0″ encoding=”UTF-8″?>
<services-config><br />+    <services>+<br />+        <service-include file-path=”remoting-config.xml” />+<br />+        <service-include file-path=”proxy-config.xml” />+<br />+        <service-include file-path=”messaging-config.xml” />        +<br />+    </services>+<br />+    <channels>+<br />+        <channel-definition id=”my-amf” class=”mx.messaging.channels.AMFChannel”>+<br />+            <endpoint url=”http://{server.name}:{server.port}/{context.root}/messagebroker/amf” class=”flex.messaging.endpoints.AMFEndpoint”/>+<br />+        </channel-definition>+<br />+        <channel-definition id=”my-secure-amf” class=”mx.messaging.channels.SecureAMFChannel”>+<br />+            <endpoint url=”https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure” class=”flex.messaging.endpoints.SecureAMFEndpoint”/>+<br />+            <properties>+<br />+                false+<br />+            </properties>+<br />+        </channel-definition>+<br />+        <channel-definition id=”my-polling-amf” class=”mx.messaging.channels.AMFChannel”>+<br />+            <endpoint url=”http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling” class=”flex.messaging.endpoints.AMFEndpoint”/>+<br />+            <properties>+<br />+                <polling-enabled>true</polling-enabled>+<br />+                <polling-interval-seconds>4</polling-interval-seconds>+<br />+            </properties>+<br />+        </channel-definition>+<br />+    </channels>    +<br />+</services-config>+ </p><p><br />*remoting-config.xml*</p><p> </p><p>+<?xml version=”1.0″ encoding=”UTF-8″?>+<br />+<service id=”remoting-service” class=”flex.messaging.services.RemotingService”>+<br />+    +<br />+        +<br />+    +<br />+    <default-channels>+<br />+        <channel ref=”my-amf”/>+<br />+    </default-channels>+<br />+    <destination id=”SAPFunctions”>+<br />+        <properties>+<br />+            <source>demo.sap.com.SAPFunctions</source>+<br />+        </properties>+<br />+    </destination>+<br />+</service>+<br /><br />*proxy-config.xml*</p><p> </p><p>+<?xml version=”1.0″ encoding=”UTF-8″?>+<br />+<service id=”proxy-service” +<br />+    class=”flex.messaging.services.HTTPProxyService”>+<br />+    <properties>+<br />+        <connection-manager>+<br />+            <max-total-connections>100</max-total-connections>+<br />+            <default-max-connections-per-host>2</default-max-connections-per-host>+<br />+        </connection-manager>+<br />+        true+<br />+    </properties>+<br />+    +<br />+        +<br />+        +<br />+    +<br />+    <default-channels>+<br />+        <channel ref=”my-amf”/>+<br />+    </default-channels>+<br />+    <destination id=”DefaultHTTP”>+<br />+    </destination>+<br />+</service>+<br /><br /></p><p>*messaging-config.xml*</p><p> </p><p>+<?xml version=”1.0″ encoding=”UTF-8″?>+<br />+<service id=”message-service” +<br />+    class=”flex.messaging.services.MessageService”>+<br />+    +<br />+        +<br />+        <!– –><br />    <br />    <default-channels><br />        <br />    </default-channels><br />+

Finally, project tree should look

like:

Now, we are going to modify web.xml

file to declare MessageBroker servlet. Add following xml tags into web.xml :

<servlet><br />+    <servlet-name>MessageBrokerServlet</servlet-name><br />    <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class><br />    <init-param><br />      <param-name>services.configuration.file</param-name><br />      <param-value>/WEB-INF/flex/services-config.xml</param-value><br />    </init-param><br />    <load-on-startup>1</load-on-startup><br />  </servlet><br />  <servlet-mapping><br />    <servlet-name>MessageBrokerServlet</servlet-name><br />    <url-pattern>/messagebroker/*</url-pattern><br />  </servlet-mapping></p><p> </p><p>in the remoting-config.xml file we declared a destination tag for java class to be called.</p><p> </p><p>    <br />        <br />            <br />        </properties><br />    </destination></p><p> </p><p>It is the key point of the communication. We create a destination name “SAPFunctions” which will be used in Flex Application and in the source tag we declare the java class “SAPFunctions” in the package demo.sap.com. It is time to create SAPFunctions.java: </p><p> </p><p>Right-click on the project name and select New -> Class and follow the wizard to create SAPFunctions class. Put the following code into class:</p><p> </p><p>package demo.sap.com;<br /><br />public class SAPFunctions {<br />    public String doPing(String in) {<br />        return “Hello “+ in “.SAP J2EE engine is ready to serve you.”;

+    }<br />}+

 

Now it is time to package the application into Enterprise Application Project.

Create a new development component “blaze1ear” of type Enterprise Application.

 

!https://weblogs.sdn.sap.com/weblogs/images/29528/baf4.png|height=432|alt=|width=323|src=https://weblogs.sdn.sap.com/weblogs/images/29528/baf4.png!

 

In the Referenced Projects window select our previously created project “blaze1” as reference.

 

!https://weblogs.sdn.sap.com/weblogs/images/29528/baf5.png|height=244|alt=|width=292|src=https://weblogs.sdn.sap.com/weblogs/images/29528/baf5.png!

/
1 Comment
You must be Logged on to comment or reply to a post.