4 Replies Latest reply on Sep 17, 2009 1:31 PM by Cr99

    communicating with flex from html

    Cr99 Level 1

      I have a flex/air application that I want to be able to talk to using an html form.  The air application will run on the server and the user will visit a plain old vanilla html web page, submit his data and then the air app will do its business (which involves generating some images) on the server and then (using java) serve up a static version of the images created on another html web page created on the fly.


      I know how to do all this with flex in a browser via BlazeDS, but how can I open things up for those who only have access to a normal web page (for security reasons).  Does anyone know how this should be done?



        • 1. Re: communicating with flex from html
          Cr99 Level 1

          Hasn't anyone had to do this?


          The essence of my problem is: how do you initiate communication from the server side without using BlazeDS (or perhaps using BlazeDS but where the original data is coming from a servlet).  All the examples I can find are where flex is communicating to some service and is the initiator, not the other way around which is what I need to do.

          • 2. Re: communicating with flex from html
            JeffryHouser Level 4

            I think you have a misleading subject line; because HTML is not exactly a server side technology.


            You need some type of push technology.  I do not believe that BlazeDS will do it, but LiveCycle should.  I believe WebORB and GraniteDS have push features too.

            • 3. Re: communicating with flex from server - event generated by server
              ozDiGennaro Level 1

              Please accept my attempt:


              If you use an HTTPService request from you flex application (in  the browser) and set the timeout to "no timeout" (see Livedocs), when the server eventually responds to the request, your service handler function will run.  The response can include the data you need, or it can simply be a "trigger" so that other code of yours can directly access the file that was created on the server.


              I have to admit, running AIR on the server seems more than a bit round-about to me, but the method I've outlined is independent of the process on the server that creates the desired file.


              To summarize (actions in the browser):


                   make the HTTP request

                   initiate the process on server to create the desired file

                        (on the server:  when the desired file is ready, respond to the HTTP  request)

                   catch the result event (be sure to listen for the error event too)

                   access the created file on the server


              We are multi-processing across the client/server boundary.  Very modern!


              • 4. Re: communicating with flex from server - event generated by server
                Cr99 Level 1

                Thanks for the input and suggestions.


                I'm not actually starting with flex which is the problem.  I am starting in a normal HTML page.  So the servlet has to know how to contact the AIR app.  Now I could go directly to the AIR app but then how would I know when it had finished generating the images.  So I set up a channel in BlazeDS.  The AIR app knows how to communicate with my ServiceAdapter, but I can't get the Servlet to talk to the ServiceAdapter.  I did find this page:


                http://sujitreddyg.wordpress.com/2008/08/14/sending-messages-from-java-to-blazeds-destinat ions-using-messagebroker/


                Which says that you should be able to send a message to a Flex app this way from Java:



                public void sendMessageToClients(String messageBody) {
                     AsyncMessage msg = new AsyncMessage();
                     msg.setTimestamp(new Date().getTime());
                     //you can create a unique id
                     //destination to which the message is to be sent
                     //set message body
                     msg.setBody(messageBody != null?messageBody:"");
                     //set message header
                     msg.setHeader("sender", "From the server");
                     //send message to destination
                     MessageBroker.getMessageBroker(null).routeMessageToService(msg, null);               



                Which seems promising, but for me it doesn't work.  I need to go to the Adapter so that I will have something which can get a reply back saying "I'm done".  I've included a diagram below to explain how the communication needs to flow.


                Picture 5.png