Thursday, November 4, 2010

Dynamic , Static creation of AMFChannel for accessing Java methods using Remote Objects

In one of the projects I am working on , we are using Flex ,Spring BlazeDs integration . Initially we configured the RemoteObject using dynamically created AMFChannel. Later on due to some changing requirements , we changed to read the ChannelSet definition and endpoint URL mapping from services-config.xml.  Thought many of the Flex developers may be looking for something like this and hence sharing what needs to be done.

RemoteObject with dynamic AMFChannel and ChannelSet.
1)      My services-config.xml has following channel definition. (As I am using Flex –Spring- BlazeDs inetgeration hence the spring/messagebroker/amf )
              <channels>
                       <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
                                    <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf"
                                                class="flex.messaging.endpoints.AMFEndpoint"/>
                                                <properties>
                                <record-message-times>true</record-message-times>
                                <record-message-sizes>false</record-message-sizes>
                                </properties>
                                </channel-definition>
                  </channels>
2)      Create dynamic AMFChannel and ChannelSet

var amfChannel = new AMFChannel("myamf", “/DemoApp/spring/messagebroker/amf”);
                where DemoApp is the context-root of my application. One can also store the above URI into a properties file and use ResourceManager to get the string at runtime, rather using the hardcoding.
var channelSet = new ChannelSet();
channelSet.addChannel(amfChannel);

3)      Create RemoteObject
Have created a public function which returns a RemoteObject instance .
The destination is the id of the destination mentioned in services-config.xml or incase of spring-blazeDs integration it’s the bean id defined in applicationContext.xml.

public function getService(destination:String):RemoteObject
                                {
                                                var remoteService:RemoteObject = new RemoteObject();
//reference to channelset we created dynamically in step 2.
                                                remoteService.channelSet = this.channelSet ;
                                                remoteService.destination = destination ;
                                                remoteService.showBusyCursor = true ;
                                                return remoteService ;
                                }
               
RemoteObject with AMFChannel and ChannelSet.defined in services-config.xml

1)      Services-config.xml , we difine a channel-definition like below.


<channel-definition id="demoApp-amf"

class="mx.messaging.channels.AMFChannel">

<endpoint url="http://{server.name}:{server.port}/DemoApp/spring/messagebroker/amf"

class="flex.messaging.endpoints.AMFEndpoint"/>

<properties>

<record-message-times>false</record-message-times>

<record-message-sizes>false</record-message-sizes>

</properties>

</channel-definition>

2)      Create AMFChannel and Channel set from entry provided in Services-config.xml
var channeled:String  =  demoApp-amf”;
var amfChannel:AMFChannel  = null ;
try{
if(ServerConfig.getChannel(channelId)!=null){
amfChannel = new AMFChannel(channelId,ServerConfig.getChannel(channelId).endpoint);                                                     
}
                                                }catch(error : InvalidChannelError){}

var channelSet = new ChannelSet();
channelSet.addChannel(amfChannel);

3)      Create RemoteObject
Have created a public function which returns a RemoteObject instance .
The destination is the id of the destination mentioned in services-config.xml or incase of spring-blazeDs integration it’s the bean id defined in applicationContext.xml.

public function getService(destination:String):RemoteObject
                                {
                                                var remoteService:RemoteObject = new RemoteObject();
//reference to channelset we created dynamically in step 2.
                                                remoteService.channelSet = this.channelSet ;
                                                remoteService.destination = destination ;
                                                remoteService.showBusyCursor = true ;
                                                return remoteService ;
                                }


Sunday, October 31, 2010

Let the blog begin....

It's been fantastic 2.5 years having an association with Flex technology. The experience started way back in mid 2008 when we had prepared an app using DOJO , JSP's etc , and to our dismay the cross browser compatibility issues were just never ending. One fix used to worsen it in another browser.The client was furious when the browser hung during an important demo due to some document node error . Instantly the client was advised to use Flex by some of his fren. And then we had to learn Flex in a fortnight.

The news we had was Flex is something that runs on flash.. so our initial mindset was , wud i have to learn flash.. which we weren't ready for at all. Somehow we started coding small POC's just to check how easy it was working with Flex. We then a training arranged from a Adobe trainer for 5 entire days and boom .. we were into Flex full time. We ate , sat , slept flex in office .. day and night and got the entire app built again into Flex. Those 2 months with the amazing team of Flex , Java and DB guys were best of times.

With time Flex developed quite good expertise in Flex . Soon started training a batch of 20 developers whose questions amazed me and made me learn more of Flex. Used to read lot of blogs specially of Sujit Reddy , Anandvardhan.There were quite many interactions with other Flex apprentice on various forums. I always felt should also start bloggin .. but the idea never took off.  Disappointed couldn't make it to a Flex session of Sujit Reddy in Pune Cogni office. Was tied up with project pressures.. else wud never let such a chance go by to meet him in person.. Keeping fingers crossed .. hoping to meet some Flex names soon..

All in all i wud keep bloggin about my Flex experiences , day to day problems and solutions i face while developing with Adobe Flex Gumbo and Moxie.. Keep reading ..