<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gridshore &#187; flex</title>
	<atom:link href="http://www.gridshore.nl/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Attaching flex to Axon using the new Axon CommandBus</title>
		<link>http://www.gridshore.nl/2010/04/11/attaching-flex-to-axon-using-the-new-axon-commandbus/</link>
		<comments>http://www.gridshore.nl/2010/04/11/attaching-flex-to-axon-using-the-new-axon-commandbus/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 15:41:50 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[Spring BlazeDS]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1027</guid>
		<description><![CDATA[<p>I have blogged before about the flex client I have created for the Axon framework addressbook sample project. If you did not read it before and want to learn more about the parsley framework, check this blog.</p> <p>http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/</p> <p>In this blog item I am describing changes based on a new feature made available in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/axon_logo.png" alt="axon_logo.png" border="0" width="55" height="55" align="left" />I have blogged before about the flex client I have created for the Axon framework addressbook sample project. If you did not read it before and want to learn more about the parsley framework, check this blog.</p>
<p><a href="http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/">http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/</a></p>
<p>In this blog item I am describing changes based on a new feature made available in Axon. Allard has created support for a CommandBus and command handlers. Basic idea is that you dispatch items on the bus, and a registeredhandler picks it up and handles it. This makes the command query separation also more clear on the flex side of the application.</p>
<p><span id="more-1027"></span>
<p>What are the big changes in relation to the previous version of the sample? The biggest change is that we have one endpoint to receive all command objects. The impact of this change is separated into two parts, the flex part and the server side part.</p>
<h2>Changes on the server side</h2>
<h3>Spring</h3>
<p>Spring is used to configure the command bus and a special bean to find all command handlers based on annotations. The following code block shows the beans needed to configure the bus as well as the annoattion support</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;bean class=&quot;org.axonframework.commandhandling.annotation.AnnotationCommandHandlerBeanPostProcessor&quot;&gt;
        &lt;property name=&quot;commandBus&quot; ref=&quot;commandBus&quot;/&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;commandBus&quot; class=&quot;org.axonframework.commandhandling.SimpleCommandBus&quot;/&gt;

    &lt;bean id=&quot;contactCommandHandler&quot; class=&quot;org.axonframework.sample.app.command.ContactCommandHandler&quot;&gt;
        &lt;property name=&quot;repository&quot; ref=&quot;contactRepository&quot;/&gt;
    &lt;/bean&gt;
</pre>
<p>Now we have a command bus that is wired into the CommandReceiver. We also configured the ContactCommandHandler that contains annotated methods that are registered as command handlers. The bean with class AnnotationCommandHandlerBeanPostProcessor finds all these annotated methods, creates a wrapper around these methods and registered them as handlers in the command bus.</p>
<h3>Command objects</h3>
<p>To make good use of the command part of CQRS, communication of changes is done using command objects. The application now has the following command objects.</p>
<ul>
<li>ChangeContactNameCommand</li>
<li>ContactCommandHandler</li>
<li>CreateContactCommand</li>
<li>RegisterAddressCommand</li>
<li>RemoveAddressCommand</li>
<li>RemoveContactCommand</li>
</ul>
<p>As described in the Axon reference manual each command needs it&#8217;s own handler. The next section discusses the handlers.</p>
<h3>Command handlers</h3>
<p>Axon provides a mechanism with annotation so you can group multiple handlers in one class. I use the ContactCommandHandler class to hold all handlers. The following code block gives an example of one of these handlers</p>
<pre class="brush: java; title: ; notranslate">
    @CommandHandler
    public UUID handle(CreateContactCommand command) {
        logger.debug(&quot;Received a command for a new contact with name : {}&quot;, command.getNewContactName());
        Assert.notNull(command.getNewContactName(), &quot;Name may not be null&quot;);
        Contact contact = new Contact(command.getNewContactName());
        repository.save(contact);
        return contact.getIdentifier();
    }
</pre>
<p>That is it, the CommandHandler annotation and the argument of the method. In this example we have the handler for CreateContactCommand objects. The implementation is straightforward. Notice the return of the identifier of the contact.</p>
<h2>The flex client</h2>
<p>BlazeDS is used to transform data from actionscript objects into java objects. Therefore we need an counter object for all command objects that we created. Just add the bindable and remoteclass tags to the actionscript class. For completeness the following code block shows the action script command class.</p>
<pre class="brush: jscript; title: ; notranslate">
[Bindable]
[RemoteClass(alias=&quot;org.axonframework.sample.app.command.CreateContactCommand&quot;)]
public class CreateContactCommand {
    public var newContactName:String;
    public function CreateContactCommand() {
    }
}
</pre>
<p>Now we need to tell parsley about the new remote service that accepts the new command objects. This is configured in the ParsleyConfiguration.mxml file.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;mx:RemoteObject
            id=&quot;remoteCommandReceiver&quot;
            destination=&quot;commandReceiver&quot;
            endpoint=&quot;messagebroker/amf&quot;
            showBusyCursor=&quot;true&quot;/&gt;
</pre>
<p>In the NewContactController we actually use this remote service to send the </p>
<pre class="brush: jscript; title: ; notranslate">
    public function execute(message:NewContactCommandMessage):AsyncToken {
        if (message.contact.name.length &lt; 1) {
            dispatcher(new ValidationMessage(&quot;Name field is required for contact&quot;));
            return null;
        }
        this.contact = message.contact;
        var addContactCommand:CreateContactCommand = new CreateContactCommand();
        addContactCommand.newContactName = message.contact.name;
        return commandReceiver.sendCommand(addContactCommand);
    }
</pre>
<p>What I like about this solution is that we have a remote service for accepting all command objects and other remote services for doing the querying. He CQRS at the flex side. Using this technique makes it a lot easier to create a task based application with each task being represented by a command. Because the server understands these tasks the flex part is very connected with the server part.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F04%2F11%2Fattaching-flex-to-axon-using-the-new-axon-commandbus%2F&amp;title=Attaching%20flex%20to%20Axon%20using%20the%20new%20Axon%20CommandBus&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/04/11/attaching-flex-to-axon-using-the-new-axon-commandbus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a sample for axon using flex and parsley</title>
		<link>http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/</link>
		<comments>http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 10:46:37 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[axon]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[parsley]]></category>
		<category><![CDATA[spring 3]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1013</guid>
		<description><![CDATA[<p>The last weeks or maybe even months, I have spent time getting to understand the Axon Framework created by Allard. Axon is a framework that can help developers created a scalable and maintainable application based on Command Query Responsibility Segregation (CQRS) principles. Each morning Allard and I discussed the framework and the sample we [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/axon_logo.png" alt="axon_logo.png" border="0" width="55" height="55" align="left" />The last weeks or maybe even months, I have spent time getting to understand the Axon Framework created by Allard. Axon is a framework that can help developers created a scalable and maintainable application based on Command Query Responsibility Segregation (CQRS) principles. Each morning Allard and I discussed the framework and the sample we wanted to have. Since I know my way around flex and Axon makes heavily use of events, I decided to create a flex client that could demonstrate some cool features of the Axon framework.</p>
<p><img src="http://www.gridshore.nl/wp-content/uploads/parsley-spicelib-vert.jpg" alt="parsley-spicelib-vert.jpg" border="0" width="156" height="40" align="left" />This post is mainly about flex and <a href="http://www.spicefactory.org/parsley/">Parsley</a>. We will go into depth of the architecture of the client and how to talk to the server. I will describe the communication with the application that makes use of the axon framework, but I will not go into a lot of details. If you want more information about the Axon Framework I suggest you go to the website <a href="http://www.axonframework.org">http://www.axonframework.org</a>. There is good documentation available in the reference manual. If you want to learn about flex and the Parsley framework in general, please read on.</p>
<p><span id="more-1013"></span><br />
<h2>What is Parsley and why use it?</h2>
<p>Parsley is all about decoupling. It is a dependency injection framework and is has strong support for messaging. I like the way the dependency injection as well as message handling is configured. By using [INJECT] on a parameter, you tell parsley to inject an object of the type as specified by the parameter. We will see examples of the usage later on. Other things to inject are the [MessageDispatcher] that enables dispatching messages from each component.</p>
<p>The final component I want to mention is the <strong>DynamicCommand object</strong>. I use it more as a controller, still it is an interesting concept. We create one component that receives a message, does a remote call and handles the result of that call. All in one object. Again, an example will follow later on.</p>
<h2>Structure of the Parsley solution</h2>
<p>The following image gives you an idea of the overall solution of parsley. The image shows you the relationship between the view components, the controllers and the model. Messages are send from the view to the controller. The controller interacts with the remote components, updates the model and determines which view should be active. The controllers can also respond to remote push notifications, more on that later on.</p>
<div style="text-align:center;"><img src="http://www.gridshore.nl/wp-content/uploads/parsley-overview.png" alt="parsley-overview.png" border="0" width="463" height="454" /></div>
<h3>Configure parsley</h3>
<p>To enable injection and message handling, parsley needs it&#8217;s own context to be setup. The easiest way to do this is using an mxml object and an mxml ContextBuilder object. The next code block shows you the complete configuration of the framework. Within the configuration you can see the controllers being configured as DynamicCommand objects. You also find there the RemoteObject, the Consumer and the model objects. They should all be familiar from the previous image.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:Object xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
           xmlns:sf=&quot;http://www.spicefactory.org/parsley&quot;
           xmlns:commands=&quot;org.axonframework.examples.addressbook.commands.*&quot;
           xmlns:model=&quot;org.axonframework.examples.addressbook.model.*&quot;
           xmlns:cons=&quot;org.axonframework.examples.addressbook.consumer.*&quot;
        &gt;
    &lt;mx:RemoteObject
            id=&quot;remoteAddressService&quot;
            destination=&quot;addressService&quot;
            endpoint=&quot;messagebroker/amf&quot;
            showBusyCursor=&quot;true&quot;/&gt;
    &lt;cons:Consumer/&gt;

    &lt;sf:DynamicCommand type=&quot;{NewAddressController}&quot; messageType=&quot;{NewAddressMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{NewContactController}&quot; messageType=&quot;{NewContactMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{SearchAddressController}&quot; messageType=&quot;{SearchForAddressesMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{SelectContactController}&quot; messageType=&quot;{SelectContactMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{ShowContactsController}&quot; messageType=&quot;{ShowContactsMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{UpdatedContactController}&quot; messageType=&quot;{UpdatedContactMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{UpdatedContactAddressController}&quot; messageType=&quot;{UpdatedContactAddressMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{RemoveAddressController}&quot; messageType=&quot;{RemoveAddressMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{RemovedItemController}&quot; messageType=&quot;{RemovedItemMessage}&quot;/&gt;
    &lt;sf:DynamicCommand type=&quot;{RemoveContactController}&quot; messageType=&quot;{RemoveContactMessage}&quot;/&gt;

    &lt;model:AddressModel/&gt;
    &lt;model:ContactModel/&gt;

    &lt;mx:Script&gt;&lt;![CDATA[
        import org.axonframework.examples.addressbook.commands.*;
        import org.axonframework.examples.addressbook.messages.*;
        ]]&gt;&lt;/mx:Script&gt;
&lt;/mx:Object&gt;
</pre>
<p>That is all that parsley needs to know. The final step is to build the context using the special mxml tag. I have included the next tag in my Main.mxml.</p>
<pre>
	&lt;sf:ContextBuilder config="ParsleyConfiguration"/&gt;
</pre>
<p>Next we will focus on the different components</p>
<h3>Messages</h3>
<p>We make use of two types of messages:</p>
<ul>
<li>CommandMessage &#8211; tells the receiver to do something.</li>
<li>NotificationMessage &#8211; tells the receiver that something happened</li>
</ul>
<h3>View</h3>
<p>Each view component should focus on presenting data and sending messages. The data is injected as a model object. Messages can be dispatched by the special parsley provided dispatcher. Than parsley also provides a Context object that can be used when pop-ups are needed. The following code block shows you the configuration of these mentioned parameters from the <strong>ContactsView.mxml</strong> component. You can also find a function that is called by pushing a button to send a message to obtain details about a certain contact.</p>
<pre class="brush: jscript; title: ; notranslate">
[Inject]
[Bindable]
public var contactModel:ContactModel;
[MessageDispatcher]
public var dispatcher:Function;
[Inject]
public var context:Context;

private function showContactDetails(event:ListEvent):void {
    dispatcher(new SelectContactCommandMessage(event.currentTarget.selectedItem as Contact));
    currentState = 'detail';
}
</pre>
<p>This is all pretty straightforward, if you need the code check out the sources from the google code project. Let us follow what happens when obtain details button is pushed and the SelectContactMessage is dispatched. </p>
<h3>Controller</h3>
<p>By dispatching this message, parsley selects the <strong>SelectContactController</strong> since the argument of the execute method is that exact message. The following code block gives you the complete implementation of the SelectContactController. The super class of all controllers contains a method to handle the faults coming from the remote calls and it makes the dispatcher as well as the remote object available. This class is also in the code block. In the code check how the dispatcher, the RemoteObject and the contactModel are injected. Another thing to notice here is that we only go to the server if we have not cached the contact details locally. So what if the contact details get updated on the server? Or if new contacts are added on the server? More on that in the next section.</p>
<pre class="brush: jscript; title: ; notranslate">
public class BaseController {
    [MessageDispatcher]
    public var dispatcher:Function;

    [Inject(id=&quot;remoteAddressService&quot;)]
    public var addressService:RemoteObject;

    public function BaseController() {
        // default constructor
    }

    public function error(fault:Fault):void {
        dispatcher(new ErrorNotificationMessage(fault.faultString));
    }

}

public class SelectContactController extends BaseController {
    [Inject]
    public var contactModel:ContactModel;

    private var findAddressesFor:Contact;

    public function SelectContactController() {
        super();
    }

    public function execute(message:SelectContactCommandMessage):AsyncToken {
        var cachedContact:Contact = contactModel.findContactByIdentifier(message.contact.uuid);
        contactModel.selectedContact = cachedContact;
        findAddressesFor = cachedContact;

        if (!cachedContact.detailsLoaded) {
            return addressService.obtainContactAddresses(message.contact.uuid);
        }
        return null;
    }

    public function result(addresses:ArrayCollection):void {
        var cachedContact:Contact = contactModel.findContactByIdentifier(findAddressesFor.uuid);
        cachedContact.addresses = addresses;
        cachedContact.detailsLoaded = true;
    }
}
</pre>
<p>You have now seen the most important parts of the mechanism to go from a view to a controller. Did you notice that we send an <strong>ErrorNotificationMessage</strong> when something goes wrong in the server communication? The notification messages are handled in the <strong>OverallView</strong> component. Other notification messages are also handled in this component. The following code block gives a piece of code that handles the message.</p>
<pre class="brush: jscript; title: ; notranslate">
[MessageHandler]
public function handleActivityLogEvent(message:NotificationMessage):void {
    createNotification(message.message, Notification.INFO);
}
</pre>
<h2>Communication with the server</h2>
<p>The server is used to send data to and of course to obtain data from. The easiest way is when the flex client takes control. As we saw in the parsley configuration, the remote object is configured as you would in any flex client. In the code from the SelectContactController we can see the call to the server. The result function is called when the server returns a result. This is not very complicated to understand.</p>
<p>Let us have a look at how this is handled on the server. Using spring blazeds integration this becomes very easy as well</p>
<h3>BlazeDS and Spring BlazeDS Integration</h3>
<p>Doing flex remoting with the Spring BlazeDS integration is so easy that anybody can use it. In the web.xml you configure the dispatcher servlet. The config file is loaded using the following tag in a spring configuration file.</p>
<pre>
&lt;flex:message-broker services-config-path="classpath*:services-config.xml"/&gt;
</pre>
<p>Now I use annotations to explicitly export some of the functions as remote services. The following code block gives you the example of obtaining address details for a contact. Notice that the name of the method is the same as the method call used in the flex code. By adding the annotation @RemotingInclude we tell spring to expose this as a remote service using BlazeDS.</p>
<pre class="brush: java; title: ; notranslate">
    @RemotingInclude
    public List&lt;AddressDTO&gt; obtainContactAddresses(String contactIdentifier) {
        List&lt;AddressDTO&gt; foundAddresses = new ArrayList&lt;AddressDTO&gt;();

        List&lt;AddressEntry&gt; addressesForContact =
                repository.findAllAddressesForContact(UUID.fromString(contactIdentifier));
        for (AddressEntry entry : addressesForContact) {
            foundAddresses.add(AddressDTO.createFrom(entry));
        }
        return foundAddresses;
    }
</pre>
<p>The repository is based on the query database of Axon. I am not going into all the Axon Framework details here. Check the references if you want to learn more about Axon.</p>
<p>That is all there is to it, now you can obtain data from the server. Sending data to the server is done exactly the same.</p>
<h2>Receiving events</h2>
<p>I already mentioned that we cache data in the flex client. Still we want to have up-to-date data. Using the Axon framework and Spring BlazeDS integration it is not hard to push data to the client from the server when new or updated data is available. Again this blog does not have the intention to fully discuss the axon framework.</p>
<h3>Catching and dispatching events on the server</h3>
<p>We focus on the event that a new contact is created. The following code shows how you can register a listener for new contacts being created using the Axon framework. The listener makes use of the <strong>UpdateMessageProducerForFlex</strong>. Axon registers listeners based on the annotation @EventHandler and the argument of the method, in this case the <strong>ContactCreatedEvent</strong>.</p>
<pre class="brush: java; title: ; notranslate">
private UpdateMessageProducerForFlex producer;
@EventHandler
public void handleContactCreatedEvent(ContactCreatedEvent event) {
    logger.debug(&quot;Received and event with name {} and identifier {}&quot;, event.getName(), event.getEventIdentifier());
    ContactDTO contactDTO = new ContactDTO();
    contactDTO.setName(event.getName());
    contactDTO.setUuid(event.getAggregateIdentifier().toString());
    producer.sendContactUpdate(contactDTO);
}
</pre>
<p>This is the Axon part, the producer is used to send the message to the clients. Sending the message to the flex client is done using the spring BlazeDS integration. The following piece of code shows the producer. After that the configuration of the server.</p>
<pre class="brush: java; title: ; notranslate">
public class UpdateMessageProducerForFlex {
    private MessageTemplate template;

    @Autowired
    public UpdateMessageProducerForFlex(MessageTemplate template) {
        this.template = template;
    }

    public void sendContactUpdate(final ContactDTO contactDTO) {
        template.send(contactDTO);
    }
}
</pre>
<pre class="brush: xml; title: ; notranslate">
    &lt;flex:message-destination id=&quot;event-bus&quot;/&gt;

    &lt;bean id=&quot;defaultMessageTemplate&quot; class=&quot;org.springframework.flex.messaging.MessageTemplate&quot;&gt;
        &lt;property name=&quot;defaultDestination&quot; value=&quot;event-bus&quot;/&gt;
    &lt;/bean&gt;
</pre>
<p>The value for the default destination &#8220;<strong>event-bus</strong>&#8221; is very important. This needs to be configured in the client as well. Speaking of the client &#8230;</p>
<h3>Catching and dispatching events at the client</h3>
<p>Within the parsley configuration we have configured an object called Consumer. This object configures the client side of the poller and registers it on startup. This registration needs to be done at the right time. Parsleys provides the [Init] notation for that.</p>
<p>The consumer receives messages from the server and dispatches new Notification messages to the client side application. Controller objects pick up these events and update the model. The following code block shows the complete consumer object. Notice the configuration of the ChannelSet and the consumer.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:Object xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;&lt;![CDATA[
        [Init]
        public function init():void {
            consumer.subscribe();
        }

        [MessageDispatcher]
        public var dispatcher:Function;

        public function messageHandler(event:MessageEvent):void {
            if (event.message.body is Contact) {
                dispatcher(new UpdatedContactNotificationMessage(event.message.body as Contact));
            } else if (event.message.body is Address) {
                dispatcher(new UpdatedContactAddressNotificationMessage(event.message.body as Address))
            } else if (event.message.body is Removed) {
                dispatcher(new RemovedItemNotificationMessage(event.message.body as Removed));
            }

        }

        public function faultHandler(event:Event):void {
            dispatcher(new ErrorNotificationMessage(&quot;Fault while receiving message&quot; + event.toString()))
        }

        ]]&gt;&lt;/mx:Script&gt;
    &lt;mx:Consumer id=&quot;consumer&quot; destination=&quot;event-bus&quot; channelSet=&quot;{cs}&quot; message=&quot;messageHandler(event)&quot;
                 fault=&quot; faultHandler(event)&quot;/&gt;

    &lt;mx:ChannelSet id=&quot;cs&quot;&gt;
        &lt;mx:AMFChannel url=&quot;messagebroker/pollingamf&quot;/&gt;
    &lt;/mx:ChannelSet&gt;

&lt;/mx:Object&gt;
</pre>
<h2>Wrapping up</h2>
<p>That is it. We have touched all components. I like how clean you can develop flex clients using Parsley and how easy it is to interact with a server using the Spring BlazeDS integration. Also the way to handle events using Axon makes this a very nice way to keep the data in your flex client up to date.</p>
<p>Hope you likes the sample, sources can be found in google code. Check the addressbook sample project of the axon framework.</p>
<p>The following image shows a screendump of the sample, after that are some references.</p>
<div style="text-align:center;"><img src="http://www.gridshore.nl/wp-content/uploads/Screen-shot-2010-02-18-at-13.49.13.png" alt="Screen shot 2010-02-18 at 13.49.13.png" border="0" width="1120" height="576" /></div>
<ul>
<li><a href="http://code.google.com/p/axonframework/source/browse">http://code.google.com/p/axonframework/source/browse</a></li>
<li><a href="http://www.spicefactory.org/parsley/">http://www.spicefactory.org/parsley/</a></li>
<li><a href="http://www.springsource.org/spring-flex">http://www.springsource.org/spring-flex</a></li>
<li><a href="http://www.axonframework.org">http://www.axonframework.org</a></li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F02%2F25%2Fcreating-a-sample-for-axon-using-flex-and-parsley%2F&amp;title=Creating%20a%20sample%20for%20axon%20using%20flex%20and%20parsley&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/02/25/creating-a-sample-for-axon-using-flex-and-parsley/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Upgrading my books-overview flex, BlazeDS, Spring security application</title>
		<link>http://www.gridshore.nl/2010/02/17/upgrading-my-books-overview-flex-blazeds-spring-security-application/</link>
		<comments>http://www.gridshore.nl/2010/02/17/upgrading-my-books-overview-flex-blazeds-spring-security-application/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 19:54:02 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex 3]]></category>
		<category><![CDATA[flex-mojos]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[Spring BlazeDS]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1005</guid>
		<description><![CDATA[<p>In March 2008 I started experimenting with flex and java integration. I wrote a lot of blog posts since than and even published an article on adobe.com. For most of my blog items I used a sample that is available on google code called books-overview. During the years the sample improved a lot. By [...]]]></description>
			<content:encoded><![CDATA[<p>In March 2008 I started experimenting with flex and java integration. I wrote a lot of blog posts since than and even published an article on adobe.com. For most of my blog items I used a sample that is available on google code called <a href="http://code.google.com/p/gridshore">books-overview</a>. During the years the sample improved a lot. By now the sample consists of Mate, BlazeDS, Spring BlazeDS and a lot of other spring technologies like spring security.</p>
<p>I was some time a go I had a look at the sample, since than a lot of people keep coming back to it. I still get questions about it. Therefore I decided to upgrade the sample. This blog post is about the upgrade I did which are mainly upgrades in versions of the libraries and the build configuration. Still I think it is worthwhile to have a look at it.</p>
<p><span id="more-1005"></span>
<p>Before I start with this blog post I need to warn you that I am not going to explain a lot of the internals. Please browse my other <a href="http://www.gridshore.nl/tag/flex3/">flex 3 blog items</a> to find out more.</p>
<h2>Library upgrade</h2>
<h3>The client (flex) side</h3>
<p>For the flex building I use <a href="http://mate.asfusion.com/">Mate</a>. I think mate is a nice framework, but it is not very active. Not many improvements are created. Still it does the job. I am also creating a flex sample for the <a href="http://www.axonframework.org">Axon Framework</a> using <a href="http://www.spicefactory.org/parsley/">Parsley</a>. Stay tuned for a blog post that is around the corner about this sample. I upgrade the mate to release 0.8.9</p>
<p>Another framework I use on the flex side is the <a href="http://www.springactionscript.org/">spring-actionscript</a> project. This project changed a lot since the last time I used it. I am now using version 0.8.1. This project is now split up into a few other modules. I did have a problem with the StringUtils class. This is in as3commons:as3commons-lang. By transitive dependecy you get 0.1 of this library. I had to upgrade to version 0.2 to make it work.</p>
<h3>The serverside</h3>
<p>I did not upgrade a lot on the serverside. I could have upgrade to spring 3, I&#8217;ll wait till it becomes the default for the spring blazeds integration project. They still use version 2.5.6, so I&#8217;ll stick with that. I did upgrade the Spring Blazeds Integration project to the latest release: 1.0.2.RELEASE.</p>
<h2>Building and developing</h2>
<p>The biggest change was in the maven configuration. Flex-mojos made a lot of improvements and is now tightly integrated with Intellij. To me that is incredibly important. My development speed with flex has enormously increased.</p>
<p>I use flex-mojos version 3.5.0. The configuration is now very easy. For the war project you just need to add the following plugin plus configuration:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.sonatype.flexmojos&lt;/groupId&gt;
    &lt;artifactId&gt;flexmojos-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;${flex-mojos.version}&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
                &lt;goal&gt;copy-flex-resources&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>Now let us have a look at the configuration of the swf file. Again it is pretty straightforward. You have to add the flex-framework as a dependency.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;
    &lt;artifactId&gt;flex-framework&lt;/artifactId&gt;
    &lt;version&gt;${flex.sdk.version}&lt;/version&gt;
    &lt;type&gt;pom&lt;/type&gt;
&lt;/dependency&gt;
</pre>
<p>Finally we have to configure the flex-mojos compiler plugin.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.sonatype.flexmojos&lt;/groupId&gt;
    &lt;artifactId&gt;flexmojos-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;${flex-mojos.version}&lt;/version&gt;
    &lt;extensions&gt;true&lt;/extensions&gt;
    &lt;configuration&gt;
        &lt;debug&gt;true&lt;/debug&gt;
        &lt;configurationReport&gt;true&lt;/configurationReport&gt;
    &lt;/configuration&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.adobe.flex&lt;/groupId&gt;
            &lt;artifactId&gt;compiler&lt;/artifactId&gt;
            &lt;version&gt;${flex.sdk.version}&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.adobe.flex.compiler&lt;/groupId&gt;
            &lt;artifactId&gt;asdoc&lt;/artifactId&gt;
            &lt;version&gt;${flex.sdk.version}&lt;/version&gt;
            &lt;classifier&gt;template&lt;/classifier&gt;
            &lt;type&gt;zip&lt;/type&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
<p>The <strong>configurationReport</strong> parameter is used by intellij. This creates an xml file that intellij uses to set you compiler properties in intellij. Very nice.</p>
<h3>Repositories</h3>
<p>I also want to mention the additional repositories I configured. I added a repository for libraries coming from flex-mojos and another library for the spring-actionscript libraries.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;repository&gt;
    &lt;id&gt;flexmojos-repository&lt;/id&gt;
    &lt;url&gt;http://repository.sonatype.org/content/groups/flexgroup/&lt;/url&gt;
&lt;/repository&gt;
&lt;repository&gt;
    &lt;id&gt;yoolab.org-releases&lt;/id&gt;
    &lt;url&gt;http://projects.yoolab.org/maven/content/repositories/releases&lt;/url&gt;
    &lt;releases&gt;
        &lt;enabled&gt;true&lt;/enabled&gt;
    &lt;/releases&gt;
&lt;/repository&gt;
</pre>
<p>The only library I still cannot find online is Mate. Therefore I added it to my google code repository. Please do the same thing if you need it for your own project. Do not use my repository because I will reach my maximum bandwidth and then I have to take it away again.</p>
<p>If you want to check out the state of the project while I was writing this blog, use the following tag:</p>
<p><a href="http://code.google.com/p/gridshore/source/browse/#svn/tags/books-overview-1.0.0">http://code.google.com/p/gridshore/source/browse/#svn/tags/books-overview-1.0.0</a></p>
<p>Hope this is helpfull when exploring my sample, feel free to post remarks, improvements and questions.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F02%2F17%2Fupgrading-my-books-overview-flex-blazeds-spring-security-application%2F&amp;title=Upgrading%20my%20books-overview%20flex%2C%20BlazeDS%2C%20Spring%20security%20application&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/02/17/upgrading-my-books-overview-flex-blazeds-spring-security-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integrate flex security in Mate using the spring BlazeDS integration project</title>
		<link>http://www.gridshore.nl/2009/05/24/integrate-flex-security-in-mate-using-the-spring-blazeds-integration-project/</link>
		<comments>http://www.gridshore.nl/2009/05/24/integrate-flex-security-in-mate-using-the-spring-blazeds-integration-project/#comments</comments>
		<pubDate>Sun, 24 May 2009 09:04:20 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[Mate]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=789</guid>
		<description><![CDATA[<p>More than a year a go I started writing about flex. My first post was about the integration of BlazeDS with the springframework at the back-end using intellij. I moved on with a Datagrid component that had filtering included in my second post. Than I did two posts about integrating spring security. The first [...]]]></description>
			<content:encoded><![CDATA[<p>More than a year a go I started writing about flex. <a href="http://www.gridshore.nl/2008/03/04/integrating-flex3-and-springframework-using-blazeds-and-intellij/">My first post</a> was about the integration of BlazeDS with the springframework at the back-end using intellij. I moved on with a Datagrid component that had filtering included in <a href="http://www.gridshore.nl/2008/03/25/creating-a-flex-3-datagrid-component-with-backend-filtering/">my second post</a>. Than I did two posts about integrating spring security. <a href="http://www.gridshore.nl/2008/05/11/integrating-flex-3-with-spring-security-formerly-known-as-acegi/">The first article</a> was a nice start to understand the concepts. <a href="http://www.gridshore.nl/2008/07/14/integration-spring-security-acegi-and-flex-3-the-sequel/">The second post</a> improved the code a lot with more understanding of the flex principles.</p>
<p>With the next posts I moved on to use maven, which in the beginning was not easy, but thanks to the <a href="http://code.google.com/p/flex-mojos/">excellent flex-mojos plugin</a> from velo. In the beginning of this year I started blogging about the springsource coming into the flex domain for real. Two projects, one for the spring style of programming in the ActionScript language. The other one for integrating BlazeDS and the spring framework. I wrote multiple posts about the new spring project. This post will probably not be the last. But if you are using Mate as well as the spring BlazeDS Integration project. This is a must read post. Maybe only to laugh at what I have done, but I hope to be amazed how simple a full flexed application can be when you combine all these technologies.</p>
<p>Kind of a long introduction, but what is this post really about? I have been using a sample application called books-overview that I have been using for flex based applications. I have been adding stuff to it once in while, but now I have completely refactored it. I am using a framework called <a href="http://mate.asfusion.com/">Mate</a>, have made it modular using the flex-mojos plugin and I have adopted the Spring BlazeDS integration project. Time to explain the way I handle security now, how I am using maven and show the extension to Mate for security.</p>
<p>Read on to find out how I did it and like always leave a comment if you like it or if you have improvements.</p>
<p><span id="more-789"></span><br />
<h2>The books-overview sample</h2>
<p>The books overview sample is a very easy application. You need to login to get access to the application. You can get two different roles. A normal user can look at the books, and admin user can also add books. The domain model is very easy. There are two entities; book and author. A book can have multiple authors and an author can write multiple books. I think the architecture is pretty straightforward. The basic business layer, dao layer, domain component and a web project containing the BlazeDS and flex components. We use spring-security to implement authentication as well as authorization. All data is stored in an in memory database and everything is build using maven. You can find the code in google code, checkout the trunk with the following command:</p>
<p><strong>svn checkout http://gridshore.googlecode.com/svn/trunk/books-overview gridshore-books-overview</strong></p>
<p>To tests if it works, you can use the following commands:</p>
<ul>
<li>step into the directory where you just checked out the sample</li>
<li>mvn clean install (you might have to install some artifacts yourself that are not available in a repository)</li>
<li>cd books-web</li>
<li>mvn clean jetty:run-war</li>
<li>open your browser with the url: <a href="http://localhost:8080/books-web">http://localhost:8080/books-web</a></li>
</ul>
<p>You should see the login screen, enter user admin with password admin and you should see the following screen:</p>
<p><img src="http://www.gridshore.nl/wp-content/uploads/bo-screen-initial.png" alt="bo_screen_initial.png" border="0" width="786" height="519"/></p>
<p>It looks like a pretty easy screen, but a lot has happened before this screen is presented to you. Most important to know for now is that the <strong>New Book</strong> button is only available when logged in as admin. The name can be seen in the logout button on the right. This time with the label <strong>logout admin</strong>. You can now experiment with the application a bit. That way you will better understand what is happening in the code.</p>
<h2>Setting up the maven build</h2>
<p>For my development I use a combination of building with maven and writing code within intellij. Maybe I should invest more time to build with intellij as well, but I keep having problems with it. The workflow of building with maven in a command line is now so easy that I settle with that. Though I do miss the debugging, maybe I&#8217;ll step into it once more. A very cool feature of intellij is that it can group projects into modules. You can make intellij create these modules automatically based on maven structures. <strong>Pom</strong> projects become modules. That way grouping your flex projects to give them common dependencies becomes very easy. That is what I have done for the sample.</p>
<p><img src="http://www.gridshore.nl/wp-content/uploads/bo-dir-struct.png" alt="bo_dir_struct.png" border="0" width="236" height="258"/></p>
<p>Lets have a look at the dependencies and some build specifics. The parent pom contains the following dependencies: flex.sdk.version=3.2.0.3958, spring-actionscript=0.7.1, mate.version=0.8.7.1, flex-mojos.version=3.2.0 </p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;
    &lt;artifactId&gt;flex-framework&lt;/artifactId&gt;
    &lt;version&gt;${flex.sdk.version}&lt;/version&gt;
    &lt;type&gt;pom&lt;/type&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-actionscript&lt;/artifactId&gt;
    &lt;version&gt;${spring-actionscript.version}&lt;/version&gt;
    &lt;type&gt;swc&lt;/type&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.asfusion&lt;/groupId&gt;
    &lt;artifactId&gt;mate&lt;/artifactId&gt;
    &lt;version&gt;${mate.version}&lt;/version&gt;
    &lt;type&gt;swc&lt;/type&gt;
&lt;/dependency&gt;
&lt;!-- testing --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.sonatype.flexmojos&lt;/groupId&gt;
    &lt;artifactId&gt;flexmojos-unittest-support&lt;/artifactId&gt;
    &lt;version&gt;${flex-mojos.version}&lt;/version&gt;
    &lt;type&gt;swc&lt;/type&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</pre>
<p>The build section for both of the flex modules is the same. The only difference is the packaging. For the security model it is <em>swc</em> and for the mate module it is <em>swf</em>. The mate modules is actually not a very good name, it contains the application, maybe I should call it main or so. The build section of the pom looks like this:</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;build&gt;
        &lt;sourceDirectory&gt;src/main/flex&lt;/sourceDirectory&gt;
        &lt;testSourceDirectory&gt;src/test/flex&lt;/testSourceDirectory&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.sonatype.flexmojos&lt;/groupId&gt;
                &lt;artifactId&gt;flexmojos-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;${flex-mojos.version}&lt;/version&gt;
                &lt;extensions&gt;true&lt;/extensions&gt;
                &lt;configuration&gt;
                    &lt;contextRoot&gt;/books-web&lt;/contextRoot&gt;
                    &lt;mergeResourceBundle&gt;true&lt;/mergeResourceBundle&gt;
                    &lt;resourceBundlePath&gt;${basedir}/src/main/locale/{locale}&lt;/resourceBundlePath&gt;
                    &lt;locales&gt;
                        &lt;locale&gt;en_US&lt;/locale&gt;
                        &lt;!--&lt;locale&gt;nl_NL&lt;/locale&gt;--&gt;
                    &lt;/locales&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
        &lt;defaultGoal&gt;install&lt;/defaultGoal&gt;
        &lt;resources&gt;
            &lt;resource&gt;
                &lt;directory&gt;${basedir}/src/main/resources&lt;/directory&gt;
            &lt;/resource&gt;
        &lt;/resources&gt;
    &lt;/build&gt;
</pre>
<p>The other big maven thing to configure is the server side. This you can find in the books-web project. There are dependencies for BlazeDS and the spring-flex project containing the BlazeDS spring integration. Please check the code if you want to see more of it. The last thing I want to show about maven are the repositories I use to find most of the artifacts. You do need to install some manually, but most of them come from an existing repository:</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;repositories&gt;
        &lt;repository&gt;
            &lt;id&gt;flex-mojos-repository&lt;/id&gt;
            &lt;url&gt;http://repository.sonatype.org/content/groups/public&lt;/url&gt;
            &lt;releases&gt;
                &lt;enabled&gt;true&lt;/enabled&gt;
            &lt;/releases&gt;
            &lt;snapshots&gt;
                &lt;enabled&gt;false&lt;/enabled&gt;
            &lt;/snapshots&gt;
        &lt;/repository&gt;
        &lt;repository&gt;
            &lt;id&gt;fnh&lt;/id&gt;
            &lt;url&gt;http://fna.googlecode.com/svn/trunk/fna/fna_m2_repository/&lt;/url&gt;
        &lt;/repository&gt;
        &lt;repository&gt;
            &lt;id&gt;Servebox&lt;/id&gt;
            &lt;url&gt;http://maven.servebox.org/repository&lt;/url&gt;
            &lt;releases&gt;
                &lt;enabled&gt;true&lt;/enabled&gt;
            &lt;/releases&gt;
            &lt;snapshots&gt;
                &lt;enabled&gt;false&lt;/enabled&gt;
            &lt;/snapshots&gt;
        &lt;/repository&gt;

        &lt;repository&gt;
            &lt;id&gt;spring-milestone&lt;/id&gt;
            &lt;name&gt;Spring Portfolio Milestone Repository&lt;/name&gt;
            &lt;url&gt;http://maven.springframework.org/milestone&lt;/url&gt;
            &lt;releases&gt;
                &lt;enabled&gt;true&lt;/enabled&gt;
            &lt;/releases&gt;
            &lt;snapshots&gt;
                &lt;enabled&gt;false&lt;/enabled&gt;
            &lt;/snapshots&gt;
        &lt;/repository&gt;
    &lt;/repositories&gt;
    &lt;pluginRepositories&gt;
        &lt;pluginRepository&gt;
            &lt;id&gt;flex-mojos-repository&lt;/id&gt;
            &lt;url&gt;http://repository.sonatype.org/content/groups/public&lt;/url&gt;
            &lt;releases&gt;
                &lt;enabled&gt;true&lt;/enabled&gt;
            &lt;/releases&gt;
            &lt;snapshots&gt;
                &lt;enabled&gt;false&lt;/enabled&gt;
            &lt;/snapshots&gt;
        &lt;/pluginRepository&gt;
    &lt;/pluginRepositories&gt;
</pre>
<p>Enough about maven, lets move on to the flex side.</p>
<h2>Introducing Mate, a flex framework</h2>
<p><img src="http://www.gridshore.nl/wp-content/uploads/mate-logo.png" alt="mate_logo.png" border="0" width="107" height="108" align="right" />Mate is a tag-based, event-driven Flex framework. At least that is what <a href="http://mate.asfusion.com/">the website</a> states. Event driven is very important. If you follow the recommended way to create your application you get a clean separation of front end components that show data, forms and interaction components. Each action should lead to an event, which is handled by Mate. Most of the logic is put into manager components.</p>
<p>Lets have a look at what happens when you click on the All Books button. The MainNavigation.mxml contains a button that calls the following code when the button is clicked.</p>
<pre class="brush: jscript; title: ; notranslate">
private function doObtainAllBooks():void {
    var event:BooksEvent = new BooksEvent(BooksEvent.OBTAIN_ALL_BOOKS);
    dispatchEvent(event);
}
</pre>
<p>As you can see, this only dispatches and event. Mate uses an mxml component with a lot of special tags to handle events. This handling can result in calling remote services, manager classes, dispatching new events and injecting data into view components. The following code block shows the capturing of this event, calling a remote service to obtain the books, giving the books to a manager, injecting the results into the AllBooks.mxml view component. Finally a new navigation event is dispatched to open the view component. The names of the tags give a clear description of what is going on.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;EventMap xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; xmlns=&quot;http://mate.asfusion.com/&quot;&gt;
    ...
    &lt;mx:RemoteObject id=&quot;booksService&quot;
                     endpoint=&quot;http://{props.host}:{props.port}/{props.webcontext}/messagebroker/amf&quot;
                     destination=&quot;remoteBookManager&quot;/&gt;

    &lt;EventHandlers type=&quot;{BooksEvent.OBTAIN_ALL_BOOKS}&quot; debug=&quot;true&quot;&gt;
        &lt;RemoteObjectInvoker instance=&quot;{booksService}&quot; method=&quot;obtainAllBooks&quot;&gt;
            &lt;resultHandlers&gt;
                &lt;MethodInvoker generator=&quot;{BooksManager}&quot; method=&quot;storeBooks&quot; arguments=&quot;{resultObject}&quot;/&gt;
                &lt;EventAnnouncer generator=&quot;{MainNavigationEvent}&quot; type=&quot;{MainNavigationEvent.NAVIGATION}&quot;&gt;
                    &lt;Properties navigationId=&quot;{MainNavigationEvent.ALL_BOOKS}&quot;/&gt;
                &lt;/EventAnnouncer&gt;
            &lt;/resultHandlers&gt;
        &lt;/RemoteObjectInvoker&gt;
    &lt;/EventHandlers&gt;
    &lt;Injectors target=&quot;{AllBooks}&quot;&gt;
        &lt;PropertyInjector source=&quot;{BooksManager}&quot; sourceKey=&quot;books&quot; targetKey=&quot;books&quot;/&gt;
    &lt;/Injectors&gt;
    ...
&lt;/EventMap&gt;
</pre>
<p>Now have a look at the code of the <em>BooksManager</em> component. Calling the actual remote object and transforming java objects into flex objects is done using BlazeDS. More on this later on. The objects that you get back are Books.</p>
<pre class="brush: jscript; title: ; notranslate">
public class BooksManager {
    [Bindable]public var books:ArrayCollection = new ArrayCollection();

    public function storeBooks(obj:Object):void {
        books = ArrayCollection(obj);
    }
}

[Bindable]
[RemoteClass(alias=&quot;nl.gridshore.samples.books.domain.Book&quot;)]
public class Book {
    public var id:Number;
    public var title:String;
    public var isbn:String;
    public var authors:ArrayCollection = new ArrayCollection();

    public function Book() {
    }

    public function addAuthor(author:Author):void {
        authors.addItem(author);
    }
}
</pre>
<p>That was your crash coarse in Mate. If you want to know more about the basics, be sure to check out their website. A lot of links to other good resources are available. Time to move on. For the security part I need to extend Mate. That is what the next section is about</p>
<h2>Implementing authentication in the flex client</h2>
<p>With respect to the authentication there are three different events that take place:</p>
<ul>
<li>Check if needs authentication &#8211; If the current client is not authenticated the login form must be presented</li>
<li>Try authentication &#8211; check the provided credentials, show an error message if authentication fails or go to the initial screen.</li>
<li>Logout &#8211; logout from the client</li>
</ul>
<p>The handling of these three events can be found in the SecurityEventMap.mxml component. This part of the solution has changed the most with respect to previous versions of the sample. In the current release I make use of the standard capabilities of the flex class <a href="http://livedocs.adobe.com/flex/3/langref/mx/messaging/ChannelSet.html">mx.messaging.ChannelSet</a>. I have created an extension to interact with this channelset using tags, the <strong>ChannelSetInvoker</strong>. Creating this class was not easy to me, there is <a href="http://mate.asfusion.com/page/how-to/extend-mate">a document that can help</a> and the source code from existing tags is very helpful. I run by some things I learned while creating the extension.</p>
<p>A very important part is to make a difference to properties that you need to configure the component and arguments to the methods being called. The ChannelSet will not change and can be provided as a property. The username and password for the login method are arguments to the method and need to be provided as arguments. Within the source code you can see the difference as well, the ChannelSet is a property of the component, while username and password are not really visible in the code. The ChannelSetInvoker component uses the ResultEvent and the FaultEvent to communicate with handlers. You can register handlers in the Mate event mapping component. Of course we need to registers these handlers within the component. This is done in the complete function</p>
<pre class="brush: jscript; title: ; notranslate">
    override protected function complete(scope:IScope):void {
        if (this.resultHandlers &amp;&amp; resultHandlers.length &gt; 0) {
            this.createInnerHandlers(scope, ResultEvent.RESULT, resultHandlers);
        }
        if (this.faultHandlers &amp;&amp; faultHandlers.length &gt; 0) {
            this.createInnerHandlers(scope, FaultEvent.FAULT, faultHandlers);
        }
    }
</pre>
<p>Time to move on to the fun part, the actual interaction with the ChannelSet. The components supports three methods (think about the three events we needed): login, logout and authenticated. The magic takes place in the run function.</p>
<pre class="brush: jscript; title: ; notranslate">
    override protected function run(scope:IScope):void {
        var argumentList:Array = (new SmartArguments()).getRealArguments(scope, this.arguments);
        innerHandlersDispatcher = channelSet;

        if (method == &quot;login&quot;) {
            if (!channelSet.authenticated) {
                var loginToken:AsyncToken = channelSet.login(argumentList[0], argumentList[1]);
                loginToken.addResponder(new AsyncResponder(
                        function(event:ResultEvent, token:Object = null):void {
                            scope.lastReturn = event.result;
                            innerHandlersDispatcher.dispatchEvent(event);
                        },
                        function(event:FaultEvent, token:Object = null):void {
                            scope.lastReturn = event.fault;
                            innerHandlersDispatcher.dispatchEvent(event);
                        }));
            }
        } else if (method == &quot;logout&quot;) {
            var logoutToken:AsyncToken = channelSet.logout();
            logoutToken.addResponder(new AsyncResponder(
                    function(event:ResultEvent, token:Object = null):void {
                        innerHandlersDispatcher.dispatchEvent(event);
                    },
                    function(event:FaultEvent, token:Object = null):void {
                        innerHandlersDispatcher.dispatchEvent(event);
                    }));
        } else if (method == &quot;authenticated&quot;) {
            var isAuthenticated:Boolean = channelSet.authenticated;
            scope.lastReturn = isAuthenticated;
            var event:ResultEvent = new ResultEvent(&quot;user is authenticated?&quot;, false, true, isAuthenticated);
            innerHandlersDispatcher.dispatchEvent(event);
        }
    }
</pre>
<p>Check how we use the provided arguments in the login method handling. AsyncToken objects are used to handle the asynchronous results of the login and logout methods. Finally the innerHandlerDispatcher is used to notify the registered handlers of new results. For the final piece of the puzzle, have a look at the implementation of the event handling. Due to the names of the tags the code is self explanatory.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;EventMap xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; xmlns=&quot;http://mate.asfusion.com/&quot;
          xmlns:extensions=&quot;extensions.*&quot;&gt;
    &lt;mx:ChannelSet id=&quot;authenticationChannelSet&quot;&gt;
        &lt;mx:AMFChannel id=&quot;myAmf&quot; uri=&quot;http://{props.host}:{props.port}/{props.webcontext}/messagebroker/amf&quot;/&gt;
    &lt;/mx:ChannelSet&gt;

    &lt;!-- Event handlers --&gt;
    &lt;EventHandlers type=&quot;{AuthenticationEvent.TRY}&quot; debug=&quot;true&quot;&gt;
        &lt;extensions:ChannelSetInvoker method=&quot;login&quot;
                                      channelSet=&quot;{authenticationChannelSet}&quot;
                                      arguments=&quot;{[event.username,event.password]}&quot;&gt;
            &lt;extensions:resultHandlers&gt;
                &lt;MethodInvoker generator=&quot;{AuthenticationManager}&quot; method=&quot;logInSuccess&quot;
                               arguments=&quot;{currentEvent.result}&quot;/&gt;
            &lt;/extensions:resultHandlers&gt;
            &lt;extensions:faultHandlers&gt;
                &lt;MethodInvoker generator=&quot;{AuthenticationManager}&quot; method=&quot;storeAuthenticationProblem&quot;
                               arguments=&quot;{currentEvent.fault}&quot;/&gt;
            &lt;/extensions:faultHandlers&gt;
        &lt;/extensions:ChannelSetInvoker&gt;
    &lt;/EventHandlers&gt;

    &lt;EventHandlers type=&quot;{AuthenticationEvent.CHECK_NEEDS}&quot; debug=&quot;true&quot;&gt;
        &lt;extensions:ChannelSetInvoker method=&quot;authenticated&quot; channelSet=&quot;{authenticationChannelSet}&quot;&gt;
            &lt;extensions:resultHandlers&gt;
                &lt;MethodInvoker generator=&quot;{AuthenticationManager}&quot; method=&quot;isAuthenticated&quot;
                               arguments=&quot;{currentEvent.result}&quot;/&gt;
            &lt;/extensions:resultHandlers&gt;
        &lt;/extensions:ChannelSetInvoker&gt;
    &lt;/EventHandlers&gt;

    &lt;EventHandlers type=&quot;{AuthenticationEvent.LOGOUT}&quot; debug=&quot;true&quot;&gt;
        &lt;extensions:ChannelSetInvoker method=&quot;logout&quot; channelSet=&quot;{authenticationChannelSet}&quot;&gt;
            &lt;extensions:resultHandlers&gt;
                &lt;MethodInvoker generator=&quot;{AuthenticationManager}&quot; method=&quot;logout&quot;/&gt;
            &lt;/extensions:resultHandlers&gt;
        &lt;/extensions:ChannelSetInvoker&gt;
    &lt;/EventHandlers&gt;
&lt;/EventMap&gt;
</pre>
<p>To be able to actually authenticate, we need a server component as well. With the RC2 release of the spring-flex project this has become incredibly easy. The next section talks about that part of the application.</p>
<h2>Spring-flex, how easy can it be.</h2>
<p>I do want to stress that the documentation coming with spring-flex is a good read. I recommend to read it to see all options that you have. For now I discuss only the basic steps.</p>
<p><a href="http://static.springframework.org/spring-flex/docs/1.0.x/reference/html/ch04s02.html">http://static.springframework.org/spring-flex/docs/1.0.x/reference/html/ch04s02.html</a></p>
<ul>
<li>Configure the web.xml, add the dispatcher servlet and the springSecurityFilterChain for the initialization of spring security.</li>
<li>I added one servlet mapping for *.properties. This is for loading the config.properties file through a spring bean. Check my post <a href="http://www.gridshore.nl/2009/01/23/flex-remoting-without-configuring-the-client/">flex remoting without configuring the client</a> to find out more on this topic.</li>
<li>Configure BlazeDS using the services-config.xml file in the default location WEB-INF/flex. Remember that we do not need this file in the flex client anymore like we did in the past. It is also this file where you configure BlazeDS logging.</li>
<li>Configure the security, be sure to look good before it is over.</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
    &lt;!-- Bootstraps and exposes the BlazeDS MessageBroker --&gt;
    &lt;flex:message-broker&gt;
        &lt;flex:secured /&gt;
    &lt;/flex:message-broker&gt;

    &lt;!-- remote proxies --&gt;
    &lt;flex:remoting-destination destination-id=&quot;remoteBookManager&quot; ref=&quot;bookManager&quot; exclude-methods=&quot;internalUseStoreBook&quot;/&gt;

    &lt;security:http entry-point-ref=&quot;preAuthenticatedEntryPoint&quot;/&gt;

    &lt;bean id=&quot;preAuthenticatedEntryPoint&quot;
        class=&quot;org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint&quot; /&gt;

    &lt;security:global-method-security&gt;
        &lt;security:protect-pointcut
            expression=&quot;execution(* nl.gridshore.samples.books.business.*Manager.store*(..))&quot;
            access=&quot;ROLE_ADMIN&quot;/&gt;
        &lt;security:protect-pointcut
            expression=&quot;execution(* nl.gridshore.samples.books.business.*Manager.obtain*(..))&quot;
            access=&quot;ROLE_USER&quot;/&gt;
    &lt;/security:global-method-security&gt;

    &lt;security:authentication-provider&gt;
        &lt;security:user-service&gt;
            &lt;security:user name=&quot;admin&quot; password=&quot;admin&quot; authorities=&quot;ROLE_USER, ROLE_ADMIN&quot;/&gt;
            &lt;security:user name=&quot;user&quot; password=&quot;user&quot; authorities=&quot;ROLE_USER&quot;/&gt;
        &lt;/security:user-service&gt;
    &lt;/security:authentication-provider&gt;
</pre>
<p>As you can see, most of the configuration deals with method-security and the authentication provider. It takes around 5 lines of code to configure spring security to receive all incoming authentication requests and connect to BlazeDS security. I think this is pretty amazing. During the refactoring I could remove a lot of configuration and a java class. Also the client code has become a lot easier and adheres to standards of flex remoting.</p>
<h2>Concluding</h2>
<p>That is it, now we have a much cleaner sample. Be sure to check out the code and of course the referring frameworks. I also want to mention the extendability of the Mate framework. At first I had to understand some basic concepts, but than it become easy to write an extension. I hope you like the blog. Questions and commands are welcome.</p>
<p>See you again next time.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F05%2F24%2Fintegrate-flex-security-in-mate-using-the-spring-blazeds-integration-project%2F&amp;title=Integrate%20flex%20security%20in%20Mate%20using%20the%20spring%20BlazeDS%20integration%20project&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/05/24/integrate-flex-security-in-mate-using-the-spring-blazeds-integration-project/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>Upgrading the flex based books-overview sample</title>
		<link>http://www.gridshore.nl/2009/05/10/upgrading-the-flex-based-books-overview-sample/</link>
		<comments>http://www.gridshore.nl/2009/05/10/upgrading-the-flex-based-books-overview-sample/#comments</comments>
		<pubDate>Sun, 10 May 2009 20:14:09 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=766</guid>
		<description><![CDATA[<p>As a lot of you out there know, I write a lot about flex and java. For my flex posts I use a sample called books-overview. You can find the sourcecode on google code. A lot of different frameworks released new versions. In this post I describe the some of the upgrades that are [...]]]></description>
			<content:encoded><![CDATA[<p>As a lot of you out there know, I write a lot about flex and java. For my flex posts I use a sample called books-overview. You can find the sourcecode on <a href="http://code.google.com/p/gridshore">google code</a>. A lot of different frameworks released new versions. In this post I describe the some of the upgrades that are important to me</p>
<ul>
<li>flex-mojos (3.1) &#8211; the maven flex plugin</li>
<li>Mate (0.8.7.1) &#8211; a flex framework</li>
<li>Spring BlazeDS Integration 1.0.0.RC1</li>
</ul>
<p>Read on to find out the changes I had to make, the problems I ran into (not that much actually).</p>
<p><span id="more-766"></span><br />
<h2>Maven build</h2>
<p>Let us start with the build system. I want to upgrade to the latest and greatest 3.1 version of the flex-mojos plugin. This is not hard, there is excellent documentation available in the form of this <a href="http://www.sonatype.com/books/maven-book-stage/reference/ch20.html">open source book</a>.</p>
<p>I did not have to make a lot of changes, the groupId and the artifactId of the plugin have changed, but that is easy. I do have problems running the tests on a mac. The mentioned book does give a method to make the flex unit tests work, but it does not work for me like I would have wanted it to. It seems that the call to the flash executable is wrong. The suggested way is to cp the Flash Player.app to the /Applications folder. Please do not do this using sudo, I prefer to do it by hand using the Finder. Another problem is the call from the plugin. It calls FlashPlayer.app, I think It should be Flash\ Player. Therefore I add the following directive to the maven command:</p>
<p><strong>-DflashPlayer.command=Flash\ Player</strong></p>
<p>This only works if you make sure the player is on the path, I included the following line in my .bash_profile file:</p>
<p><strong>export PATH=$PATH:/Applications/Flash\ Player.app/Contents/MacOS</strong></p>
<p>Now the application is running again. Time to move on.</p>
<h2>Mate</h2>
<p>Mate is now upgraded to the released version 0.8.7.1. I did not find a good repository containing this release for maven. Therefore I had to add it manually. I did not really go into the new features. I see there are mock objects now for services. I have not come up with the right way to use them without changing my code in for instance unit tests. Therefore there are no exiting things to do for mate. Feel free to add a comment if I missed something.</p>
<h2>Spring BlazeDS Integration</h2>
<p>It seems to be a small step, but I had to make some adjusments. I had to change the bean from flex:remote-service into flex:remoting-destination. Beware to change the service-id into destination-id if you need another name of the destination than the default name deduced from the exposed bean. This was not right at the moment in the documentation.</p>
<p>The flex:remoting-destination configuration than becomes:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;flex:remoting-destination destination-id=&quot;remoteBookManager&quot; ref=&quot;bookManager&quot; exclude-methods=&quot;internalUseStoreBook&quot;/&gt;
</pre>
<p>To make this all work, I had to add a dependency which is optional by default but I did need it. Not sure why.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
    &lt;version&gt;0.9.9-6&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<p>The next problem I ran into, had to do with the following error message. I do only show the first line, not the complete stacktrace.</p>
<pre>
Problem with the : org.springframework.beans.factory.NoSuchBeanDefinitionException:
        No bean named '_filterChainList' is defined
</pre>
<p>As described is <a href="http://forum.springsource.org/showthread.php?t=71633">this forum post</a>, this can be resolved by disabling session fixation in the http configuration of spring security. Jeremy has tested this as well and stated it is indeed a bug. A fix is committed and will be in the next release.</p>
<p>Now everything is working again. I am personally not fond of the spring dependencies labelled 2.5.6.A. These have to do with the special OSGi enabled jars. But they give a lot of double dependencies on external jars. Luckily Jeremy has promised to create a version without the OSGi versions as well. Check <a href="http://forum.springsource.org/showthread.php?t=71631">this post</a>. The responsiveness of the community and the committers is great, this is what I like so much about the spring framework. I had to say it <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Some additional remarks</h2>
<p>Next to the framework upgrades I also want to mention some things you can find in the sample. I added a unit test based on FlexUnit. I took the flex security out of the normal project and placed it into a seperate swc project.</p>
<p>What is left? Well I need to add the old features in the new mate version. You cannot add new books at the moment. I also want to have a good look at the security integration in the BlazeDS integration project of the spring framework. I also want to do some messaging, which I have done already in another project. Finally I have a nice maven solution to print a build version number in the flex application. If you like that idea, be patient. I&#8217;ll try to write my next post about that topic.</p>
<p>Thanks for reading, hope to see you back soon. Do not forget to connect to me via linkedin, gridshore has it&#8217;s own group. You can also stay up to date using twitter.</p>
<h2>References</h2>
<ul>
<li><a href="http://www.sonatype.com/books/maven-book-stage/reference/ch20.html">http://www.sonatype.com/books/maven-book-stage/reference/ch20.html</a> &#8211; reference manual for the flex maven build plugin.</li>
<li><a href="http://www.statusq.org/archives/2008/07/30/1954/">http://www.statusq.org/archives/2008/07/30/1954/</a> &#8211; reference to the easiest way to get wget on your machine.</li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F05%2F10%2Fupgrading-the-flex-based-books-overview-sample%2F&amp;title=Upgrading%20the%20flex%20based%20books-overview%20sample&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/05/10/upgrading-the-flex-based-books-overview-sample/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Doing flex with JMS: combining BlazeDS, spring-jms and ActiveMQ</title>
		<link>http://www.gridshore.nl/2009/04/13/doing-flex-with-jms-combining-blazeds-spring-jms-and-activemq/</link>
		<comments>http://www.gridshore.nl/2009/04/13/doing-flex-with-jms-combining-blazeds-spring-jms-and-activemq/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 05:34:03 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[ActiveMQ]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=744</guid>
		<description><![CDATA[<p>The complete story of combining a lot of different technologies and a lot of different blog post and articles found on the web. There are multiple good posts around this topic, but none of them gave the exact solution I needed. Therefore I write this blog post, maybe someone else can use this as [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/flexlogo.png" alt="flexlogo.png" border="0" width="100" height="100" align="left" />The complete story of combining a lot of different technologies and a lot of different blog post and articles found on the web. There are multiple good posts around this topic, but none of them gave the exact solution I needed. Therefore I write this blog post, maybe someone else can use this as well.</p>
<p><img src="http://www.gridshore.nl/wp-content/uploads/picture-11.png" alt="Picture 1.png" border="0" width="379" height="98" align="right" />To get an idea if this post is about the approach you need, let me describe the problem or challenge I am facing.</p>
<p>I have an application that is showing the current stock supply of an online shop. Because obtaining all stock items takes a few seconds, I want to notify users when stock changes. To be able to do this I want to communicate changes from a java server using spring technology to a flex client through BlazeDS. The amount of users is not very big, and the changes to the stock are not important when someone obtains all stock items. Therefore the messages do not need to be persisted and we can use an in memory message server implementation provided by ActiveMq. So the flow becomes:</p>
<ul>
<li>Spring sends a message to a topic.</li>
<li>BlazeDS pics up the message and transforms the stock payload</li>
<li>All flex clients gets notified of the message</li>
</ul>
<p>Go on to read about the solution.</p>
<p><span id="more-744"></span><br />
<h2>Technology stack</h2>
<p>The project uses a normal architecture, web layer, business layer and data layer. There is an integration component for xml export. The jms part is an integral part of the business layer, maybe I move it to the integration layer. But that does not have influence on the solution. Now we focus on the most important components. The web component and the business component.</p>
<h3>Web/BlazeDS project</h3>
<p>BlazeDS is used as the remoting solution for the flex clients. The flex clients send requests to the server. BlazeDS runs on the server, receives the requests and using spring factories calls the spring beans. For our solution we need to do it the other way around. From the server we want to notify all connected clients. Using BlazeDS, this is done with JMS. BlazeDS has an adapter to publish and subscribe to queues and topics.</p>
<p>BlazeDS only supports client pull for notifications. This is not ideal, actual push by the server would be better. You&#8217;ll need less bandwidth and less activity on the server as well as client. This is supported by the commercial version life cycle data services of adobe, but not by BlazeDS. The commercial version uses a proprietary called <strong>Real Time Messaging Protocol</strong>. You can read more on this topic in this <a href="http://www.trajiklyhip.com/blog/index.cfm/2008/5/21/The-Truth-About-BlazeDS-and-Push-Messaging">blog post by Aaron West</a>. This technology is not Open Source and therefor not in the BlazeDS technology stack. For applications with a limited amount of users, this client pull is not a real problem. The client pull can use two different channel types: Streaming and polling. I&#8217;ll settle with polling for now. Streaming might me the better option, but polling works for now. More info on the channels can be found in an <a href="http://www.adobe.com/devnet/livecycle/articles/blazeds_testdrive_07.html">example by Adobe</a></p>
<h3>Business containing JMS provider</h3>
<p>The spring framework comes with some extras to support JMS communication. Sending messages is made easy using the spring framework. We still need a messaging platform. I have choosen ActiveMQ. It is one of the best known Open Source JMS providers and it has very good integration with the spring framework. ActiveMQ comes with a mechanism to embed the messaging container in your application. This can be fully configured in spring. </p>
<h2>Maven for dependencies</h2>
<p>I am not going into a great detail here. I have written multiple posts about BlazeDS, find maven setup in one of these posts. For the messaging I had to add the following dependencies</p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
     &lt;groupId&gt;org.springframework&lt;/groupId&gt;
     &lt;artifactId&gt;spring-jms&lt;/artifactId&gt;
     &lt;version&gt;${spring.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
     &lt;groupId&gt;javax.jms&lt;/groupId&gt;
     &lt;artifactId&gt;jms&lt;/artifactId&gt;
     &lt;version&gt;1.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
     &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
     &lt;artifactId&gt;activemq-core&lt;/artifactId&gt;
     &lt;version&gt;5.2.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
     &lt;groupId&gt;org.apache.xbean&lt;/groupId&gt;
     &lt;artifactId&gt;xbean-spring&lt;/artifactId&gt;
     &lt;version&gt;3.5&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<h2>Spring configuration of ActiveMQ</h2>
<p>Time to start the messaging container. I could find most of the required info online in other post. Still I had to do some tweaking to get it done. The most important post I used is <a href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html">how-do-i-embed-a-broker-inside-a-connection</a>. I&#8217;ll show you all the configuration in a spring config file first.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:amq=&quot;http://activemq.apache.org/schema/core&quot;
       xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
       xsi:schemaLocation=&quot;
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd&quot;&gt;

    &lt;amq:broker useJmx=&quot;false&quot; persistent=&quot;false&quot;&gt;
        &lt;amq:transportConnectors&gt;
            &lt;amq:transportConnector uri=&quot;tcp://localhost:61616&quot;/&gt;
        &lt;/amq:transportConnectors&gt;
    &lt;/amq:broker&gt;

    &lt;amq:topic id=&quot;destination&quot; physicalName=&quot;stockMessageTopic&quot;/&gt;

    &lt;amq:connectionFactory id=&quot;jmsFactory&quot; brokerURL=&quot;vm://localhost&quot;/&gt;
&lt;/beans&gt;
</pre>
<h3>Namespace</h3>
<p>ActiveMQ has namespace support for spring, I think they do use an extension in the XBean project. I did not really evaluate this, but you need the dependency. Beware that in the original sample the xsd does not have the right url. If you want to use xml support in Intellij, you need to change the xsd url in what I have. The namespace can be used to configure the Topic, the connection factory and of course the broker.</p>
<h3>Topic destination</h3>
<p>We configure a topic, again I spend some time to figure this out. The sample used a query instead of a topic. I just missed it. So beware to take the right one. The physical name is important, this is used by BlazeDS as well to connect to the topic to receive messages. Check the Tomcat configuration later on.</p>
<h3>Connection Factory</h3>
<p>Configuration of a connection factory that connects to a local broker (running in the same jvm). This connection factory can be used by clients, in our case the spring jms client that publishes messages.</p>
<h3>Broker</h3>
<p>The broker does the actual routing of messages, provides the queues and topics. In short this is the message container. Because we define it in the spring container, it runs in the same jvm. Which is perfect in our case, we do not need persistent messages. The send messages can very short, just long enough to notify all connected subscribers.</p>
<h2>The Message provider</h2>
<p>The message provider is a spring bean. We need to add a bit of spring configuration. The next block shows the additional beans.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;bean id=&quot;myJmsTemplate&quot; class=&quot;org.springframework.jms.core.JmsTemplate&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot;&gt;
            &lt;bean class=&quot;org.springframework.jms.connection.SingleConnectionFactory&quot;&gt;
                &lt;property name=&quot;targetConnectionFactory&quot;&gt;
                    &lt;ref local=&quot;jmsFactory&quot;/&gt;
                &lt;/property&gt;
            &lt;/bean&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;stockMessageProducer&quot; class=&quot;nl.primatras.backoffice.service.jms.JmsStockMessageProducer&quot;&gt;
        &lt;property name=&quot;jmsTemplate&quot; ref=&quot;myJmsTemplate&quot;/&gt;

        &lt;property name=&quot;destination&quot; ref=&quot;destination&quot;/&gt;
    &lt;/bean&gt;
</pre>
<p>Spring jms makes use of a JmsTemplate, you can read more about this in the spring <a href="http://static.springframework.org/spring/docs/2.5.x/reference/jms.html">reference manual</a>. The template is used to send a message to a queue or topic. Therefore the jmsTemplate needs to have a connection factory. The other component is the message producer. This class does the actual message creation. To be able to do just that, it needs the mentioned jmsTemplate and a destination. The the code looks like this:</p>
<pre class="brush: java; title: ; notranslate">
    public void sendStockUpdate(final StockVO stock) {
        logger.debug(&quot;About th send a message ...&quot;);
        jmsTemplate.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createObjectMessage(stock);
            }
        });
    }
</pre>
<p>Notice that we use the method createObjectMessage, we will come back to this when configuring BlazeDS. You can also use TextMessage, but we use the javax.jms.ObjectMessage and let BlazeDS do it&#8217;s parsing trick on the client.</p>
<h2>Tomcat configuration</h2>
<p>BlazeDS uses JNDI to find the connection factory and the name of the queue or topic to connect to. These need to be available. WIth tomcat that is not to hard. You can configure this using the context.xml file that can be found in the <em>conf</em> folder. The contents of this file are copied almost one-on-one from this <a href="http://mmartinsoftware.blogspot.com/2008/05/simplified-blazeds-and-jms.html">excellent blog post</a>.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Context path=&quot;/BlazeTest&quot;&gt;
&lt;Resource name=&quot;jms/flex/TopicConnectionFactory&quot;
        type=&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;
        description=&quot;JMS Connection Factory&quot;
        factory=&quot;org.apache.activemq.jndi.JNDIReferenceFactory&quot;
        brokerURL=&quot;tcp://localhost:61616&quot;
        brokerName=&quot;myBroker&quot;/&gt;
&lt;Resource name=&quot;jms/stockMessageTopic&quot;
        type=&quot;org.apache.activemq.command.ActiveMQTopic&quot;
        description=&quot;a stock topic&quot;
        factory=&quot;org.apache.activemq.jndi.JNDIReferenceFactory&quot;
        physicalName=&quot;stockMessageTopic&quot;/&gt;
&lt;/Context&gt;
</pre>
<p>The names of the resources are used in the flex configuration, important are the brokerURL and the physical name of the topic. These are the same as the ones configured in the spring activeMQ xml.</p>
<h2>BlazeDS/Flex Configuration</h2>
<p>Configuration of the destinations of messaging is done in the messaging-config.xml file. The file looks like this.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;service id=&quot;message-service&quot; class=&quot;flex.messaging.services.MessageService&quot;&gt;
    &lt;adapters&gt;
        &lt;adapter-definition id=&quot;actionscript&quot; class=&quot;flex.messaging.services.messaging.adapters.ActionScriptAdapter&quot;
                            default=&quot;true&quot;/&gt;
        &lt;adapter-definition id=&quot;jms&quot; class=&quot;flex.messaging.services.messaging.adapters.JMSAdapter&quot; default=&quot;false&quot;/&gt;
    &lt;/adapters&gt;

    &lt;default-channels&gt;
        &lt;channel ref=&quot;my-polling-amf&quot;/&gt;
    &lt;/default-channels&gt;

    &lt;destination id=&quot;stock-topic-jms&quot;&gt;
        &lt;properties&gt;
            &lt;jms&gt;
                &lt;destination-type&gt;Topic&lt;/destination-type&gt;
                &lt;message-type&gt;javax.jms.ObjectMessage&lt;/message-type&gt;
                &lt;connection-factory&gt;java:comp/env/jms/flex/TopicConnectionFactory&lt;/connection-factory&gt;
                &lt;destination-jndi-name&gt;java:comp/env/jms/stockMessageTopic&lt;/destination-jndi-name&gt;
                &lt;delivery-mode&gt;NON_PERSISTENT&lt;/delivery-mode&gt;
                &lt;message-priority&gt;DEFAULT_PRIORITY&lt;/message-priority&gt;
                &lt;acknowledge-mode&gt;AUTO_ACKNOWLEDGE&lt;/acknowledge-mode&gt;
                &lt;initial-context-environment&gt;
                    &lt;property&gt;
                        &lt;name&gt;Context.INITIAL_CONTEXT_FACTORY&lt;/name&gt;
                        &lt;value&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/value&gt;
                    &lt;/property&gt;
                    &lt;property&gt;
                        &lt;name&gt;Context.PROVIDER_URL&lt;/name&gt;
                        &lt;value&gt;tcp://localhost:61616&lt;/value&gt;
                    &lt;/property&gt;
                &lt;/initial-context-environment&gt;
            &lt;/jms&gt;
        &lt;/properties&gt;
        &lt;adapter ref=&quot;jms&quot;/&gt;
    &lt;/destination&gt;
&lt;/service&gt;
</pre>
<p>There are a few things to notice here. You can see the message type, the connection factory and destination using JNDI. The initial context environment is coming from ActiveMQ and the provider url should be familiar by now.</p>
<h2>The client</h2>
<p>The final step is the flex client. Flex has very good support for consumers and producers. On the client I am mainly using Mate, which is a flex event driven framework. It has support for messaging as well through the MessageHandlers tag. It turns however that flex 3.2 has a problem together with Mate. Check <a href="http://mate.asfusion.com/page/documentation/tags/messagehandlers">this blog post</a> for the way it should work and go through the comments to get an idea why it does not work. Because of this problem I had to take a slight detour. The most important part is very easy though. The following code block shows the most important part of configuring a consumer.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:Consumer id=&quot;consumer&quot; destination=&quot;stock-topic-jms&quot; message=&quot;messageHandler(event)&quot;
             acknowledge=&quot;acknowledgeHandler(event);&quot; fault=&quot; faultHandler(event)&quot;/&gt;
</pre>
<p>Then finally you need to login, this can best be done in the creationComplete handler.</p>
<pre class="brush: jscript; title: ; notranslate">
private function logon():void {
    consumer.subscribe();
}
</pre>
<p>That is it, now you just have to implement the three methods that are attached to the consumer. I&#8217;ll show the messageHandler implementation as the last piece of the puzzle.</p>
<pre class="brush: jscript; title: ; notranslate">
private function messageHandler(event:MessageEvent):void {
    var stock:Stock = event.message.body as Stock;
    var updateEvent:StockEvent = new StockEvent(StockEvent.UPDATE_STOCKITEM_EVENT);
    updateEvent.stock = stock;
    dispatchEvent(updateEvent);
}
</pre>
<p>Notice that by using the ObjectMessage type, the body of a message is a stock object.</p>
<h2>The future</h2>
<p>This is all looking very good. I am very pleased about the result. I hope the spring blazeds integration project will make life easier. I know that m2 release contains some messaging support. Did not have time to have a look at it yet. Hope to add it to m books-overview example in a while.</p>
<h2>Conclusions</h2>
<p>I do want to stress that most of the configuration and code come from other blog posts. I have named them all in the references section. The biggest problem is to combine the server side spring/activemq part with the client/blazeds part. I think this blog post closes that hole.</p>
<p>Stay tuned for more flex stories.</p>
<h2>References</h2>
<ul>
<li><a href="http://livedocs.adobe.com/blazeds/1/blazeds_devguide/">http://livedocs.adobe.com/blazeds/1/blazeds_devguide/</a></li>
<li><a href="http://mmartinsoftware.blogspot.com/2008/05/simplified-blazeds-and-jms.html">http://mmartinsoftware.blogspot.com/2008/05/simplified-blazeds-and-jms.html</a></li>
<li><a href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html">http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html</a></li>
<li><a href="http://mate.asfusion.com/page/documentation/tags/messagehandlers">http://mate.asfusion.com/page/documentation/tags/messagehandlers</a></li>
<li><a href="http://bugs.adobe.com/jira/browse/BLZ-300">http://bugs.adobe.com/jira/browse/BLZ-300</a></li>
<li><a href="http://www.joshuaostrom.com/2008/08/01/tunkey-blazeds-jms-activemq/">http://www.joshuaostrom.com/2008/08/01/tunkey-blazeds-jms-activemq/</a></li>
<li><a href="http://www.adobe.com/devnet/livecycle/articles/blazeds_testdrive_07.html">http://www.adobe.com/devnet/livecycle/articles/blazeds_testdrive_07.html</a></li>
<li><a href="http://www.trajiklyhip.com/blog/index.cfm/2008/5/21/The-Truth-About-BlazeDS-and-Push-Messaging">http://www.trajiklyhip.com/blog/index.cfm/2008/5/21/The-Truth-About-BlazeDS-and-Push-Messaging</a></li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F04%2F13%2Fdoing-flex-with-jms-combining-blazeds-spring-jms-and-activemq%2F&amp;title=Doing%20flex%20with%20JMS%3A%20combining%20BlazeDS%2C%20spring-jms%20and%20ActiveMQ&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/04/13/doing-flex-with-jms-combining-blazeds-spring-jms-and-activemq/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Upgrading to Spring BlazeDS Integration M2</title>
		<link>http://www.gridshore.nl/2009/03/08/upgrading-to-spring-blazeds-integration-m2/</link>
		<comments>http://www.gridshore.nl/2009/03/08/upgrading-to-spring-blazeds-integration-m2/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 11:15:45 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=657</guid>
		<description><![CDATA[<p>I have written some posts about using flex and the project Spring BlazeDS Integration. If you haven&#8217;t read that post I suggest you start there first : Flex remoting without configuring the client. That said, what is this post about? As the title already says, we are going to upgrade the example from the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/flexlogo.png" alt="flexlogo.png" border="0" width="100" height="100" align="left" /><img src="http://www.gridshore.nl/wp-content/uploads/springlogo1.png" alt="springlogo.png" border="0" width="100" height="45" align="right" />I have written some posts about using flex and the project <a href="http://www.springsource.org/node/1100">Spring BlazeDS Integration</a>. If you haven&#8217;t read that post I suggest you start there first : <a href="http://www.gridshore.nl/2009/01/23/flex-remoting-without-configuring-the-client/">Flex remoting without configuring the client</a>. That said, what is this post about? As the title already says, we are going to upgrade the example from the previous blog post to use the new features of the M2 release of spring Blazeds integration.</p>
<p><span id="more-657"></span><br />
<h2>Maven</h2>
<p>I do not think the spring blazeds artifacts are available in maven yet. Therefor you have to download them and install them in your local maven repo, or deploy them in your Artifactory if you use it.</p>
<p><code><br />
mvn install:install-file -DgroupId=org.springframework.flex -DartifactId=org.springframework.flex -Dversion=1.0.0.M2 -Dpackaging=jar -Dfile=/path/to/jar<br />
</code></p>
<p>Change the used version of the jar in the books-web projects pom.xml. If you haven&#8217;t downloaded the sources yet, you can <a href="http://code.google.com/p/gridshore/source/browse/#svn/trunk/books-overview">find them here</a>.</p>
<p>Doing a mvn clean install and everything should be fine. If you are having problems with out of memory exceptions, give maven a bit of extra memory</p>
<p><code><br />
export MAVEN_OPTS=-Xmx256m<br />
</code></p>
<h2>Namespace support in spring configuration</h2>
<h3>Message broker</h3>
<p>Next up is changing the spring configuration to use the new namespace support. Before you can use the new namespace, you have to specify it in the xml header. The next code block shows you the configuration as I use it. The suggestion comes from the reference manual.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot;
       xsi:schemaLocation=&quot;
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;
...
&lt;/beans&gt;
</pre>
<p>The first element configures the message broker, the handler mapping and a message broker handler adapter. If you read my previous post, remember that we add our own handler adapter as well for the config files. By default spring looks up a handler adapter. If one is already available and you need a second, you have to configure one yourself. In our case we add the simple controller handler adapter.</p>
<p>The new namespace configuration also adds a SimpleUrlHandlermapping. We need to add our mapping for the config.properties file. Therefore we cannot use the default mapping. The default mapping routes all requests to the MessageBroker. Check the following code for the additional configuration as I would have liked it. To bad this is not possible. On the other hand, Jeremy Grelle gives a good explanation why this cannot be done this way in <a href="http://forum.springframework.org/showthread.php?t=68607">this forum thread</a>.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;flex:message-broker&gt;
        &lt;flex:mapping pattern=&quot;/config.properties=configPropertyController&quot;/&gt;
        &lt;flex:mapping pattern=&quot;/*=_messageBroker&quot;/&gt;
    &lt;/flex:message-broker&gt;
</pre>
<p>This code block shows how it really must be. Which is good as well.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;flex:message-broker&gt;
        &lt;flex:secured /&gt;
    &lt;/flex:message-broker&gt;

    &lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
        &lt;property name=&quot;order&quot; value=&quot;0&quot;/&gt;
        &lt;property name=&quot;mappings&quot;&gt;
            &lt;value&gt;
                /config.properties=configPropertyController
            &lt;/value&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</pre>
<h3>Remote services</h3>
<p>Methods of beans can be exposed at remote services. There is namespace support for this as well. Again the namespace provides a lot of default behavior. One of the things is the name of the service that comes from the references bean. I need to change this since the used name is already used. This can easily be done using the service-id property. There is another feature that I like. You can explicitly configure the methods to expose or the methods to prevent from being exposed. You can use the exclude-methods and the include-methods. I use this to prevent the internal use method from being exposed. The following code block shows the configuration.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;flex:remote-service service-id=&quot;remoteBookManager&quot; ref=&quot;bookManager&quot;
                         exclude-methods=&quot;internalUseStoreBook&quot;/&gt;
</pre>
<h2>Remote services configuration</h2>
<p>If your application is only using spring managed remote services you can remove the remoting configuration completely. Default channels are provided by the spring integration. We do have a problem with our current security implementation. This makes use of a non spring managed remote service for authentication. If we want to remove this we need to use the new spring security integration. That is the next step.</p>
<h2>Integrating spring security</h2>
<p>The new M2 milestone comes with spring security integration. To be honest, there is not much use for me here. I did add it because there must be some exception handling and mapping being done. I still have some questions on this area that I will try to get answered the coming weeks. So stay tuned for an improved security version as well.</p>
<h2>Summary</h2>
<p>The following two code blocks show the old config file and the new style. I just love these more clean configuration files that make use of namespaces. To bad I have to provide my own SimpleUrlMappingHandler, but as mentioned it is probably better to make the separation.</p>
<p><strong>old</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot;
       xsi:schemaLocation=&quot;
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;

    &lt;!-- Bootstraps and exposes the BlazeDS MessageBroker --&gt;
    &lt;bean id=&quot;mySpringManagedMessageBroker&quot; class=&quot;org.springframework.flex.messaging.MessageBrokerFactoryBean&quot;/&gt;

    &lt;!-- Maps request paths at /* to the BlazeDS MessageBroker --&gt;
    &lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
        &lt;property name=&quot;mappings&quot;&gt;
            &lt;value&gt;
                /config.properties=configPropertyController
                /*=mySpringManagedMessageBroker
            &lt;/value&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;!-- Dispatches requests mapped to a MessageBroker --&gt;
    &lt;bean class=&quot;org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter&quot;/&gt;

    &lt;!-- Dispatches request mapped to a Controller --&gt;
    &lt;bean class=&quot;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter&quot;/&gt;

    &lt;!-- remote proxies --&gt;
    &lt;bean id=&quot;remoteBookManager&quot; class=&quot;org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter&quot;&gt;
        &lt;property name=&quot;messageBroker&quot; ref=&quot;mySpringManagedMessageBroker&quot;/&gt;
        &lt;property name=&quot;service&quot; ref=&quot;bookManager&quot;/&gt;
    &lt;/bean&gt;

    &lt;!-- Controllers for property configuration files --&gt;
    &lt;bean id=&quot;configPropertyController&quot; class=&quot;nl.gridshore.samples.books.web.controller.ConfigPropertyController&quot;/&gt;

    &lt;!-- View resolver used connect the views returned by controllers to view implementation classes --&gt;
    &lt;bean id=&quot;defaultViewResolver&quot; class=&quot;org.springframework.web.servlet.view.ResourceBundleViewResolver&quot;&gt;
        &lt;property name=&quot;basename&quot; value=&quot;views&quot;/&gt;
        &lt;property name=&quot;order&quot; value=&quot;1&quot;/&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p><strong>new</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot;
       xsi:schemaLocation=&quot;
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;

    &lt;!-- Bootstraps and exposes the BlazeDS MessageBroker --&gt;
    &lt;flex:message-broker&gt;
        &lt;flex:secured /&gt;
    &lt;/flex:message-broker&gt;

    &lt;!-- remote proxies --&gt;
    &lt;flex:remote-service service-id=&quot;remoteBookManager&quot; ref=&quot;bookManager&quot;
                         exclude-methods=&quot;internalUseStoreBook&quot;/&gt;

    &lt;!-- Non default url handler mapping needed for the property file --&gt;
    &lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
        &lt;property name=&quot;order&quot; value=&quot;0&quot;/&gt;
        &lt;property name=&quot;mappings&quot;&gt;
            &lt;value&gt;
                /config.properties=configPropertyController
            &lt;/value&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;!-- Dispatches request mapped to a Controller --&gt;
    &lt;bean class=&quot;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter&quot;/&gt;

    &lt;!-- Controllers for property configuration files --&gt;
    &lt;bean id=&quot;configPropertyController&quot; class=&quot;nl.gridshore.samples.books.web.controller.ConfigPropertyController&quot;/&gt;

    &lt;!-- View resolver used connect the views returned by controllers to view implementation classes --&gt;
    &lt;bean id=&quot;defaultViewResolver&quot; class=&quot;org.springframework.web.servlet.view.ResourceBundleViewResolver&quot;&gt;
        &lt;property name=&quot;basename&quot; value=&quot;views&quot;/&gt;
        &lt;property name=&quot;order&quot; value=&quot;1&quot;/&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F03%2F08%2Fupgrading-to-spring-blazeds-integration-m2%2F&amp;title=Upgrading%20to%20Spring%20BlazeDS%20Integration%20M2&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/03/08/upgrading-to-spring-blazeds-integration-m2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Flex remoting without configuring the client</title>
		<link>http://www.gridshore.nl/2009/01/23/flex-remoting-without-configuring-the-client/</link>
		<comments>http://www.gridshore.nl/2009/01/23/flex-remoting-without-configuring-the-client/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 17:36:57 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=633</guid>
		<description><![CDATA[<p>For a while I am experimenting with flex. I wrote quite some posts about flex and security and I started writing about the Springframework BlazeDS Integration project. One thing that I do not really like about the configuration is the way to configure the remoting. All the hassle with the service-config.xml that needs to [...]]]></description>
			<content:encoded><![CDATA[<p>For a while I am experimenting with flex. I wrote quite some posts about flex and security and I started writing about the <a href="http://www.springsource.org/spring-flex">Springframework BlazeDS Integration project</a>. One thing that I do not really like about the configuration is the way to configure the remoting. All the hassle with the service-config.xml that needs to be available on the client as well as on the server. Not really nice. Using the maven way of creating a jar with these config files and unzipping this jar into the web server project as well as the client flex project is a way. Still, not ideal when developing in your ide when you want to add a new remote service.</p>
<p>What is the arternative? On the serverside, the mentioned spring project is doing a good job. You do not have to configure all endpoints. But you still need something on the client.</p>
<p>This post talks about a mechanism to enable you to loose all this configuration on the client</p>
<p><span id="more-633"></span><br />
<h2>An overview</h2>
<p>So what am I planning to do. Using the <code>Properties</code> object from the Spring-ActionScript project I will load a property file from the server. This property file will contain the parameters required by the remote objects to connect to an endpoint. The property files will not be on the server, the request will be captured by the Dispatcher servlet from spring. Special controller classes will create the properties requested by the client and a view class creates a stream to the client. That way the client does not know the requested file is actually a dynamic resource.</p>
<p>Does that sound complicated? Well, read on and I&#8217;ll explain it step by step.</p>
<h2>The server side</h2>
<p>As mentioned in the introduction, we use the special spring BlazeDS integration project on the server. I am not going to discuss the configuration anymore. Read my previous post <a href="http://www.gridshore.nl/2009/01/05/wow-springframework-enters-the-actionscript-and-flex-domain/">Wow springframework enters the actionscript and flex domain</a> to learn how to do that. For this post I&#8217;ll focus on the differences.</p>
<p>So what do we need? We need the server to respond to the url:</p>
<p><code>http://localhost:8080/books-web/config.properties</code></p>
<p>with the result:</p>
<pre>
host=localhost
port=8080
context-root=books-web
</pre>
<p>And of course the result should be different when running on another server.</p>
<h3>web.xml</h3>
<p>We add a servlet mapping for a *.properties</p>
<pre class="brush: xml; title: ; notranslate">
&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.properties&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<h3>spring-web.xml</h3>
<p>We need to add a url mapping, and we have to add a mapping for the <code>config.properties</code> request. Now the simple url mapping looks like this.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
    &lt;property name=&quot;mappings&quot;&gt;
        &lt;value&gt;
            /config.properties=configPropertyController
            /*=mySpringManagedMessageBroker
        &lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</pre>
<p>Next step is to configure the controller and a default view resolver. The view resolver uses a resource bundle to connect the views and the classes that generate content.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean id=&quot;configPropertyController&quot; class=&quot;nl.gridshore.samples.books.web.controller.ConfigPropertyController&quot;/&gt;
&lt;bean id=&quot;defaultViewResolver&quot; class=&quot;org.springframework.web.servlet.view.ResourceBundleViewResolver&quot;&gt;
    &lt;property name=&quot;basename&quot; value=&quot;views&quot;/&gt;
    &lt;property name=&quot;order&quot; value=&quot;1&quot;/&gt;
&lt;/bean&gt;
</pre>
<p>The last thing to mention for the spring configuration took me a moment to figure out. Usually when creating a spring application, by default a <code>HandlerAdapter</code> is registered. Since the BlazeDS integration registers it&#8217;s own HandlerAdapter, the <code>MessageBrokerHandlerAdapter</code>, we need to register an additional HandlerAdapter to take care of our controller. That is why I added the following line to the spring config.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean class=&quot;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter&quot;/&gt;
</pre>
<h3>PropertyController</h3>
<p>The classes I added are pretty straightforward. I created a super class called <code>PropertyController</code>. This class implements the <code>Controller</code> interface. It is an abstract class that calls the method to create a <code>Map&lt;String,String></code>. This map is stored in the model and we move on to the view with a name <em>propertiesView</em>.</p>
<pre class="brush: java; title: ; notranslate">
public abstract class PropertyController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map&lt;String, String&gt; exposedParams = createExposedParamsMap(request);
        return new ModelAndView(&quot;propertiesView&quot;, &quot;exposedParams&quot;, exposedParams);
    }

    abstract protected Map&lt;String, String&gt; createExposedParamsMap(HttpServletRequest request);
}
</pre>
<h3>ConfigPropertyController</h3>
<p>For our case, we mapped the config.properties to the class <code>ConfigPropertyController</code>. The implementation makes use of the provided <code>HttpServletRequest</code> to read information about the server.</p>
<pre class="brush: java; title: ; notranslate">
public class ConfigPropertyController extends PropertyController {
    protected Map&lt;String, String&gt; createExposedParamsMap(HttpServletRequest request) {
        Map&lt;String, String&gt; exposedParams = new HashMap&lt;String, String&gt;();
        exposedParams.put(&quot;host&quot;, request.getServerName());
        exposedParams.put(&quot;port&quot;, String.valueOf(request.getServerPort()));

        // The context root path contains a prefix '/', we have to take that of.
        String contextRoot = request.getContextPath();
        contextRoot = contextRoot.substring(1);
        exposedParams.put(&quot;context-root&quot;, contextRoot);

        return exposedParams;
    }
}
</pre>
<p>The last piece of the puzzle is the <code>PropertyView</code> class. This class writes out the file to the client with one of the provided properties per line. Exactly like you&#8217;d expect a property file to be.</p>
<pre class="brush: java; title: ; notranslate">
public class PropertyView extends AbstractView {
    public PropertyView() {
        setContentType(&quot;text/plain&quot;);
    }

    protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map&lt;String,String&gt; exposedParams = (Map&lt;String,String&gt;)model.get(&quot;exposedParams&quot;);

        Set&lt;Map.Entry&lt;String,String&gt;&gt; entries = exposedParams.entrySet();

        response.setContentType(getContentType());
        for(Map.Entry&lt;String,String&gt; entry : entries) {
            StringBuilder lineBuilder = new StringBuilder();
            lineBuilder.append(entry.getKey());
            lineBuilder.append(&quot;=&quot;);
            lineBuilder.append(entry.getValue());
            response.getWriter().println(lineBuilder.toString());
        }
    }
}
</pre>
<p>Now you can start up the server and test the implementation. Than we continue with the flex client</p>
<h2>The Client</h2>
<p>On the client side I use Mate, I do not think this changes the implementation of this strategy a lot. Another thing you&#8217;ll need is a copy of the spring-ActionScript project. Sorry no maven yet. Get a copy from the site and build it.</p>
<p><a href="http://forum.springsource.org/showthread.php?t=66193">http://forum.springsource.org/showthread.php?t=66193</a></p>
<p>You&#8217;ll need this library for easy access to a nice way of loading property files from the server. The next block of code shows some functions that reside in you main flex application file.</p>
<pre class="brush: jscript; title: ; notranslate">
[Bindable]
public var properties:Config = new Config();
private var loadedProps:Properties = new Properties();

public function initApp():void {
    loadedProps.addEventListener(Event.COMPLETE, onLoaderComplete);
    loadedProps.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    loadedProps.load(&quot;config.properties&quot;);
}

private function onLoaderComplete(event:Event):void {
    properties.host = loadedProps.getProperty(&quot;host&quot;);
    properties.port = loadedProps.getProperty(&quot;port&quot;);
    properties.webcontext = loadedProps.getProperty(&quot;context-root&quot;);
}
</pre>
<p>First we initiate a load of the file we used in the server side part called config.properties. Responding to the complete event, we set the properties of the <code>Config</code> object using the loaded properties from the server. Next up we initiate the Mate event maps. Notice that we add the properties object to this map under the property props.</p>
<p><code>&lt;map:MainEventMap props="{properties}"/></code></p>
<p>In the EventMap we have to add the property called <strong>props</strong> of type Config. Using this object we can configure the remote obejcts like this.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;mx:RemoteObject id=&quot;booksService&quot;
                     endpoint=&quot;http://{props.host}:{props.port}/{props.webcontext}/messagebroker/amf&quot;
                     destination=&quot;remoteBookManager&quot;/&gt;
</pre>
<p>That is about it, now the client knows how to obtain the server config data and with this information it can access the endpoints.</p>
<p>If you want to have a look at the code or try it yourself, have a look at the following project in google code.</p>
<p><a href="http://code.google.com/p/gridshore/source/browse/#svn/trunk/books-overview">http://code.google.com/p/gridshore/source/browse/#svn/trunk/books-overview</a></p>
<p>Look for the books-flex-mate module to check the current progress of the new implementation. It is by far from finished. As of now you can only login using user/user and logout again.</p>
<p>Hope this can help you program your flex better, or at least have some inspiration to improve your (or mine) code. Comments are welcome</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F01%2F23%2Fflex-remoting-without-configuring-the-client%2F&amp;title=Flex%20remoting%20without%20configuring%20the%20client&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/01/23/flex-remoting-without-configuring-the-client/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

