


Blaze DS and Spring :: Part 3
Let's continue with our application setup. Now this part of the Java application is done, we can continue with the rest of the application. First let's continue with adding our settings to Blaze DS so we can make our communication work, after that we'll start with the Flex part and get the entire application working. Our Spring and Hibernate part is done already so as soon as we have the rest connected this should be working.
Next step is our configuration files in Blaze DS, so let's open up our configurations file and get things working.
We already added our SpringFactory to the first configurationfile in step one so that's already done, now we start with the first call we are going to do and that's the call with the username from the Flex GUI to our Spring service. To set this up we open the remoting-config.xml in our WEB-INF/flex folder and add a destination there. In this case I called the destination "taskManager" and registered my Java class as the taskManager service in Spring. So now that we have our information we can set up the connection in our configuration file
<properties>
<source>taskManager</source>
<factory>spring</factory>
</properties>
</destination>
Next we need the part where we can send messages to our Flex GUI, for that we are using messaging, so now we need to add a destination in our messaging-config.xml file. First thing we need to do again is define what the name of the destination is that we are going to use, this is the same name we routed our message to in our taskManager service class, so there we did call it taskusers, so let's use the same name here, since that is the connection between Java and Blaze.
<properties>
<network>
<session-timeout>0</session-timeout>
</network>
<server>
<max-cache-size>1000</max-cache-size>
<message-time-to-live>0</message-time-to-live>
<durable>false</durable>
</server>
</properties>
<channels>
<channel ref="my-polling-amf" />
</channels>
<adapter ref="actionscript" />
</destination>
Since RTMP is not present in Blaze DS we are going to use polling to get the information to the client, if you would use LiveCycle DS you could also use the RTMP channel to make sure the message is faster at the client and make sure there is less traffic needed for communication. so now our destinations are set up.
One thing I did show in my demo is how you could also send messages from one Flex client to another with no use of Java at all, that was to send tasks from one user to the other, so for that I'll also add a destination.
<properties>
<network>
<session-timeout>0</session-timeout>
</network>
<server>
<max-cache-size>1000</max-cache-size>
<message-time-to-live>0</message-time-to-live>
<durable>false</durable>
</server>
</properties>
<channels>
<channel ref="my-polling-amf" />
</channels>
</destination>
{
import flash.events.Event;
/**
* Close popup event with username
*/
public class ClosePopupEvent extends Event
{
public static const CLOSE_POPUP:String = "userNameChosen";
public var userName:String;
public function ClosePopupEvent(type:String, userName:String)
{
super(type, true);
this.userName = userName;
}
}
}
Now that we have this event we can use it and the login screen can be completed. We'll call this later from the main screen of this application.
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" cornerRadius="20" >
<mx:Script>
<![CDATA[
import events.ClosePopupEvent;
import mx.managers.PopUpManager;
/**
* As soon as the user clicks the button he will be logged in.
*/
private function login():void
{
var evt:ClosePopupEvent = new ClosePopupEvent(ClosePopupEvent.CLOSE_POPUP, userName.text);
this.dispatchEvent(evt);
userLogon.loginUser(userName.text);
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name="userNameChosen", type="events.ClosePopupEvent")]
</mx:Metadata>
<mx:RemoteObject id="userLogon" destination="taskManager"/>
<mx:Form horizontalCenter="0" verticalCenter="0">
<mx:FormItem label="Gebruikersnaam">
<mx:TextInput id="userName"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Log in" click="login()"/>
</mx:FormItem>
</mx:Form>
</mx:TitleWindow>
This window is going to send a message to the server using the RemoteObject we have defined here that points to the taskManager destination, this is directly going to call our Spring Service on the server. So with this the method is going to be called and the server can start processing user information.
Tomorrow there is going to be more on this, i'll add the receiving page for tasks and the page that is going to receive the user information and is going to send out tasks.





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