Blazeds, and Java Together - A Simple Tutorial: Steps For Using Flex With Java
Blazeds, and Java Together - A Simple Tutorial: Steps For Using Flex With Java
Blazeds, and Java Together - A Simple Tutorial: Steps For Using Flex With Java
iv. Under the folder flex is an xml file named remoting-config where we will put an XML node that tells our Flex application how to connect to the Java class 4. Using a Java IDE (for example Eclipse or Flex Builder 3 with the Java plug-in) create the following Java source file named HelloWorld.java.
package example; public class HelloWorld { public HelloWorld() { } public String getHelloWorld() { return Hello From Java!; } }
Compile the Java source file into a class file (HelloWorld.class). Since our source file specified a package of example, our class file should be under a folder named example. a. Copy the example folder to [tomcat-home]\webapps\blazeds\WEB-INF\classes
5. Add the following node to [tomcat-home]\ webapps\blazeds\WEBINF\flex\remoting-config.xml right after the closing </defaultchannels> node and before the closing </service> node. Note the values for
id attribute and the value for the source tag (the complete path and name of our Java class).
<destination id=helloworld> <properties> <source>example.HelloWorld</source> </properties> <adapter ref=java-object/> </destination>
6. Stop Tomcat if its running and start Tomcat 7. Create a new Flex Project named HelloWorld
a. In the New Flex Project wizard select J2EE as the Application Server type (see the very limited instructions here for some help) b. Make sure Use remote object access service is checked c. Click next d. On the configure J2EE server uncheck use default location for local LiveCyle Data Services server e. Specify the following values for root folder, root URL, and context root i. Root folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\blazeds ii. Root URL: http://localhost:8080/blazeds iii. Context root: /blazeds f. Click on the Validate Configuration button should get the message The web root folder and root URL are valid. g. Click Next and then click Finish 8. In your HelloWorld.mxml create the following source between the <mx:Application> </mx:Application> tags
<mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.utils.ObjectUtil; import mx.controls.Alert; import mx.utils.StringUtil; private function resultHandler(event:ResultEvent):void { //used for debugging - shows details about result //returned by the Java class method
Alert.show( ObjectUtil.toString(event.result) ); } private function faultHandler(event:FaultEvent):void { Alert.show( ObjectUtil.toString(event.fault) ); } ]]> </mx:Script> <mx:RemoteObject id=ro destination=helloworld source=example.HelloWorld result=resultHandler(event) fault=faultHandler(event)/> <mx:Panel x=10 y=10 width=440 height=200 layout=vertical title=Test Flex 3 Using Java borderColor=#008040 fontFamily=Arial fontWeight=bold fontSize=13> <mx:Text text=Click The Button To Test Getting Data Into Flex From A Java Class fontWeight=bold width=250/> <mx:Spacer height=20/> <mx:Button label=Get Hello World! click=ro.getHelloWorld()/> </mx:Panel>
9. Run the Flex HelloWorld application. You should see an HTML file with a Flex panel and a Get Hello World! button. Click on the button and a Flex Alert component should appear with the words Hello from Java!. 10. Note in the mx:RemoteObject tag the value for destination matches the id attribute value and our source matches the value for the source tag in our destination node in the remote-config.xml file.
Trouble-shooting Tips
If you change the HelloWorld Java file then youll need to copy the new class file into the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder in the correct package. Then youll have to stop and restart Tomcat.
If you change the remote-config.xml file, youll need to stop and restart Tomcat. You may also need to rebuild your Flex application before running it again.
Summary:
How easily Flex works with ColdFusion Components (CFCs) is just another reason I miss ColdFusion. But my new company uses Java to develop their web applications and they are not going to change to ColdFusion. But I hope that eventually we will be able to use Flex on the front end and Java on the back end where it makes sense. But first Ive got to get smart on how to integrate Flex and Java. So Ive got alot of learning and trial and error. Ill keep you posted in this series of blog entries. Up next sending information from Flex to a Java class. http://raajasoft.wordpress.com/2009/03/17/blazeds-and-java-together-a-simple-tutorial/
BlazeDS Tomcat Java Class Configuration for Flex3 Version STEP -I Tomcat Configuration 1. Installing Apache Tomcat Version in any of your Root Folder (ver. -6.0.18) 2. In the Bin Folder the Tomcat Service can be start / stop 3. User / Password for Tomcat Service may added in tomcat-users.xml 4. Port can change in server.xml file default Port is :8080 for BlazeDS 8400 5. Every Configuration the Service should Stop and Start.
STEP II BlazeDS Configuration 1. blazeds.war (downloaded) file should place in \Tomcat[xxxx]\webapps folder 2. After place the file the blazeds folder and insider created..(Automatically) 3. in \webapps\blazeds\flex some of xml file is available for configuration like remoting proxy-config, service-config,messaging-config files (depends upon developer request)
STEP III Java Class files 1. In the \webapps\blazeds\WEB-INF\classes created classes can put inside(relevant path) STEP IV Configuration in Flex-3
d. Flex Builder 3 2. These instructions assume you know how to do the following: a. Create Java classes b. Use Flex Builder 3 c. Stop and start Tomcat 3. Download BlazeDS (these instructions are as of June 22, 2008) a. http://opensource.adobe.com/wiki/display/blazeds/Release+Builds b. Download the BlazeDS binary distribution i. Save the .zip file to your computer ii. There are two files in the zip blazeds.war and blazeds-bin-readme.html iii. Extract blazeds.war to your [tomcat-home]\webapps directory c. Stop Tomcat if its running and then start Tomcat d. In Windows Explorer navigate to the folder [tomcat-home]\webapps i. You should now have a folder named blaseds ii. Under blazeds is a folder named web-inf iii. Under web-inf are several folders, one called classes is where we will put our Java classes so that our Flex application may use them. iv. Under the folder flex is an xml file named remoting-config where we will put an XML node that tells our Flex application how to connect to the Java class 4. Using a Java IDE (for example Eclipse or Flex Builder 3 with the Java plug-in) create the following Java source file named HelloWorld.java.
package example; public class HelloWorld { public HelloWorld() { }
Compile the Java source file into a class file (HelloWorld.class). Since our source file specified a package of example, our class file should be under a folder named example. a. Copy the example folder to [tomcat-home]\webapps\blazeds\WEB-INF\classes
5. Add the following node to [tomcat-home]\ webapps\blazeds\WEBINF\flex\remoting-config.xml right after the closing </defaultchannels> node and before the closing </service> node. Note the values for
id attribute and the value for the source tag (the complete path and name of our Java class).
<destination id=helloworld> <properties> <source>example.HelloWorld</source> </properties> <adapter ref=java-object/> </destination>
6. Stop Tomcat if its running and start Tomcat 7. Create a new Flex Project named HelloWorld a. In the New Flex Project wizard select J2EE as the Application Server type (see the very limited instructions here for some help) b. Make sure Use remote object access service is checked c. Click next d. On the configure J2EE server uncheck use default location for local LiveCyle Data Services server e. Specify the following values for root folder, root URL, and context root i. Root folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\blazeds
ii. Root URL: http://localhost:8080/blazeds iii. Context root: /blazeds f. Click on the Validate Configuration button should get the message The web root folder and root URL are valid. g. Click Next and then click Finish 8. In your HelloWorld.mxml create the following source between the <mx:Application> </mx:Application> tags
<mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.utils.ObjectUtil; import mx.controls.Alert; import mx.utils.StringUtil; private function resultHandler(event:ResultEvent):void { //used for debugging - shows details about result //returned by the Java class method Alert.show( ObjectUtil.toString(event.result) ); } private function faultHandler(event:FaultEvent):void { Alert.show( ObjectUtil.toString(event.fault) ); } ]]> </mx:Script>
<mx:RemoteObject id=ro destination=helloworld source=example.HelloWorld result=resultHandler(event) fault=faultHandler(event)/> <mx:Panel x=10 y=10 width=440 height=200 layout=vertical title=Test Flex 3 Using Java borderColor=#008040 fontFamily=Arial fontWeight=bold fontSize=13> <mx:Text text=Click The Button To Test Getting Data Into Flex From A Java Class fontWeight=bold width=250/> <mx:Spacer height=20/> <mx:Button label=Get Hello World! click=ro.getHelloWorld()/> </mx:Panel>
9. Run the Flex HelloWorld application. You should see an HTML file with a Flex panel and a Get Hello World! button. Click on the button and a Flex Alert component should appear with the words Hello from Java!. 10. Note in the mx:RemoteObject tag the value for destination matches the id attribute value and our source matches the value for the source tag in our destination node in the remote-config.xml file.
Trouble-shooting Tips
If you change the HelloWorld Java file then youll need to copy the new class file into the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder in the correct package. Then youll have to stop and restart Tomcat. If you change the remote-config.xml file, youll need to stop and restart Tomcat. You may also need to rebuild your Flex application before running it again.
Summary:
How easily Flex works with ColdFusion Components (CFCs) is just another reason I miss ColdFusion. But my new company uses Java to develop their web applications and they are not going to change to ColdFusion. But I hope that eventually we will be able to use Flex on the front end and Java on the back end where it makes sense. But first Ive got to get smart on how to integrate Flex and Java. So Ive got alot of learning and trial and error. Ill keep you posted in this series of blog entries. Up next sending information from Flex to a Java class.