Using Flex, BlazeDS, and Java Together - A Simple Tutorial
Introduction
When you want to directly use Java classes to provide data to a Flex application you need to add some additional plumbing that enables Flex to "talk with" the Java classes. Flex comes ready to rock with ColdFusion Components, but doesn't have everything it needs to communicate directly with Java classes exposed by a J2EE or servlet container such as Tomcat.
I know that Flex can use either web services or HTTP services to communicate with a Java servlet or JSP page, but what I want to be able to do is leverage my Java classes directly to provide data to Flex, similar to how a ColdFusion Component can be called using the <mx:RemoteObject> tag and return complex data to the Flex application.
Adobe offers 3 different technologies (reference 1) that have different costs and provide different services (see references 2 and 3) for integrating Flex with Java.
BlazeDS is "the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data..." (reference 4). As I understand it BlazeDS is the free open-source plumbing we need to install in our server to allow Flex to communicate with Java classes.
Since I recently changed jobs from a company that used Flex and ColdFusion to a company using Java to create web applications, I need to learn how to integrate Flex and Java. I won't get into how much I miss creating web applications using ColdFusion 8 (it's alot). I hope to eventually show my new co-workers the benefits of using Flex on the front-end of our web applications. To do that I need to get Flex working with Java on the back end.
This is the first in what I hope will be a series of posts showing how to use Java on the back end with Flex on the front end and BlazeDS providing the plumbing to enable Flex and Java to work together. I'm starting off very easy with a "Hello World" example.
Frustration
I spend much of a Sunday morning just trying to find a good example of integrating Flex and Java using BlazeDS. The BlazeDS web site (reference 5) was not the most helpful. First they expect you to download a complete turn-key system that includes a version of Tomcat, the BlazeDS application, and several examples. They then explain how to run the examples but only if you've downloaded their turn-key system. I already have Tomcat running on my Java web application development server so I really just wanted to learn how to integrate BlazeDS into my existing Flex Builder 3 and Tomat server development environment.
I would have happily studied their example code to try to figure out how to use BlazeDS but after searching throughout the BlazeDS web site I could not find a download just for the example applications source code.
After several hours of trial-and-error, I think I've come up with the steps to get Flex, BlazeDS, and Java working together. So this blog article will hopefully help you (and me) learn how to get Flex, BlazeDS, and Java working together. A demo of the example application you'll build using the instructions below can be viewed here.
Steps for Using Flex With Java
1. Note my development system setup. If your system setup is different then you'll need to adjust these instructions.
a. Windows XP
b. Tomat 6.0 installed in C:\Program Files\Apache Software Foundation\Tomcat 6.0\ referred to as [tomcat-home]
c. Tomat server running on port 8080
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 it's 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() {
}
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\WEB-INF\flex\remoting-config.xml right after the closing </default-channels> 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 you'll need to copy the new class file into the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder in the correct package. Then you'll have to stop and restart Tomcat.
If you change the remote-config.xml file, you'll 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 I've got to get smart on how to integrate Flex and Java. So I've got alot of learning and trial and error. I'll keep you posted in this series of blog entries.
Up next - sending information from Flex to a Java class.
References
- LiveCycle Developer Center
- LiveCycle ES vs LiveCycle DS vs BlazeDS - clearing up the confusion
- BlazeDS and LCDS Feature difference
- BlazeDS Overview
- BlazeDS
- Creating Flex Builder Projects that Use Server Technologies
(mx.rpc::Fault)#0
errorID = 0
faultCode = "InvokeFailed"
faultDetail = "Couldn't establish a connection to 'helloworld'"
faultString = "[MessagingError message='Destination 'helloworld' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']"
message = "faultCode:InvokeFailed faultString:'[MessagingError message='Destination 'helloworld' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']' faultDetail:'Couldn't establish a connection to 'helloworld''"
name = "Error"
rootCause = (null)
**help! i'm really lost.. dunno what to do =(
1. Verify that HelloWorld.class is in the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder
2. Double check that you've entered the correct node data in remote-config.xml
3. Restart Tomcat
4. Ensure in the mxml file that in the mx:RemoteObject tag source = "example.HelloWorld" is there
5. Check your project properties for the correct root folder, root url, and context root (click the test configuration button to verify them)
6. Do a complete clean of your Flex project
After doing the above try re-running the flex project.
Good luck, Bruce
but i dont know what is the problem.. i just followed your trouble shooting tips.. and it works.. O_O.. haha.. anywayz.. thank you thank you!!!
your post really helped me a lot.. i tried different site before and i got lost somewhere.. but your post is really complete and really step by step.. ^^
i am working on a project, using flex as front end and java as the backend.. i tried webservice before (with the wsdl stuff).. but i think I read somewhere that BlazeDS is better right? hehehe.... i guess i will try BlazeDS for now.. see how far I could get from there.. =)
go go go! ^^
BlazeDS is supposed to be the fastest way for Flex to communicate with Java on the backend.
I'll be doing a series of blog posts on using Flex and Java with BlazeDS providing the plumbing between the two. But I'm just learning how to use BlazeDS myself, so keep us posted on your experience with using Flex and Java.
sure sure.. i'm also learning/exploring the BlazeDS right now.. hehe.. trying to connect to DB now.. hehe.. hope it works.. :D
i will surely keep you posted about my experience.. hehe.. thanks =)
go go go! ^^ will visit your site very often.. :D
i was able to succesfully get data from my DB! yey! improving! (more to go~)
i guess if it not for your blog article.. i would still be stuck in figuring out how to make that BlazeDS works.. hehe. =D
i just realized that it's quite the same as the WebService.. well. ofcourse, now I have to use RemoteObject instead of WebService and method instead of operation.. aside from that I guess everything is quite the same.
I guess there's still lot to learn as I work on my project.. but this is already a good start! Thanks :D
- Jen
Keep doing great work
One thing that further guided our decision to use web services was the inherent debuggability and interoperability of the textual XML format. AMF may be touted as more performant but properly designed services should never be so fragile that they depend upon a binary format to achieve responsiveness. In addition, though AMF is now an open protocol there are not a huge number of implementations. Therefore, you are effectively in a case of vendor lock-in.
Either way, thank you for taking the time to write this tutorial for the greater good of us all.
I agree with you that AMF is much better option if we have to transfer lots of data. But there is not benchmark available like if you have 50 kb of data to be tranferes use AMF.
some thougths from your side
For small amounts of data I don't think there would be much difference between AMF and XML. However, my goal here is to see if BlazeDS will enable me to put a Flex front end on some Java web applications that return several hundred objects to a JavaServer Page where the objects are displayed using a mixture of JavaScript and Struts2 tags.
I think a Flex front end (based on my previous job) would provide a much nicer and easier to maintain user interface. But first I need to verify that BlazeDS will provide the plumbing between Flex and Java as the Java back end is not going to change.
Thanks for sharing, I am sure it will save a day for many developers.
sample apps come with blazeads is good start point to understand how everything works..cool
hibernate files are "hibernate.cfg.xml" and "<name of class-mostly on table name>.hbm.xml".
also make sure you copy all the hibernate jar files in "webapps\blazeds\WEB-INF\lib" directory. Make sure you have mysql and jdbc driver in place (if you have existing app connecting to mysql using tomcat you don't have to do anything apart from previous steps)
You are great!
I had a problem when a extract the 2 files from BlazeDS binary distribution. I extract this file, blazeds.war to C:\Archivos de programa\Apache Software Foundation\Tomcat 6.0\webapps, i restarted Apache but there's not a blazeds folder in the directory, only blazeds.war file.
Any suggestion? thk
Nice work Bruce!!
keep on this
A couple of things that are confusing to me though - when creating a new Flex Project using J2EE server as the server type, the wizard asks me for a 'root folder' (as you've mentioned here.) I got around this by mounting my blazeds application folder on the remote server using samba, but does this mean that any application I develop using flex will rest on the same server as my J2EE server? What if I just want to make a html and swf that talk to the remote java object? Your example here runs fine..but when I move the html and swf to my local machine and run it, it gives me a bunch of errors. I couldn't find a configuration file with the project that would allow me to change the remote blazeds server url.
Hope I'm making sense. Thanks much in advance!
I am facing this problem...I tryed to set a variable called 'data' in the HelloWold.java . In my processSayHello function inside my mxml I have some this:
ro.setMe("moussa");
now when I try to print this text (which it should print moussa), it prints null..
any suggestions?
Thanks in advance
I get the same (or very similar) error when trying to access a Java class using the Flex RemoteObject class. I have the destination "helloworld" defined in remoting-config.xml on the server. Is there something I need to do to tell the Flex client about that file? I know I can pass the "-services c:\path-to\services-config.xml" so that it knows about services, but how do I tell it about Remote objects?
My "RemoteObject" has the destination entered correctly and the "source" is also set.
Any ideas?
My services-config.xml was not including "remoting-config.xml".
Snippet:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="messaging-config.xml" />
<service-include file-path="data-management-config.xml" />
<service-include file-path="remoting-config.xml" />
</services>
...
</services-config>
I got
"Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid."
Your example looks really cool and really helped me in learning the Flex integration with Blazeds and Java.
But it would be great if you help me out for the below scenario.
My Blazeds server is located in remote machine. Say for example, http://131.60.60.60/blazeds.
And i have my Flex installed in other machine. If i want to include the above mentioned URL in the FlexAPP to retrieve the method of the class located in Blazeds server, how can I?
ie, Flex code talking with the Blazeds located in other machine.
Thanks in Advance
mx.messaging.channels::AMFChannel)#2
messageAgents = (Array)#7
[0] (mx.rpc::AsyncRequest)#8
authenticated = false
autoConnect = true
channelSet = (mx.messaging::ChannelSet)#4
clientId = (null)
connected = false
defaultHeaders = (null)
destination = "helloworld"
id = "39802F25-7BA6-1D57-42CC-04A5991AA383"
reconnectAttempts = 0
reconnectInterval = 0
requestTimeout = -1
subtopic = ""
connected = false
connectTimeout = -1
enableSmallMessages = true
endpoint = "http://localhost:8080/blazeds/messagebroker/amf&qu...;;
failoverURIs = (Array)#9
id = "my-amf"
mpiEnabled = false
netConnection = (flash.net::NetConnection)#10
client = (mx.messaging.channels::AMFChannel)#2
connected = false
objectEncoding = 3
proxyType = "none"
uri = "http://localhost:8080/blazeds/messagebroker/amf&qu...;;
piggybackingEnabled = false
polling = false
pollingEnabled = true
pollingInterval = 3000
protocol = "http"
reconnecting = false
recordMessageSizes = false
recordMessageTimes = false
requestTimeout = -1
plz tell abt this error i am waiting for your reply
Until you, nobody has taken a moment to properly explain, really step by step, this thing. All the other explanations miss steps or make it much more complicated than it acually is. I also spent one morning messing around, and your tutorial help me to achieve it in 10 mins!
Thanks very much, if anytime, in this or other life, i'll meet you, remember me to invite you to some beers!!! :)
I am trying to set up blazeDS on a remote server, and I am not sure how to configure the compiler (-services) and server settings (root folder) to make it work. I keep getting errors about invalid root folder, or the web server cannot be connected. I would appreciate any pointers you can give me. Thanks a lot!
Christina
To resolve the problem of getting "Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid." you need to install this version of Apache Tomcat :http://tomcat.apache.org/download-60.cgi
and the problem will be gone.
Cheers
but i want know about where to put jsp in which folder?
is it jsp in WEB_INF of blazeds or other folder? or
any steps is neccesary plz reply to me?
Finally a nice tutorial. Seems good and working good so far.. but i am having a little problem in step 7-f... when i press the button.. it says
'Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid.'
however i have checked in browser, 'http://localhost:8080' is working fine
can you tel me what can be wrong?
i wil also try continue so that it might work...
thanks alottttt for your tutorial...
i just copied the rong example folder...
no need to reply now
thanks again
leme try this on my actual application now
hope that works .. coz m stuck on it for about a month now :(
This is Kartik and a newbie flex aspirant.
I am making a flex application with J2EE(Glassfish server) + Flex .
I was trying to explore Blaze DS but the problem is that i am unable to deploy in Glassfish server.
Can u please give me some insights as to how to install Blaze DS on a glassfish server or whether Glassfish doesn't support Blaze DS.
Also please provide me with some material wrt Blaze DS.
Regards
M.Kartik
I have been struggling last couple of days to get blazeds for with jboss. I did follow the steps in this article but like some of you have faced I am not able to successfully validate the flex server "Cannot access the web server. The server root folder or root URL may be invalid". Could you please direct me to solve this problem.
Another question was, if it is any different with a JBOSS App Server and how do you run the HelloWorld.mxml.
i want to learn how to communicate database from the flex ?
this material is indeed of great learning...
Since Monday I've been trying to find out how to set-up a sample project in such an environment and obviously neither of BlazeDS docs nor any other help could be found in setting up a project over an existing J2ee web-server.
cheers to u... I could run my first sample without much fuss.
As it is evident that you've been into blazeDS for the past 4 months n you have done a lot, please have your valuable ideas on the implementations through any of J2ee architecture, preferably Struts.
FaultHandler=(mx.rpc::Fault)#0
errorID = 0
faultCode = "Server.ResourceUnavailable"
faultDetail = "Type 'HelloWorld' not found."
faultString = "Cannot create class of type 'HelloWorld'."
message = "faultCode:Server.ResourceUnavailable faultString:'Cannot create class of type 'HelloWorld'.' faultDetail:'Type 'HelloWorld' not found.'"
name = "Error"
rootCause = (null)
the article it was really helpful. For me it worked.
Just a little question, is it posible to acces this way the beans exposed in an Enterprise Aplication (an .ear) in Glassfish?
Thank you very much,,
but I am new to Java when I tried your above example I got all
the things placed proper and could run the application.
But I got an following error whie cliked on the "Get Hello World!" button.
ERROR Details are as follows:
(mx.rpc::Fault)#0
errorID = 0
faultCode = "Server.Processing"
faultDetail = (null)
faultString = "Bad version number in .class file (unable to load class example.HelloWorld)"
message = "faultCode:Server.Processing faultString:'Bad version number in .class file (unable to load class example.HelloWorld)' faultDetail:'null'"
name = "Error"
rootCause = (Object)#1
cause = (null)
localizedMessage = "Bad version number in .class file (unable to load class example.HelloWorld)"
message = "Bad version number in .class file (unable to load class example.HelloWorld)"
"
I tried doing following.
I was having JDK 1.6 and JRE 1.6
I uninstalled Jdk and installed the previous version jdk 1.5
I unistalled Apache Tomcat 6.0.18 and reinstalled
And repeated above steps again
I tried the troubleshooting tips given above, still it gives errors.
But still I am getting the same error can you help me resolving this.
Thanks
Iresh SA
Instead of the modifications to blazeds in tomcat. You can do these in the Flex Builder project themself.
Overall nice that you shared this info. At this moment you are my guru djie. ;)
Thanks
Pedro
Your article is excellent, its help me a lot. You cover everything from top to bottom also most important thing Trouble-shooting (most authors do not care then you can see a long list of comments) .I just follow your instruction; create my own java class and its works like charm.
Thanks Bruce
Lincoln
help me a lot. Also i really like your style you cover ev
..
Mine reports back "Hello from Java" just like it should when built as a web application(which runs in Flash Player). But when I build it as a desktop application (to run in Adobe Air), I get the following error after clicking "Get Hello World!":
(mx.rpc::Fault)#0
errorID = 0
faultCode = "Client.Error.MessageSend"
faultDetail = "Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://ain.swf/blazeds/messagebroker/amf'"
faultString = "Send failed"
message = "faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://ain.swf/blazeds/messagebroker/amf''"
name = "Error"
rootCause = (mx.messaging.events::ChannelFaultEvent)#1
bubbles = false
cancelable = false
channel = (mx.messaging.channels::AMFChannel)#2
authenticated = false
channelSets = (Array)#3
[0] (mx.messaging::ChannelSet)#4
authenticated = false
channelIds = (Array)#5
[0] "my-amf"
channels = (Array)#6
[0] (mx.messaging.channels::AMFChannel)#2
clustered = false
connected = false
currentChannel = (mx.messaging.channels::AMFChannel)#2
initialDestinationId = (null)
messageAgents = (Array)#7
[0] (mx.rpc::AsyncRequest)#8
authenticated = false
autoConnect = true
channelSet = (mx.messaging::ChannelSet)#4
clientId = (null)
connected = false
defaultHeaders = (null)
destination = "helloworld"
id = "E363D005-8B85-50F3-8143-222B15E86D30"
reconnectAttempts = 0
reconnectInterval = 0
requestTimeout = -1
subtopic = ""
connected = false
connectTimeout = -1
enableSmallMessages = true
endpoint = "http://ain.swf/blazeds/messagebroker/amf"" target="_blank">http://ain.swf/blazeds/messagebroker/amf";
failoverURIs = (Array)#9
id = "my-amf"
mpiEnabled = false
netConnection = (flash.net::NetConnection)#10
client = (mx.messaging.channels::AMFChannel)#2
connected = false
objectEncoding = 3
proxyType = "none"
uri = "http://ain.swf/blazeds/messagebroker/amf"" target="_blank">http://ain.swf/blazeds/messagebroker/amf";
piggybackingEnabled = false
polling = false
pollingEnabled = true
pollingInterval = 3000
protocol = "http"
reconnecting = false
recordMessageSizes = false
recordMessageTimes = false
requestTimeout = -1
uri = "http://{server.name}:{server.port}/blazeds/messagebroker/amf"
url = "http://{server.name}:{server.port}/blazeds/messagebroker/amf"
useSmallMessages = false
channelId = "my-amf"
connected = false
currentTarget = (mx.messaging.channels::AMFChannel)#2
eventPhase = 2
faultCode = "Channel.Connect.Failed"
faultDetail = "NetConnection.Call.Failed: HTTP: Failed: url: 'http://ain.swf/blazeds/messagebroker/amf'"
faultString = "error"
reconnecting = false
rejected = false
rootCause = (Object)#11
code = "NetConnection.Call.Failed"
description = "HTTP: Failed"
details = "http://ain.swf/blazeds/messagebroker/amf"" target="_blank">http://ain.swf/blazeds/messagebroker/amf";
level = "error"
target = (mx.messaging.channels::AMFChannel)#2
type = "channelFault"
The only clue that really stands out to me is the missing letter in all of the URLs right after 'http://'. Any help in proceeding with AIR would be appreciated.
Thanks for the clear, well-documented article,
JackD
Your article is very informative, thanks for such an article.
I have a doubt, as to how to this integration in case the server is not on your working system. i.e you need to deploy blazeds on a server system.
thanks in advance
shot. I am also now planing to develop an application with java backend
and flex as front end. Waiting for your next blogs related to this.
Appreciate your effort and time for such a nice and clear article.
Your material helped me a lot. Thanks!
I am trying to connect database(MySQL) with Java and Flex. I have a method in java class returning List, now want to save that list in ArrayCollection.
Please suggest me how I have to fetch List(of objects) from Java Class into .mxml file.
Read through the entire series I wrote on using Java, BlazeDS, and Flex. The last article using Java to get information from a database and return an ArrayList to Flex.
See: /blog/index.cfm/FX
Bruce
I'd like to thank you for your information you put on your site. It sure helped me to start with passing objects between java and flex!
I have a little remark though ;)
I noticed you have in your <mx:RemoteObject> a property source="example.HelloWorld" but this is unnecessary as it finds this information in the remoting-config.xml.
Just my 5 cents ;)
cya
I have a typical scenario. I have an already existing java project(say Sample). Now this is deployed in tomcat. I am developing an UI using flex for the homepage of this project. I include the flex nature by right clicking the java project(Sample) and got sample.mxml created. Now the problem is
my tomcat is installed in C:/Porgram Files/Apache Software foundation and the blazeds i downloaded is extracted to the tomcat_home/webapps folder. But my source code for the project Sample is in C:/Sample and the output folder is also within the same folder(C:/Sample/Webapps). Whenever i compile the java project the output goes to this folder by default. I need to use some existing java classes and methods to get the data for the home page of this flex application. But by default my flex application looks for the class files in tomcat_home/webapps/blazeds/web-inf/classes folder. How do i configure my flex application to make use of the java classes that are already there deplyed in the tomcat server.
I tried changing the root of the flex server , url and context to my project(Sample/webapps) but it could not validate the configurations. Please let me know how to configure this scenario.
Thanks
Sunil
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://localhost:8080/blazeds/messagebroker/amf&qu...;; class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
I have the mxml file like you mentioned and compiled. I'm not using Flex Builder. Would really appreciate your help and/or any other person. Thx !
Thanks for this great tutorial! I did it too!
By the way do you have some advices to handle session in BlazeDS (idea is to perform a login, logout, etc)
Thank you. Your comments will be highly appreciated.
I am also getting the same "Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid." error, and I also have installed " apache-tomcat-6.0.18, the version of tomcat. so please please please help me. What should I do to get it work correctly.
Please help me out.
Can you please help me out, I have been stucked.
Please please help me out.
Thanx in advance.
Regards
Amit Giri
i got some nasty errors when i followed your instructions.
I downloaded the blazeDs.war from the site you recommended.
I am using flex builder 3.
I did the following to create a project:
File->New->FlexProject.. a pop-up askes me to
Project name: HelloFlexFromJava
Project location is the default:C:\Documents and Settings\Administrator\My Documents\Flex Builder 3
Application Type: Web Application(runs in Flash Player)
Application server type:J2EE
selected the Useremote object access service & Live Cycle Data Services
Selected Create combined Java/Flex project using WTP.....
Next Button is clicked and leads me to:
J2EE Settings:
Target runtime: Apache Tomcat v6.0
Context root:HelloFlexFromJava
Content Folder:WebContent
Flex War file:C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.18\webapps\blazeds.war
Other options are as default
Then i click Finish.
The Directory structure in Flex Navigator is as:
---------HelloFlexFromJava
+bin-debug
flex_libs
-flex_src
+HelloFlexFromJava.mxml
+html-templates
-src
-example
HelloWorld.java
-WebContent
+META-INF
-WEB-INF
-classes
-example
HelloWorld.class
-flex
messageing-config.xml
proxy-config.xml
remoting-config.xml
services-config.xml
+libs
src
web.xml
The above is the flex navigator structure.
However i tired two ways:
a) Since i am asked to show the flex war file, in that case i used blazeDs.war file as i had found in a blog to use it.
b)Since in your tutorial you have asked to extract the blazeDS war file.
I did everything upto my best knowledge.
I get those hasty busty nasty errors as posted by:Jen Sze
Please help me,i come from the back-ground of using wicket and i want to try my fingers in Flex
Another doubt is if the Java classes are being compiled and transformed into some form of ActionScript classes.
Maybe I'm lost in space, so please I need a light in the darkness, thank you.
Appreciate your efforts.
~Sudhir
thanks for posting very good tutorial about flex-java project. After done with everything I got following error.
(mx.rpc::Fault)#0
errorID = 0
faultCode = "Server.ResourceUnavailable"
faultDetail = "Method 'getHelloWorld' not found."
faultString = "Cannot invoke method 'getHelloWorld'."
message = "faultCode:Server.ResourceUnavailable faultString:'Cannot invoke method 'getHelloWorld'.' faultDetail:'Method 'getHelloWorld' not found.'"
name = "Error"
rootCause = (null)
I follow the your previous comment but still I haven't solve the issue. and can you please send me the blazeds\WEB-INF\service-config.xml and
blazeds\WEB-INF\flex\remoting-config.xml
Bruce
you saved my day.
You are awsome man,.. as im new to flex. since 3 days am strugling to
execute a sample program.... luckily i found this blog vch is very help ful,.
and am able to run the program ..
thanku very much,,,,,... going foraward i want to develop some more
complicated examples,.. for vch i need your help,..
once again thanku verymuch,....
I've run into troubles at step #5, but changing the write/read rights for the blazeds folder let me succsessfully validate the server. Usually only users with administrator rights might write in the program folder. (I don't worry about security issues, because I don't intend to use that server in the wild/web - others may find a better solution.)
Thanks again for that great tutorial, I'll recoment it to my fellow student :-)
Thanks for this tutorial. this is very useful for me to learn blazeDS with Flex.
i followed your instruction step by step everything is fine but while running the application it shows the following error.
(mx.rpc::Fault)#0
content = (null)
errorID = 0
faultCode = "Server.ResourceUnavailable"
faultDetail = "Type 'example.HelloWorld' not found."
faultString = "Cannot create class of type 'example.HelloWorld'."
message = "faultCode:Server.ResourceUnavailable faultString:'Cannot create class of type 'example.HelloWorld'.' faultDetail:'Type 'example.HelloWorld' not found.'"
name = "Error"
rootCause = (null)
please help me to solve this error.
- Bala
Thanks for the step by step instruction.
I tried to use remote object and struggle for 2days but after going through your blog i test success. Many thanks to you and keep writing.
cheers,
Aniket
I'm using WAMP 2.0 on my machine and I was receiving that "Cannot access the web server" warning like many others. On a whim I went to the WAMP menu in the taskbar and when to: Apache -> Alias directories -> Add an alias. This opens a command-line and I created an alias (in my case I called it 'flex') . You are then prompted to enter the file path to the directory (the directory must already exist) , in my case I created a folder in the root directory of my c drive "c:\FLEXWEB" because I'm lazy and didn't want to type a long file path. success.
Now I tried to create a project ion flex again and this time when I configured the server:
Web root: C:\FLEXWEB
Root URL: http://localhost/flex
Output folder: C:\FLEXWEB\nameofproject-debug
The web root and URL where now magically valid. I don't know why this worked - I do know that I've messed with the HOST's file and the httpd-vhosts.conf file to set up convenient way's of accessing web-projects I've been working on and I can make wild uneducated assertions that what I did created a clean and uncorrupted virgin space for the magic flex voodoo dance... but really I don't know - I just hope this helps someone whatever the explanation is.
"Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid"
but only if I'm using a remote server. On localhost, everything works great.
(I'm using Flexbuilder 3 and tomcat 5.5).
I think maybe it's because of the environment variables java_home and java_catalina that aren't visible for the flex-builder (because in localhost everything works great)?
Anyone a clear answer how to manage this problem. I've already lost to much time finding a solution. :-(
Regards,
Flens
thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx: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) );
}
]]>
</fx:Script>
<fx:Declarations>
<mx:RemoteObject id="ro" destination="helloworld"
source="HelloWorld"
result="resultHandler(event)"
fault="faultHandler(event)"/>
</fx:Declarations>
<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>
</mx:Application>
Note : I have removed the package example from the java class. Now it's just HelloWorld.
It's working in Tomcat 7 and Adobe Flex Builder 4
Thank you so much for this wonderful tutorial. I'm amazed that you posted this article almost three years ago and it still the best simple example for BlazeDS out there.
Congratulations!
P.S. Please update for Flex 4. Ashu's example is good except for line 2 has an extra ";".
Thanks
Swaroop
(mx.rpc::Fault)#0
errorID = 0
faultCode = "InvokeFailed"
faultDetail = "Couldn't establish a connection to 'helloworld'"
faultString = "[MessagingError message='Destination 'helloworld' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']"
message = "faultCode:InvokeFailed faultString:'[MessagingError message='Destination 'helloworld' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']' faultDetail:'Couldn't establish a connection to 'helloworld''"
name = "Error"
rootCause = (null)
Hi Bruce I have tried your steps but I get the this error. could you explain What I could be missing. Its really disppointing
I did a lot of rechecking on my project and I came to know that the fault is coming because of the unchecking the option of 'use remote object access service' just below the option to select the Application server type (J2EE). I had unchecked it under the impression that this radio option has to be selected only for Live cycle data services. This can be usual reaction of any developer who has not done it before. My request is to alway keep this option selected but in the next screen one can uncheck the first option in the Server technology which asks for the checking the selection of use default location for local live cycle Data Services server. May be because of so many configuration to be done here and some configuration there this point may miss the attention. Moreover, I could explore the possibilities of configuring these setting after we have created the project but unforunately couldn't see any breakthrough. I will definitely post if I will find any way. In the mean time if any one comes across any way to configure these setting later on then, that will be an ice breaker.
Your blog really helped me get started with flex + java (using blazeds).I was able to call java functions from my flex app.
Is it possible that we connect to a java application through this blaze ds integration and at the same time the java app is also able to recieve data through its own socket server from different devices.
I followed the instructions and after a struggle of two weeks, succeeded in creating an application to transfer data between Flex and Java.
Thanks bro.
Also, for AIR applications, I found this link to make this example work - http://www.techierichnet.com/2010/06/air-with-blaz...