Posts mit dem Label flex werden angezeigt. Alle Posts anzeigen
Posts mit dem Label flex werden angezeigt. Alle Posts anzeigen

Sonntag, 7. September 2008

Flex/Flash wasn't made for REST

Well, it did take longer than others, but I finally got the message: Flash was not built with HTTP in mind. There are other issues flying around, but I think it all boils down to HTTP not being treated as first-class-citizen in the Flex/Flash environment.

I guess that the reason is a historical one: all remote connection protocols where proprietary, only in the last years Adobe opened itself a little bit (by releasing BlazeDS and open sourcing Flex). Now I think Adobe should go 2 steps further:
  1. implement standards (e.g. using HTTP how it was meant to be used)
  2. open source the whole stack
This is highly speculative, but perhaps the "Nay" to EcmaScript4 was due to the apparent closeness of the Flash ecosystem.

The saddest thing is that Flex is great! Real good default (looks nice out of the box), a real component model, just plain fun! Next stop: Dojo, I think ...

Donnerstag, 10. Juli 2008

Grails, Flex, Soap

Today I have written a small PoC for Grails, Flex, SOAP. The initial task was (and still is) to find out which communication takes place in a Flex application.

Having no clue about Flex, a little understandig of Web Services and some minor understanding of Grails, it took me no more than 3 hours, including googling for web service usage in Flex and hunting of really stupid beginners bug.

This shows the real muscles of Grails and its really awesome plugin ecosystem.


grails create-app HelloFlex
cd HelloFlex
grails install-plugin flex
grails install-plugin xfire
grails create-service hello

Ok, everything needed is installed. 2 more things to do. in HelloFlex\services\HelloService.groovy:

class HelloService {
static expose=['xfire', 'flex-remoting']
def hello(String echo) { return echo.reverse() }
}


Note the use of expose: this service is both available via flex-remoting and via SOAP.

Second: create HelloFlex\web-app\test.mxml


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:WebService
id="userRequest"
wsdl="http://localhost:8080/HelloFlex/services/hello?wsdl">
<mx:operation name="hello" resultFormat="object"
fault="mx.controls.Alert.show(event.fault.faultString)"
result="showResult(event)"/>
</mx:WebService>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
[Bindable] private var passage:String;
private var options:Object = {"output-format": "plain-text"};
private function showResult(e:ResultEvent):void {
passage = userRequest.hello.lastResult;
}
private function send_data(input:String):void {
userRequest.hello(input);
}
]]>
</mx:Script>

<mx:Text text="Echo Service" fontSize="16" fontWeight="bold"/>
<mx:Text text="Input" fontSize="12"/>
<mx:TextInput id="lookupPsg" textAlign="center"/>
<mx:Button label="Submit" click="send_data(lookupPsg.text)"/>
<mx:TextArea height="352" width="590" id="psg" text="{passage}" editable="false" fontSize="11"/>
</mx:Application>

(sorry for the mess, dunno how to format this better )

Hitting http://localhost:8080/HelloFlex/test.mxml displays the Flex application which uses SOAP protocol to consume the webservice.

Built on the shoulder of giants...

Update 12th Jul: Marcel Overdijk has already written a similar (well, actually better:)) example back in january.