


Connecting AIR with BlazeDS and Spring
Last week I've shown you how to connect a Flex application to a java Spring application using BlazeDS. As you might have read everywhere changing your Flex web application to an Air client side application is very easy. So let's take our Flex application that is connecting to our Spring application using BlazeDS and change it to an AIR application working exactly the same. I'm using the sources here that were created in the posts BlazeDS and Spring First what we need to do is create a new AIR project in Flex, so let's start with creating a new Flex project and on the first page of the wizard there change the setting to Desktop Application.
Now let's take the easy way and just copy all our sources to this new application. First thing we need to do there is change our Application tag. As soon as we change that to WindowedApplication we can run our application again and it should not directly give you any errors. The only thing that is not working now is all our communication with BlazeDS, reason for this is that our application is not retrieved from our server now and does not know how to connect to our server again. So for this to work we have to make a few changes to tell our RemoteObject call and our Consumer call where to connect to. So first step is change our TitleWindow Component that let's a user send in a username. There we add a creationComplete handler to start as soon as the application is completely started and we add a channelSet there to add to our RemoteObject call.
* initApp to start when the application starts that add our communication to the server.
*/
private function initApp():void {
var cs:ChannelSet = new ChannelSet();
var myChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");
cs.addChannel(myChannel);
userLogon.channelSet = cs;
}
This code creates a new Channelset with one AMFChannel connecting to our Blaze installation and in there to the AMF messagebroker. At the end of this part we add the ChannelSet to our userLogon RemoteObject and now this part of the application should work again.
Next is to make sure our Producer and Consumer work again. To get these working we do the same thing just connecting to another URI and since our consumer is going to poll the server for changes we are also defining here how intensively that has to happen.
* As soon as a user is selected we subscribe to the server to receive tasks.
*/
private function userSelectedHandler(event:ClosePopupEvent):void{
var cs:ChannelSet = new ChannelSet();
var myChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amfpolling");
myChannel.pollingEnabled = true;
myChannel.pollingInterval = 1000;
cs.addChannel(myChannel);
taskConsumer.channelSet = cs;
userName = event.userName;
taskConsumer.subscribe();
taskConsumer.addEventListener(MessageEvent.MESSAGE, incomingMessageHandler);
}
So again we created a new AMFChannel and are setting it to connect to amfpolling for connection and now we set it to poll for new messages every second. If we only make these changes and now compile our application as an Air application it should work again.





There are no comments for this entry.
[Add Comment]