Pages

Friday, January 15, 2010

Adobe Flex in Weblogic with BlazeDS & EJB3

In a earlier post I already made Adobe Flex / BlazeDS / EJB2.1 example and this example was deployed on an OC4J J2EE container. In this post I let the same example run in Oracle Weblogic 10.3.2 ( FMW11g) with the BlazeDS jars as a shared library ( this also works with Adobe Lifecycle). Also in the earlier post I needed to use EJB2.1 but with EJB factory of Peter Martin I can use Eclipselink.
To start, we need to download BlazeDS and EJB and Flex Integration jar, Extract these archives so we can copy the jar files to a new location.

We need to make a shared library for weblogic. This is better then just add all the jars to WEB-INF/lib folder of every web application. You can patch the blazeds jars without re-deploying your webapps and you now know exactly which version of blazeds you are using.
Make a folder called blazeds with as subfolders APP-INF and META-INF and add a empty zip in it and call it empty.jar

Copy the blazeds and ejb factory jars in the APP-INF/lib folder

In the META-INF folder we need to add two files application.xml and MANIFEST.MF where we will add the library information for weblogic.

The application.xml

<?xml version = '1.0' encoding="UTF-8" ?>
<application xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.4">
<description>BlazeDS Library</description>
<display-name>blazeds</display-name>
<module>
<java>empty.jar</java>
</module>
</application>

The MANIFEST.MF has this content
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0RC1
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Extension-Name: blazeds
Specification-Version: 3.2
Implementation-Title: BlazeDS - BlazeDS Application
Implementation-Version: 3.2.0.3978
Implementation-Vendor: Adobe Systems Inc.


We are ready to add this library to the Weblogic Server. The library folder is on the same file system as the weblogic server so I don't need to make an EAR file, I can just use the exploded folder. Open the Weblogic Console and go to Deployments. Here we can install a new Deployment.

Go to blazeds library folder
Install it as a libray

Weblogic will detect the manifest and application.xml and press Finish


In the deployment page we can see the blazeds library.
In the ViewController project we need to make a reference to this shared libray, to do this add a weblogic deployment descriptor. We can use weblogic-application.xml located in the META-INF folder of the EAR or use weblogic.xml in the WEB-INF of the Viewcontroller project. Here is an example of my weblogic-application.xml

<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-application">
<library-ref>
<library-name>blazeds</library-name>
</library-ref>
</weblogic-application>

The last steps is to configure the web.xml for blazeds and the blazeds configuration files for the EJB call.
first the web.xml of the viewcontroller project.

<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<description>Empty web.xml file for Web Application</description>

<servlet>
<servlet-name>MessageBrokerServlet</servlet-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>

<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>


<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
</web-app>

I use the remoting-config.xml and services-config.xml files both located in WEB-INF/flex folder
Here is my remoting-config.xml file, where source element is the JNDI name of my EJB Session Bean, after deployed of your model you can look it up in the Weblogic console ( servers, select the server and in the top there is a link to the jndi page )

<?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="EmployeeEJB">
<properties>
<factory>ejb3</factory>
<source>flex_ejb2-Model-HRSessionEJB#nl.whitehorses.model.services.HRSessionEJB</source>
</properties>
</destination>
</service>

my services-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="remoting-config.xml"/>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>
<factories>
<factory id="ejb3" class="com.adobe.ac.ejb.EJB3Factory"/>
</factories>
<channels>
<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[Flex]</prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
</target>
</logging>
</services-config>

Deploy everything to the Weblogic server.
and at last the Adobe mxml where I call the getEmployeesFindAll method.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="1155" height="206.21213">
<mx:applicationComplete>srv.getEmployeesFindAll()</mx:applicationComplete>

<mx:RemoteObject id="srv" showBusyCursor="true" destination="EmployeeEJB"/>
<mx:DataGrid width="1104.6212" dataProvider="{srv.getEmployeesFindAll.lastResult}" height="140.98485"/>

</mx:Application>

9 comments:

  1. Hi , the integration part looks nice , but please tell me where is the source code of EJB your Files (HRSessionBean)

    ReplyDelete
  2. Hi,

    here you got the link to the jdeveloper project

    I got something extra, I add push to flex with blazeds and ejb, I will make a blog about it.

    http://www.sbsframes.nl/jdeveloper/flex_ejb2.zip

    thanks

    ReplyDelete
  3. Nice example. Do you have an example of accessing weblogic web services instead of ejb. We are trying to expose our wls 10.3.2 webservices to be consume either by flex or silverlight and I have a hard time finding some examples on how to do it.
    Thanks

    ReplyDelete
  4. Hi,

    Did you read this http://biemond.blogspot.com/2008/04/flex-and-web-services-using-blazeds.html

    here you define an endpoint in blazeds and in flex use mx:WebService where you add the requested operation.

    else is the same as this blog entry.

    hope this helps

    thanks

    ReplyDelete
  5. Hi Edwin,
    I have one struggle with these types of applications in Java 1.4 / Weblogic 8. When you have a Blaze DS or LCDS server on Server A and A Weblogic Server on Server B - we always have to put an RMI "client" jar on the LCDS server "web-inf' lib which means that any time the client changes - even a small bit - we have to recycle the entire LCDS instance to get it to work correctly. (i.e if we add some new methods)

    Is there any other alternative for sharing Java objects between the front and the backend - so that you are not always recycling servers?

    Thanks in advance!

    ReplyDelete
  6. Hi,

    You can try to use shared libraries. Then you only have to deploy a library with the java objects and give it a higher version. without redeploying the webapp

    thanks

    ReplyDelete
  7. I'm a new to EJB3 and flex integration. Would you recommend any book or article? I'd really appreciate if you could link me to a sample project.

    Thanks a lot
    Dev

    ReplyDelete
  8. Hi, I am using tomcat, what changes we need to do in order to use shared libraries instead of putting them in WEB-INF/lib folder.
    web.xml has blaz-ds specific entries which refers WEB-INF/lib only. how to configue so that these entries will refer to shared lib on same file system.
    Thanks

    ReplyDelete
  9. Hi,

    dont know shared libraries is supported in tomcat, it is a weblogic feature, you should check the tomcat documentation

    thanks

    ReplyDelete