<?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; Frontend Technology</title>
	<atom:link href="http://www.gridshore.nl/category/frontend-technology/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>Combining java and Node.js through redis pub/sub and a json remote interface</title>
		<link>http://www.gridshore.nl/2011/07/28/combining-java-and-node-js-through-redis-pubsub-and-a-json-remote-interface/</link>
		<comments>http://www.gridshore.nl/2011/07/28/combining-java-and-node-js-through-redis-pubsub-and-a-json-remote-interface/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 10:11:16 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[server technology]]></category>
		<category><![CDATA[axonframework]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1163</guid>
		<description><![CDATA[<p>Recently I have been doing a lot with Node.js. It is a nice server technology that enables you to program on the server like you program on the client. Wouldn&#8217;t it be nice to create a java based business logic backend but a light weight client and server backend. Communication between node.js and java [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been doing a lot with Node.js. It is a nice server technology that enables you to program on the server like you program on the client. Wouldn&#8217;t it be nice to create a java based business logic backend but a light weight client and server backend. Communication between node.js and java is done in two ways in the sample. We use http and json for querying the data and for providing new data. Next to that I have an event system that pushes events with new data to the clients using nowjs. The following image gives you an idea about the overall solution.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.gridshore.nl/wp-content/uploads/NodejsAxonRedisBlogpost.jpg" alt="Overview solution" border="0" width="551" height="323" /></p>
<p>If you want to find out more about this sample read on.</p>
<p><span id="more-1163"></span><br />
<h2>Introducing the sample</h2>
<p>The sample is based on the famous address book from the axonframework project. We reuse the axon sample and create a rest like interface that returns json to the clients. The source code is in the rest-ui project within the axonframework source tree under samples. This project also contains the listener code for the Contact and Address based events. The listeners listen for events and publish content from these events to the redis pub/sub mechanism. More on this in the later sections.</p>
<p>The other part of the sample is a node.js application. This application makes use of the rest api to obtain the data via http requests. Events about data changes are received through redis, using the pub/sub mechanism. The node.js application is available on Github. If you want to follow along, you can find the sources here:</p>
<p><a href="https://github.com/jettro/axon-addressbook-nodejs">https://github.com/jettro/axon-addressbook-nodejs</a><br/><br />
<a href="http://code.google.com/p/axonframework/source/browse/trunk#trunk%2Fsample%2Faddressbook%2Frest-ui">http://code.google.com/p/axonframework/source/browse/trunk#trunk%2Fsample%2Faddressbook%2Frest-ui</a></p>
<p>The following screen dump gives you an idea about the application.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.gridshore.nl/wp-content/uploads/Screen-Shot-2011-07-25-at-19.06.57.png" alt="Screen Shot 2011 07 25 at 19 06 57" border="0" width="600" height="470" /></p>
<p>In the screen you see the list of contacts. You can add a new contact, change the name of a contact and add addresses to contacts. On the right you see the messages pane. Here you receive messages about new contacts that have been created, changed or deleted.</p>
<p>Now let us have a look at some of the code. We start with the java backend and then continue with the node.js part.</p>
<h2>The java part of the sample</h2>
<p>Numerous blogs have been written about rest based clients using spring mvc. Therefore I do not want to lose to much time in that area. Most important spring configuration is within the web.xml and the <a href="http://code.google.com/p/axonframework/source/browse/trunk/sample/addressbook/rest-ui/src/main/webapp/WEB-INF/spring/dispatcher-config.xml">dispatcher-config.xml</a>. In the web.xml we configure that every request is going to the spring dispatcher. We do not have status resources, only json responses. Within spring we make use of annotation to configure the beans. To be able to respond with json we make us of Jackson to transform beans into json objects. All pretty straightforward spring. Check the config file for yourself if you want to see how it works.</p>
<p>Next step is the controller that handles all the requests.</p>
<h3>Handling requests in the Cntroller</h3>
<p>The Controller handles the following requests:</p>
<ul>
<li>/contacts : GET, returns the list of all contacts</li>
<li>/contacts : POST, creates a new contact</li>
<li>/contacts : PUT, changes an existing contact</li>
<li>/contacts : DELETE, removes a contact</li>
<li>/contacts/{identifier} : GET, returns the details of a contact</li>
<li>/contacts/{identifier}/address : PUT, creates a new address or updates an existing one based on address type</li>
<li>/contacts/{identifier}/address : DELETE, removes the address of provided type</li>
</ul>
<p>Let us have a look at one of the requests to show the flow. For example we take the request for details. The following code block shows the complete method.</p>
<pre class="brush: java; title: ; notranslate">
@RequestMapping(value = &quot;{identifier}&quot;, method = RequestMethod.GET)
public @ResponseBody Map&lt;String, Object&gt; details(@PathVariable String identifier) {
    List&lt;AddressEntry&gt; addressesForContact = repository.findAllAddressesForContact(identifier);
    String name;
    if (addressesForContact.size() &gt; 0) {
        name = addressesForContact.get(0).getName();
    } else {
        name = repository.loadContactDetails(identifier).getName();
    }
    Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
    map.put(&quot;addresses&quot;, addressesForContact);
    map.put(&quot;identifier&quot;, identifier);
    map.put(&quot;name&quot;, name);
    return map;
}
</pre>
<p>The RequestMapping annotation tells spring which requests need to be mapped to this method. The controller already maps all /contacts to this controller. The {identifier} now maps everything with a url like /contacts/{identifier} to this method, as long as it is a GET request. This identifier is also used as a parameter for the method. With the @PathVariable we tell spring to take the value for this parameter from the url or Path that was requested. The final annotation in the method declaration is the @ResponseBody. This tells spring to use the return value as the response body, so not as the name of the view to use. We have already configured to use jackson to transform the response body into json. In the code of the controller you see we return a map with three objects in it. A list of addresses, an identifier of the contact and the name of the contact. The json coming out of this is:</p>
<p>{<br />
    &quot;name&quot;:&quot;Jettro&quot;,<br />
    &quot;addresses&quot;:[<br />
    {<br />
        &quot;name&quot;:&quot;Jettro&quot;,<br />
        &quot;identifier&quot;:&quot;82b4fef5-3389-440d-8893-6831a64e200d&quot;,<br />
        &quot;addressType&quot;:&quot;PRIVATE&quot;,<br />
        &quot;streetAndNumber&quot;:&quot;Feyenoordlaan 010&quot;,<br />
        &quot;zipCode&quot;:&quot;3000AA&quot;,<br />
        &quot;city&quot;:&quot;Rotterdam&quot;<br />
    }],<br />
    &quot;identifier&quot;:&quot;82b4fef5-3389-440d-8893-6831a64e200d&quot;<br />
}</p>
<p>That is what you need to know about the rest api that I have created. If you want to have a look at the controller, <a href="http://code.google.com/p/axonframework/source/browse/trunk/sample/addressbook/rest-ui/src/main/java/org/axonframework/examples/addressbook/rest/ContactsController.java">check here</a>. The next step is about the listeners that listen for axon events related to the contacts and addresses and store information in redis.</p>
<h3>Listening for events</h3>
<p>We register listeners with axon for the contact related events as well as address related events. This is very easy with the annotations provided by the axonframework. The following code block shows how we register an event listener for the ContactCreatedEvent.</p>
<pre class="brush: java; title: ; notranslate">
@EventHandler
public void handleContactCreatedEvent(ContactCreatedEvent event) {
    ContactEntry value = new ContactEntry();
    value.setName(event.getName());
    value.setIdentifier(event.getContactIdentifier());
    Message&lt;ContactEntry&gt; message = new Message&lt;ContactEntry&gt;(&quot;contact-created&quot;, value);
    publisher.publish(message);
}
</pre>
<p>Notice the @EventHandler annotation. This registers the listener with axon. As you can see we take the information from the provided event and put it in a Message object. The message object contains a type and the content. The type can be used at the receiving side to better understand how to handle the received event. The publisher is auto injected by spring. In my case it is a redis publisher.</p>
<h3>Publishing to redis</h3>
<p>A library to talk with redis is <a href="https://github.com/xetorthio/jedis">jedis</a>. Jedis makes use of a pool which is configured in spring. Check the listener-context.xml to see how it works. Jedis does not have the most obvious api but it works. The following code block shows how a message is published to redis.</p>
<pre class="brush: java; title: ; notranslate">
public void publish(Message&lt;?&gt; message) {
    StringWriter writer = new StringWriter();
    try {
        mapper.writeValue(writer, message);
    } catch (IOException e) {
        logger.warn(&quot;Problem while writing ContactEntry to a string writer&quot;, e);
        return;
    }

    Jedis jedis;
    try {
        jedis = jedisPool.getResource();
    } catch (JedisConnectionException e) {
        logger.debug(&quot;Could not obtain redis connection from the pool&quot;);
        return;
    }
    try {
        jedis.publish(&quot;nl.axonframework.examples.addressbook&quot;, writer.toString());
    } finally {
        jedisPool.returnResource(jedis);
    }
}
</pre>
<p>The code is not very complicated. The important part here is that we use a jackson provided ObjectMapper to map the provided message to a json representation. Then you can see the nice jedis api at work. As you can see we publish a message to a queue. Our node.js client will subscribe to this queue. That is have the redis publish/subscribe works. Not very hard is it?</p>
<p>That is it for the java side. We now know how to get data using the rest api and we know where to get information about events that take place. Let us move on to the node.js side of the application.</p>
<h2>The Node.js part of the sample</h2>
<p>I do not want to go in setting up a node.js project. Do not want to explain all the different libraries that I use. I have written other blog posts on node.js that I do not want to copy. The most important one is this:</p>
<p><a href="http://blog.jteam.nl/2011/04/18/learning-node-js/">http://blog.jteam.nl/2011/04/18/learning-node-js/</a></p>
<p>The node.js project uses 4 libraries:</p>
<ul>
<li>express &#8211; doing the mvc part of the web application</li>
<li>jade &#8211; view templating</li>
<li>now &#8211; server push to the client (will explain this in a bit more detail)</li>
<li>redis &#8211; for redis interaction</li>
<p> </ul>
<h3>Project layout</h3>
<p>The public folder contains all the client related files like javascript, css and images. I will explain one file in here later on when discussing node.js. The test folder contains the test for the ContactRepository. Using this test helped me to verify that the integration between the java backend and the node.js application is working without having to start the application and go through the browser to check all requests. The views folder contains all the jade templates. Check mentioned blog post to find more information on jade. The app.&#8217;s initializes the application and maps all possible requests to methods in the ContactController. The controller knows where to get the data from and what page to render. The repository is responsible for obtaining data from the rest api on the java side.</p>
<h3>Initializing the node.js application</h3>
<p>As mentioned the app.js is the start of the application. Let us have a look at the different parts.</p>
<pre class="brush: jscript; title: ; notranslate">
var ContactController = require('./ContactController');
var repository = require('./ContactRepository').createRepo('localhost',8080);
var contactController = new ContactController(repository);
</pre>
<p>This part initializes our components. We will have a look at the createRepo method later on. But notice that we initialize the controller with an instance of the repository.</p>
<pre class="brush: jscript; title: ; notranslate">
app.get('/', contactController.listContacts);
app.get('/contact/new', contactController.newContactShowForm);
app.post('/contact/new', contactController.newContactPostForm);
app.get('/contact/:identifier',contactController.contact);
app.get('/contact/:identifier/edit',contactController.changeContactShowForm);
app.post('/contact/:identifier/edit',contactController.changeContactPostForm);
app.get('/contact/:identifier/delete',contactController.deleteContactShowForm);
app.post('/contact/:identifier/delete',contactController.deleteContactPostForm);
app.get('/contact/:identifier/address/new',contactController.newAddressShowForm);
app.post('/contact/:identifier/address/new',contactController.newAddressPostForm);
app.get('/contact/:identifier/address/:addressType/edit',contactController.changeAddressShowForm);
app.post('/contact/:identifier/address/:addressType/edit',contactController.changeAddressPostForm);
app.get('/contact/:identifier/address/:addressType/delete',contactController.deleteAddressShowForm);
app.post('/contact/:identifier/address/:addressType/delete',contactController.deleteAddressPostForm);
</pre>
<p>These are all the possible requests. The urls are easy to understand. As you can see, all urls are mapped to a method of the contactController</p>
<pre class="brush: jscript; title: ; notranslate">
var Now = require('now');
var everyone = Now.initialize(app);

var redis = require(&quot;redis&quot;),
    client = redis.createClient();

client.on(&quot;error&quot;, function (err) {
    console.log(&quot;Error %s&quot;, err);
});

client.on(&quot;message&quot;, function (channel, message) {
    everyone.now.receiveContact(message);
});
client.subscribe(&quot;nl.axonframework.examples.addressbook&quot;);
</pre>
<p>This is the harder bit. This has to do with receiving messages using the redis pub/sub mechanism and sending it to all connected clients using the nowjs library. I&#8217;ll discuss the now.js part later on.</p>
<h3>Request handling</h3>
<p>By using the repository object the controller becomes very easy. We only have to obtain the right data and render the right view. The most basic method is showing a list of contacts. The following code block shows the complete method.</p>
<pre class="brush: jscript; title: ; notranslate">
ContactController.prototype.listContacts = function(req, res) {
    repository.listContacts(function(contacts) {
        res.render('index', {locals: {contacts: contacts, nowjs: true}});
    });
};
</pre>
<p>Notice that we use a callback that is provided to the repository listContact method. Check that we provide the list of contacts to the view, together with a second parameter called nowjs. Remember this, on this page we enable nowjs, meaning that we can receive messages when looking at this page. Other methods are similar, have a look at the method that handles submitting a form to create a new contact.</p>
<pre class="brush: jscript; title: ; notranslate">
ContactController.prototype.newContactPostForm = function(req, res) {
    repository.newContact(req.body.new_name, function(code, message) {
        if (code == &quot;ok&quot;) {
            res.redirect(&quot;/&quot;);
        } else {
            res.render('newcontact', {locals: {error:message}});
        }
    });
};
</pre>
<p>In line 2 we obtain the form parameter <em>new_name</em> from the request body. Than we create a new contact. The callback method expects a code indicating whether the submission of the new contact was ok. If not, we render the form again with the error message. This happens when we try to create a contact with a name that already exists. The following image shows the screen with an error message.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.gridshore.nl/wp-content/uploads/Screen-Shot-2011-07-28-at-10.07.30.png" alt="Screen showing the error message" border="0" width="600" height="459" /></p>
<p>Next up is the communication with a rest based application</p>
<h3>The Repository as a client to a rest application</h3>
<p>During the initialization of the application I already mentioned the createRepo method of the ContactRepository. The following code block shows the method. As you can see it initializes a repository with the default values for host and port.</p>
<pre class="brush: jscript; title: ; notranslate">
ContactRepository.createRepo = function(host, port) {
    var repo = new ContactRepository();
    repo.host = host;
    repo.port = port;
    return repo;
};
</pre>
<p>Again most of the interaction with the backend is the same. Therefore I use the create contact again as an example. I have created tests for all the repository methods. Let us have a look at the test first.</p>
<pre class="brush: jscript; title: ; notranslate">
function testNewContact() {
    logTestName(&quot;New contact&quot;);
    repository.newContact(&quot;My Test&quot;, function(code, message) {
        assert.equal(&quot;ok&quot;, code, &quot;This should be no problem and an ok should be returned: &quot; + code);
        // Check if the amount of contacts is increased
        repository.listContacts(function(contacts) {
            assert.equal(numContacts + 1, contacts.length, &quot;Number of contacts is not right, create did not work: &quot; + contacts.length);
            testAddAddress();
        });
    });
}
</pre>
<p>Notice that we check the return code and that the amount of contacts is increased. The following code block shows the implementation of the method of the repository.</p>
<pre class="brush: jscript; title: ; notranslate">
ContactRepository.prototype.newContact = function(name, callback) {
    var opts = createHttpRequestOpts('/contacts', 'POST');

    var req = http.request(opts, function(res) {
        res.setEncoding('utf8');
        res.on('data', function(data) {
            if (res.statusCode != 200) {
                console.log(data);
                callback('error', 'Maybe the name is already taken?');
            } else {
                callback('ok', 'The new contact has been send')
            }
        });
    });

    var contact = {};
    contact.name = name;

    req.write(JSON.stringify(contact));
    req.end();
};

function createHttpRequestOpts(path, method) {
    return {
        host: host,
        port: port,
        path:path,
        headers:{'Accept':'application/json','Content-Type':'application/json'},
        method: method
    };
}
</pre>
<p>I use the nodejs provided http request. Within the help function the opts object is created with the host, port, path, method and the headers. The headers are important to request json. Of course we provide a callback to handle the http response. Everything not 200 is an error as a response code. Here we call the provided callback to the repository method with the ok or error code. At the end of the method we do the actual request creation with the json request.</p>
<p>The final bit is the server push using the now.js library.</p>
<h3>Server push using now.js</h3>
<p>Node.js comes with a socket.io library. This makes server push very easy. Still it can be a lot easier. That is when using <a href="http://nowjs.com/">now.js</a>. Now.js enables you to call methods on the client that are actually on the server and vise versa. Let us have a look at the code for sending messages to the client when a redis event is received again.</p>
<pre class="brush: jscript; title: ; notranslate">
var Now = require('now');
var everyone = Now.initialize(app);
client.on(&quot;message&quot;, function (channel, message) {
    console.log(&quot;Received message: %s&quot;, message);
    everyone.now.receiveContact(message);
});
</pre>
<p>The important part here is the initialization of now and the line with everyone.now.receiveContact. Now we will call the connected clients method receiveContact and provide the message. Of course we need some client code for this. This code is available in the local.js file in the public folder.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
    now.receiveContact = function(data) {
        var message = JSON.parse(data);
        var toWrite;
        switch(message.type) {
            case 'contact-removed':
                toWrite = &quot;Contact removed&quot;;
                break;
            case 'contact-created':
                toWrite = &quot;Contact with name &quot; + message.content.name + &quot; created&quot;;
                break;
            case 'contact-changed':
                toWrite = &quot;Contact changed name to &quot; + message.content.name;
                break;
            case 'address-created':
                toWrite = &quot;Added address of type &quot; + message.content.addressType + &quot; to contact &quot; + message.content.name;
                break;
            case 'address-removed':
                toWrite = &quot;Removed address of type &quot; + message.content.addressType + &quot; to contact &quot; + message.content.contact.name;
                break;
        }
        $(&quot;#messages&quot;).prepend(&quot;&lt;div&gt;&quot; + toWrite + &quot; &lt;/div&gt;&quot;);
    };
});
</pre>
<p>As you can see, we construct the message based on the type of the message and prepend a new div within the #messages div. Really that is all there is to it.</p>
<h2>Last remarks</h2>
<p>That is it. Again a long blog item. Hope you got some new knowledge out of it. Feel free to post comments if you have questions or even better improvements.</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%2F2011%2F07%2F28%2Fcombining-java-and-node-js-through-redis-pubsub-and-a-json-remote-interface%2F&amp;title=Combining%20java%20and%20Node.js%20through%20redis%20pub%2Fsub%20and%20a%20json%20remote%20interface&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/2011/07/28/combining-java-and-node-js-through-redis-pubsub-and-a-json-remote-interface/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Installing Node.js on my new Synology</title>
		<link>http://www.gridshore.nl/2011/04/04/installing-node-js-on-my-new-synology/</link>
		<comments>http://www.gridshore.nl/2011/04/04/installing-node-js-on-my-new-synology/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 16:48:35 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[server technology]]></category>
		<category><![CDATA[ds211+]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[synology]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1149</guid>
		<description><![CDATA[<p>About a week a go I bought myself a Synology. A very nice product with reasonable value for money. Especially if you consider the options you have if you are not scared to get your hands dirty. Agreed the graphical admin console is nice, but the linux options are even nicer. I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>About a week a go I bought myself a <a href="http://www.synology.com/">Synology</a>. A very nice product with reasonable value for money. Especially if you consider the options you have if you are not scared to get your hands dirty. Agreed the graphical admin console is nice, but the linux options are even nicer. I wanted to have a cheap solution to host a node.js server at home. In the end I am glad I made the choice for this model.</p>
<p>In this blog post I will provided as much steps that I can remember and or wrote down while installing a node.js server on my Synology. This was not the easiest thing I have ever done. If I can help some others that want to get more out of their Synology my hours of work are worth it.</p>
<p><span id="more-1149"></span><br />
<h2>Terminal access</h2>
<p>The Synology comes with an installed firmware. In my case I started with the 3.1 DSM software.</p>
<p>Tweaking you Synology starts with obtaining Terminal access. You can enable this in the configuration panel of DSM. By default you can access your synology using DiskStation.local with the admin or root account. For the things we are going to do I recommend using the root account. The password for the root account is the same as for the admin account. Just so you know. Go on check if you have access</p>
<pre>
# ssh root@DiskStation.local
</pre>
<h2>ipkg</h2>
<p>The next step is to install ipkg, the package manager for you synology. There are multiple resources on the web that explain how to do this. Most of them point to <a href="http://forum.synology.com/wiki/index.php/Overview_on_modifying_the_Synology_Server,_bootstrap,_ipkg_etc#How_to_install_ipkg">this wiki page</a>. It is important to take the right version of the bootstrap for your synology system. The variations in processors used are big, therefore you have to use the right software. The processor can be obtained using <a href="http://forum.synology.com/wiki/index.php/What_kind_of_CPU_does_my_NAS_have">this page</a>. You can also find out more about your system from the command line.</p>
<pre>
DiskStation> uname -a
Linux DiskStation 2.6.32.12 #1605 Thu Mar 24 02:12:03 CST 2011 armv5tel GNU/Linux
</pre>
<p>For the DS211+ I needed the <em>Marvel Kirkwood mv6282 ARM</em>. The easiest way to get in onto your system is to use wget. Remember that tool, we will talk more about it.</p>
<pre>
<a href="http://wizjos.endofinternet.net/synology/archief/syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh">wget http://wizjos.endofinternet.net/synology/archief/syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh</a>
</pre>
<p>I created a downloads folder in the home folder of root. Executing the script is very easy</p>
<pre>
sh syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh
</pre>
<p>Now we have ipkg installed. The best way to check if it works is to update and upgrade.</p>
<pre>
DiskStation> ipkg update
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/Packages.gz
Inflating http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/Packages.gz
Updated list of available packages in /opt/lib/ipkg/lists/cross
Successfully terminated.
DiskStation> ipkg upgrade
Nothing to be done
Successfully terminated.
</pre>
<p>If you just want to install software that is available via ipkg, this is it. In my case I want to install node.js. This is not available via ipkg, therefore we need to compile it ourselves. This is where the problem starts. So in the next section we will have a look what you need to compile stuff.</p>
<h2>Compile from source</h2>
<p>Compiling source code on linus needs compilers (gcc) and headers files. The header files contain information about the libraries that are required during compilation of code that makes use of these libraries. Ipkg has the option to install development libraries that are required to compile source. To bad the current version does not work out of the box. With the help of some resources on the web and a lot of experimentation I finally got a working system. This part is the most important part of getting your system ready to compile node.js.</p>
<p>Usually you would install optware-devel with ipkg. But we start off with some other libraries that will not work with optware-devel.</p>
<pre>
ipkg remove wget
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/wget-ssl_1.12-2_arm.ipk
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/openssl_0.9.8p-1_arm.ipk
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/libidn_1.19-1_arm.ipk
ipkg install libidn_1.19-1_arm.ipk
ipkg install openssl_0.9.8p-1_arm.ipk
ipkg install wget-ssl_1.12-2_arm.ipk
ipkg install openssl-dev
</pre>
<p>We are almost set, now I have a problem with my limited linux knowledge. I found some resources on the web and in the end I had to copy some resources around. So these steps might not be optimal, but they did work for me.</p>
<p>I took the first step from <a href="http://forum.synology.com/enu/viewtopic.php?f=90&#038;t=30132&#038;p=119287&#038;hilit=pthread#p120183">this post</a>.</p>
<pre>
mkdir /opt/arm-none-linux-gnueabi/lib_disabled
mv /opt/arm-none-linux-gnueabi/lib/libpthread* /opt/arm-none-linux-gnueabi/lib_disabled
cp /lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/
cd /opt/arm-none-linux-gnueabi/lib/
ln -s libpthread.so.0 libpthread.so
ln -s libpthread.so.0 libpthread-2.5.so
</pre>
<p>The final copying you need to do actually only appeared to me when running node.js. Therefore I am not completely sure if this is right, but again it works for me.</p>
<pre>
cp /opt/lib/libssl.so.0.9.8 /usr/lib
cp /opt/lib/libcrypto.so.0.9.8 /usr/lib
</pre>
<p>If I remember correct, now is the time to start downloading node.js and start compiling.</p>
<h2>Compiling node.js</h2>
<p>Before we start compiling we need to have some source. This page describes what you need to do:</p>
<p><a href="https://github.com/joyent/node/wiki/Installation">https://github.com/joyent/node/wiki/Installation</a></p>
<p>I downloaded node in the /root folder, called ./configure and put the results in /opt/node. Before you can do that you need to install git first. This is easily done using ipkg. Now the steps to perform:</p>
<pre>
ipkg install git
cd /root
git clone https://github.com/joyent/node.git
cd node
./configure --prefix=/opt/node
make
make install
</pre>
<p>Hope it all goes as aspected and no errors arise. Beware the make step can take a long time (15-30 minutes or something). The next step is to add node.js to your path. In the root folder you can find the .profile file. In here you will find a PATH variable. Change it to include the folder /opt/node/bin. Something like this</p>
<pre>
PATH="/opt/node/bin:$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/syno/bin:/usr/syno/sbin:/usr/local/bin:/usr/local/sbin"
</pre>
<p>That is the end of the journey. Now you can do your node things like install npm, express, jade, sass, socket.io, etc. If you have an application running you can execute it from the shell. The problem is that it does not keep running when you logout. There are multiple mechanisms to keep the process running. I found one that is actually itself a node.js application. It seems to do the trick for me.</p>
<p><a href="https://github.com/indexzero/forever">https://github.com/indexzero/forever</a></p>
<p>That is it, node.js running on your synology. if you want more information about what I am running on my synology, check the sources on Github or check my previous blog post.</p>
<p><a href="http://www.gridshore.nl/2011/03/16/first-steps-with-node-js/">http://www.gridshore.nl/2011/03/16/first-steps-with-node-js/</a><br/><br />
<a href="https://github.com/jettro/nodejstryout">https://github.com/jettro/nodejstryout</a></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%2F2011%2F04%2F04%2Finstalling-node-js-on-my-new-synology%2F&amp;title=Installing%20Node.js%20on%20my%20new%20Synology&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/2011/04/04/installing-node-js-on-my-new-synology/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>First steps with Node.js</title>
		<link>http://www.gridshore.nl/2011/03/16/first-steps-with-node-js/</link>
		<comments>http://www.gridshore.nl/2011/03/16/first-steps-with-node-js/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 20:53:42 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[server technology]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[jade]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[sass]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1147</guid>
		<description><![CDATA[<p>With a colleague I was talking about Node.js. My first though, &#8220;yeah right, JavaScript on the server!&#8221;. But you have to be open minded if you want to learn new stuff. Therefore I thought about giving it a spin. I started looking for resources on the web, read a few of them and ended [...]]]></description>
			<content:encoded><![CDATA[<p>With a colleague I was talking about Node.js. My first though, &#8220;yeah right, JavaScript on the server!&#8221;. But you have to be open minded if you want to learn new stuff. Therefore I thought about giving it a spin. I started looking for resources on the web, read a few of them and ended up at the article : <a href="http://howtonode.org/express-mongodb">express-mongo</a>. This article was the beginning of my Node.js journey.</p>
<p>In this blog item I want to show you the steps I took, the resources I found useful and some improvements to the article that seems a bit outdated. It is not an explanation of what Node.js is, but it does provide some help to get started on your own.</p>
<p><span id="more-1147"></span><br />
<h2>The source</h2>
<p>I took the sources from the article of Ciaran Jessup as my basis. So a lot of credits go to him. You can find my sources over at github:</p>
<p><a href="https://github.com/jettro/nodejstryout">https://github.com/jettro/nodejstryout</a></p>
<h2>Setting up my environment</h2>
<p>If you want to do something with nodejs, you have to install it first. I used MacPorts to install it, but lots of other ways are <a href="https://github.com/joyent/node/wiki/Installation">documented on the wiki</a>. Using MacPorts all you have to do is:</p>
<pre>
sudo port install nodejs
</pre>
<p>The next step is to install a package manager. The mentioned article uses kiwi, but the node.js documentation recommends npm. Therefore I chose to use npm as well. Installing npm is documented well on the website: <a href="https://github.com/isaacs/npm">https://github.com/isaacs/npm</a>. To be honest I am not sure anymore whether I installed using curl or using the download/make procedure. But in the end you should be able to install dependencies using npm. I just love the way npm is used to update modules. Not easy when using multiple projects that need different versions. But maybe there is a solution to that as well. For now, lets focus on installing some modules or dependencies. Everything needs to be done with sudo, just so you know. No worries, I&#8217;ll explain the different modules later on.</p>
<pre>
# sudo npm install express
# sudo npm install jade
# sudo npm install sass
</pre>
<p>Time to check if your environment works, try to execute the famous HelloWorld sample. But first issue the command: <strong>node &#8211;version</strong>. The following code block shows the sample as presented on the <a href="http://nodejs.org/">Node.js homepage</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, &quot;127.0.0.1&quot;);
console.log('Server running at http://127.0.0.1:8124/');
</pre>
<p>Now start the server with node using : <strong>node helloworld.sh</strong> and point your browser to http://127.0.0.1:8124/.</p>
<p>Now you have your http server running, nice stuff.</p>
<h2>The sample</h2>
<p>The sample is all about providing a blog. The structure of the sample is based on the original sample. We have a public folder, a views folder and the application js files are in the root. These folders are used later on in the express code. Express is a web modules for Node.js. You can find out more about the module here: <a href="http://expressjs.com/">http://expressjs.com/</a>. The next section explains a bit more about using expressjs.</p>
<p>The sample can be started using the app.js file by calling node app.js. We start by analyzing the app.js file.</p>
<pre class="brush: jscript; title: ; notranslate">
var express = require('express');
var pub = __dirname + '/public';
var app = express.createServer();
var ArticleProvider = require('./articleprovider-memory').ArticleProvider;
var articleProvider = new ArticleProvider();
// ... more express stuff, will be discussed later on
app.listen(3000);
console.log('Express server started on port %s', app.address().port);
</pre>
<p>First we obtain the express modules, then we define a folder called pub that points to the public folder as mentioned before. In line 3 we create the express server and an ArticleProvider. The ArticleProvider is copied 1-on-1 from the article that was mentioned before. It is an in memory implementation for the datastore of the blog items. Check the sourcecode if you want to learn more about it. The final two lines are setting the port for the server to start, start the server and print a line to the console that the server has been started.</p>
<p>In the next section we will configure the express server.</p>
<h2>Express</h2>
<p>More information : <a href="http://expressjs.com/">http://expressjs.com/</a>.</p>
<p>The following code block is the remainder of the application. There are two parts in the code block. The first part is the configuration of the server, the second part configures the url handling. Within the server configuration we define the view engine (jade) and the folder where the views can be found. Another thing is the folder where the stylesheets in sass format are that need to be compiled. We also define the folder where the public files are using the <em>static</em> method. The last configuration is the bodyParser. This is required for handling the post. The second part about url handling is covered after the code.</p>
<pre class="brush: jscript; title: ; notranslate">
app.configure(function() {
    app.set('view engine', 'jade');
    app.set('views', __dirname + '/views');
    app.use(express.compiler({ src: pub, enable: ['sass'] }))
    app.use(express.methodOverride());
    app.use(express.static(pub));
    app.use(express.logger());
    app.use(express.bodyParser());
});

app.get('/', function(req, res) {
    articleProvider.findAll(function(error, docs) {
        res.render('blog', {locals: {docs: docs}});
    });
});

app.get('/blog/new', function (req, res) {
    res.render('blog_new', {locals: {title: 'New Blog Item'}});
});

app.post('/blog/new', function (req, res) {
    console.log('The provided title is : %s',req.body.new_title);
    articleProvider.save({title: req.body.new_title, body: req.body.new_body},
            function(error, docs) {
                res.redirect('/');
            });
});
</pre>
<p>Within the sourcecode you can identify three urls that are handled: /, /blog/new and a post to /blog/new. Notice that we use callbacks? This is what Node.js is all about, handling async callbacks. If you look at the app.get method for &#8216;/&#8217; you&#8217;ll see that we call the findAll method of the ArticleProvider. The result is used to render a view with the name <em>blog</em>. The part with locals is used to provide parameters to the view. In this case we provide the returned docs to the view. The next section will show you the very basics of jade, a template engine.</p>
<h2>Jade</h2>
<p>More information can be found here: <a href="https://github.com/visionmedia/jade">https://github.com/visionmedia/jade</a>.</p>
<p><cite>Jade is a high performance template engine heavily influenced by Haml and implemented with JavaScript for node.</cite></p>
<p>I am not going to give a lot of details about jade here. The following code block shows you the view with all the blog items.</p>
<pre class="brush: plain; title: ; notranslate">
h1 My blog
div
    a(href='/blog/new') New blog item
div#articles
    - each blog in docs
        div.article
            div.title #{blog.title}
            div.created_at #{blog.created_at}
            div.body #{blog.body}
</pre>
<p>As you can see, the code is very condensed. A good tool with code completion would be nice though. Still if you have some programming experience it should not be to hard to read. Check the mechanism for making a distinction between a class and an id. # is used to represent an idea and a &#8216;.&#8217; for a class. These both will be good to use in a stylesheet. Which is a nice bridge to the next section. This section is about sass that needs to be compiled in a stylesheet. The following code block shows the layout.jade file. This file contains the main template with the header of all pages. Check the way to define we use html 5.</p>
<pre class="brush: plain; title: ; notranslate">
!!! 5
html(lang=&quot;en&quot;)
  head
    title My Blog
    link(href=&quot;/style/style.css&quot;, media=&quot;screen&quot;, rel=&quot;stylesheet&quot;, type=&quot;text/css&quot;)
  body
    div!= body
</pre>
<h2>Sass</h2>
<p>More information can be found here: <a href="https://github.com/visionmedia/sass.js">https://github.com/visionmedia/sass.js</a>.</p>
<p>Is a condensed way of writing stylesheets. Before the stylesheets can actually be user they need to be compiled. This is done by express, check one of the earlier sections. The following codeblock shows the complete stylesheet. I guess it should not be to hard to follow if you have stylesheet experience.</p>
<pre class="brush: plain; title: ; notranslate">
body
  :font-family &quot;Helvetica Neue&quot;, &quot;Lucida Grande&quot;, &quot;Arial&quot;
  :font-size 13px
  :text-align center
  =text-stroke 1px rgba(255, 255, 255, 0.1)
  :color #555
h1, h2
  :margin 0
  :font-size 22px
  :color #343434
h1
  :text-shadow 1px 2px 2px #ddd
  :font-size 60px
#articles
  :text-align left
  :margin-left auto
  :margin-right auto
  :width 320px
  .article
    :margin 20px
    .created_at
      :display none
    .title
      :font-weight bold
      :text-decoration underline
      :background-color #eee
    .body
      :background-color #ffa
</pre>
<h2>Concluding</h2>
<p>There you have it, my first try on Node.js with extensive help of Ciaran Jessup. I do like Node.js., I love the speed of development. Would be nice to have some IDE support. I tried WebStorm, but it does not have Node.js support. It does help with the JavaScript coding. I will definitely continue playing around with Node.js. The next step is have a look at Rabbitmq.js. Finally I want to extend another sample of mine that makes use of the Axon framework with rabbitmq and Node.js for the front end. I also want to have a good look ar Socket.IO. So stay tuned for more blogs on this topic.</p>
<h2>Resources</h2>
<ul>
<li>https://github.com/jettro/nodejstryout</li>
<li>http://howtonode.org/express-mongodb</li>
<li>http://nodejs.org/</li>
<li>https://github.com/isaacs/npm</li>
<li>http://expressjs.com/guide.html</li>
<li>https://github.com/visionmedia/jade</li>
<li>https://github.com/visionmedia/sass.js</li>
<p> </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%2F2011%2F03%2F16%2Ffirst-steps-with-node-js%2F&amp;title=First%20steps%20with%20Node.js&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/2011/03/16/first-steps-with-node-js/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<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>Creating a sortable list of items using jQuery</title>
		<link>http://www.gridshore.nl/2009/09/14/creating-a-sortable-list-of-items-using-jquery/</link>
		<comments>http://www.gridshore.nl/2009/09/14/creating-a-sortable-list-of-items-using-jquery/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 23:01:01 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[sortable list]]></category>
		<category><![CDATA[spring 3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=896</guid>
		<description><![CDATA[<p>For a project that I am working on Your-Scrum I need a lot of items in a list that are sortable. One Story is to have a backlog with stories that are sortable to reflect the importance. Using Domain Driven Design, I have created a rich domain model. Using the model, we can execute [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/jquery-ui-logo.png" alt="jquery-ui-logo.png" border="0" width="258" height="74" align="left" />For a project that I am working on <em>Your-Scrum</em> I need a lot of items in a list that are sortable. One Story is to have a backlog with stories that are sortable to reflect the importance. Using <strong>Domain Driven Design</strong>, I have created a rich domain model. Using the model, we can execute all stories related to sorting items in a list. At the front-end I want an easy way to handle the sorting. I found a library for jQuery that can do the job for a large part on the client. Still there are some server side components as well.</p>
<p>The following screen gives an idea about the look and feel of the sortable list of stories.</p>
<p><a href="http://www.gridshore.nl/wp-content/uploads/Screenshot_yourscrum.png" rel="lightbox"><img src="http://www.gridshore.nl/wp-content/uploads/Screenshot_yourscrum.png" alt="Screenshot_yourscrum.png" border="0" width="200"/></a><span id="more-896"></span><br />
<h3>jQuery Sortable component</h3>
<p>Let us start to have a look at the front end. I am using jQuery together with jQuery-ui. Everybody doing series web development (should) know jQuery. I have written about jQuery before, but other have as well. Just do a search on google and the amount of articles is massive. Dzone also contains a few items each day about top 5 plugins for jQuery.  I think the power of jQuery-ui is not known that much. If you have not seen it before, be sure to check it out. It can help you a lot in creating websites that look sharp with icons and colors that are well balanced. The ui framework contains a lot of interaction components, widgets and effects. This blog posts focus is on the <a href="http://jqueryui.com/demos/sortable/">Sortable interaction component</a>.</p>
<p>With the sortable component you can actually drag the components in order. You get notified of the change.</p>
<h3>Setting op de component</h3>
<p>Before we can use the component we need to download the jquery-ui component. The jQuery UI project contains a <a href="http://jqueryui.com/download">download function</a> to create your customized download. Don&#8217;t forget to include at least the sortable function. You can also follow a long with the <a href="http://code.google.com/p/your-scrum/source/checkout">sources</a> I use in the your-scrum project. Now include the js files in your page. I use the script.js file to set generic libraries. (webapp/includes folder). Now open up the stories.jsp file under webapp/WEB-INF/jsp/story folder.</p>
<p>We begin by creating the list of items and use jQuery to make a sortable list out of it.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul id=&quot;sortable&quot;&gt;
    &lt;c:forEach items=&quot;${stories}&quot; var=&quot;story&quot;&gt;
        &lt;li id=&quot;story_${story.id}&quot; class=&quot;ui-state-default&quot;&gt;&lt;span class=&quot;listItemLabel&quot;&gt;${story.name}&lt;/span&gt;&lt;/li&gt;
    &lt;/c:forEach&gt;
&lt;/ul&gt;
</pre>
<p>Within the script block we now have to initialize the sortable component.</p>
<pre class="brush: jscript; title: ; notranslate">
var idsOldOrder;
$(function() {
    $(&quot;#sortable&quot;).sortable();
    idsOldOrder = $(&quot;#sortable&quot;).sortable('serialize').toString();
    $(&quot;#sortable&quot;).disableSelection();
    $(&quot;#sortable&quot;).bind('sortupdate', function(event, ui) {
        var ids = $(&quot;#sortable&quot;).sortable('serialize').toString();
        $.post('/story/reorder', {ids: ids, oldIds: idsOldOrder}, function(data) {
            // nothing special
            window.alert(data);
        });
        idsOldOrder = ids;
    });
});
</pre>
<p>This code might look more difficult than you did expect. That is because more is happening here than you expect. Within this code we need only the first line to show the sortable items. The other lines are for notification of changes. Don&#8217;t worry we explain them as well. Time to move on.</p>
<h3>Capturing change events</h3>
<p>Have a look at the previous code block. The second line stories a special form of presentation in a string. We need this on the server to actually determine the change. Than in line 4, we bind a function to the <em>sortupdate</em> event. Again a string containing the ids in the new order is created. Using the jQuery Ajax tooling we send a request to the server. The POST is done to the url <em>/story/reorder</em> with two parameters: ids and idsOldOrder. The result is shown in an alert box, which is not nice, but it works for now.</p>
<p>From the client side perspective, that is all there is to it. I actually wanted to have a real change from the library, like this item is moved before that item. But I could not find how to do just that. Therefore I had to do the trick with the old order and the new order. Now the server has to take care of finding the actual change. More on that later.</p>
<h3>Add task button</h3>
<p>One of the stories for our project is to add a new task to a story. If you have a look at the image containing a screen dump (the first image of this blog post) you see on each story the amount of tasks and an orange plus sign. The plus sign is something we use from the jquery-ui project as well. How to do this.</p>
<p>First we must add the content to the html using the jsp. So we have to extend the jsp with a text containing the number of tasks and a link that we can click to go to the add task form. The jsp now becomes:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul id=&quot;sortable&quot;&gt;
    &lt;c:forEach items=&quot;${stories}&quot; var=&quot;story&quot;&gt;
        &lt;li id=&quot;story_${story.id}&quot; class=&quot;ui-state-default&quot;&gt;&lt;span
                class=&quot;listItemLabel&quot;&gt;${story.name}&lt;/span&gt;&lt;span
                class=&quot;listItemAdd&quot;&gt;&lt;a
                href=&quot;/story/${story.id}/task/form&quot; title=&quot;add task&quot;&gt;&lt;spring:message code=&quot;generic.add&quot;/&gt;&lt;/a&gt;&lt;/span&gt;&lt;span
                class=&quot;listItemChilds&quot;&gt;tasks(${story.numberOfTasks})&lt;/span&gt;&lt;/li&gt;
    &lt;/c:forEach&gt;
&lt;/ul&gt;
</pre>
<p>Have a good look at the classes of the span elements. We are going to use them to change the appearance of the add link into that nice plus sign button. We are replacing the link with an image, clicking the image will call the function myClick which uses the actual link from the <em>a</em> element and opens that url. Have a look at the changes in the code.</p>
<pre class="brush: jscript; title: ; notranslate">
var myClick = function (event) {
    var location = $(event.target).children(&quot;a&quot;)[0].href;
    window.location = location;
};
$(function() {
    // only show changes, refer to previous code block for other lines
    $(&quot;#sortable li span.listItemAdd&quot;).addClass(&quot;ui-icon ui-icon-circle-plus&quot;).click(myClick);
});
</pre>
<p>Getting the icon with the plus sign is a jQuery trick as well. There are some style sheets that contain all the icons. You just need to find the right class to add to a span and you are done. I used the <em>ui-icon ui-icon-circle-plus</em>. More on the available icons can be found in <a href="http://jqueryui.com/themeroller/">the documentation</a>.</p>
<h3>Other jQuery things</h3>
<p>There are other things I use from jQuery. Check the references section for documentation. I use the corner plugin for the navigation. If you like the navigation implementation have a look at the main.jsp file in webapp/decorators. The final jQuery thing I want to mention is the <a href="http://code.google.com/p/js-hotkeys/">hotkeys plugin</a>. You can create hotkeys to be used on your page. I created a hotkey <em>ctrl+s</em> to open up the new story screen. The following code block shows the implementation.</p>
<pre class="brush: jscript; title: ; notranslate">
var newStory = function (event) {
    window.location = '/story/form';
    event.stopPropagation();
    event.preventDefault();
    return false;
};
$(function() {
    $(document).bind('keydown', 'ctrl+S', newStory);
});
</pre>
<h3>Finding the change on the server component</h3>
<p>The current status is that we have a POST to the server with two string containing ids in the old and the new order. Now we have to find the change. On the server I use Spring 3 to handle requests. I am not going to explain all the spring 3 configuration in this post. If you want to learn about spring 3 I advise you to go over the <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html">reference documentation</a>.</p>
<p>Handling the POST consists of two parts. The first part is finding the change from the two mentioned strings. The second part is communicate the change to the domain and persisting the change. In a next post I&#8217;ll focus more on the domain and the persistence part. For now have a look at the complete method that accepts the POST and handles it.</p>
<pre class="brush: java; title: ; notranslate">
    @RequestMapping(value = &quot;/story/reorder&quot;, method = RequestMethod.POST)
    public String reorderStories(@RequestParam(&quot;ids&quot;) String ids,
                                 @RequestParam(&quot;oldIds&quot;) String oldIds, ModelMap modelMap) {
        ItemSorter itemSorter = new ItemSorter();
        ChangedSortOfItems changedSortOfItems = itemSorter.determineChangeInStoryOrdering(strip(ids), strip(oldIds));

        Long movedItemId = null;
        try {
            if (StringUtils.hasText(changedSortOfItems.movedItem())) {
                movedItemId = Long.parseLong(changedSortOfItems.movedItem());
            }
        } catch (NumberFormatException e) {
            logger.warn(&quot;Number format exception of id from story to be planned while nog expected : &quot;
                    + changedSortOfItems.movedItem());
        }

        Long beforeItemId = null;
        try {
            beforeItemId = Long.parseLong(changedSortOfItems.beforeItem());
        } catch (NumberFormatException e) {
            logger.warn(&quot;NUmber format exception while nog expected&quot;);
        }
        backlogService.plan(movedItemId, BEFORE, beforeItemId);

        modelMap.addAttribute(&quot;message&quot;, &quot;story.order.changed&quot;);
        return &quot;message&quot;;
    }
</pre>
<p>This code should not be to hard to follow, now lets have a look at the <strong>ItemSorter</strong> class. This class uses the string to find differences. An instance of <strong>ChangedSortOfItems</strong> is returned that contains information about the items that have changed. In the end it is all about going through the list of items to find the first that changed from position. The first item that is different does not have to be the actual item that is moved. We can check that by looking at the next item. Have a look at the code if you can see what happens.</p>
<pre class="brush: java; title: ; notranslate">
    public ChangedSortOfItems determineChangeInStoryOrdering(String ids, String oldIds) {
        validateInput(ids, oldIds);

        if (ids.equals(oldIds)) {
            return ChangedSortOfItems.nothingChanged();
        }

        String[] arrayOfCurrentIds = StringUtils.delimitedListToStringArray(ids, delimiter);
        String[] arrayOfOldIds = StringUtils.delimitedListToStringArray(oldIds, delimiter);

        // A change must be found since the items are not equal
        ChangedSortOfItems change = null;
        int indexFirstChangedItem = findchangeInItems(arrayOfCurrentIds, arrayOfOldIds);
        // If you start at the beginning, the last item can never be the first item to change position
        String nextOfFirstChangedItem = arrayOfCurrentIds[indexFirstChangedItem + 1];

        if (nextOfFirstChangedItem.equals(arrayOfOldIds[indexFirstChangedItem])) {
            change = ChangedSortOfItems.movedBefore(arrayOfCurrentIds[indexFirstChangedItem],
                    arrayOfOldIds[indexFirstChangedItem]);
        } else {
            int lastitem = arrayOfCurrentIds.length - 1;
            for (int indexMovedBefore = indexFirstChangedItem; indexMovedBefore &lt; arrayOfCurrentIds.length;
                 indexMovedBefore++) {
                String movedItem = arrayOfCurrentIds[indexMovedBefore];
                if (indexMovedBefore == lastitem) {
                    change = ChangedSortOfItems.movedToEnd(movedItem);
                    break;
                } else {
                    String aNextOldItem = arrayOfOldIds[indexMovedBefore + 1];
                    if (!movedItem.equals(aNextOldItem)) {
                        change = ChangedSortOfItems.movedBefore(movedItem, aNextOldItem);
                        break;
                    }
                }
            }
        }
        return change;
    }
    private int findchangeInItems(String[] arrayOfCurrentIds, String[] arrayOfOldIds) {
        for (int i = 0; i &lt; arrayOfCurrentIds.length; i++) {
            String possibleMovedItem = arrayOfCurrentIds[i];
            String originalItem = arrayOfOldIds[i];
            if (!possibleMovedItem.equals(originalItem)) {
                return i;
            }
        }
        throw new NoChangeInSortFoundException();
    }
</pre>
<p>I hope the code is understandable. If not, questions can be asked in the comments <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<h3>Concluding</h3>
<p>Again I have to conclude that jQuery is a fantastic framework for client side development. I also have to conclude that the documentation and available samples are not always thorough enough. I am still not sure if there is no easier way to find the actual change. But maybe one of the readers of this blog out there can help me out. I do love the extendibility of the jQuery components.</p>
<p>If you liked this post, please push me up at dzone, if you have questions or remarks do not hesitate to use the comments.</p>
<h3>References</h3>
<ul>
<li><a href="http://code.google.com/p/your-scrum/">http://code.google.com/p/your-scrum/</a></li>
<li><a href="http://jqueryui.com/demos/sortable/">http://jqueryui.com/demos/sortable/</a></li>
<li><a href="http://jquery.malsup.com/corner/">http://jquery.malsup.com/corner/</a></li>
<li><a href="http://code.google.com/p/js-hotkeys/">http://code.google.com/p/js-hotkeys/</a></li>
<li><a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html</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%2F09%2F14%2Fcreating-a-sortable-list-of-items-using-jquery%2F&amp;title=Creating%20a%20sortable%20list%20of%20items%20using%20jQuery&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/09/14/creating-a-sortable-list-of-items-using-jquery/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>Looking for a wicket training in the Netherlands?</title>
		<link>http://www.gridshore.nl/2009/05/10/looking-for-a-wicket-training-in-the-netherlands/</link>
		<comments>http://www.gridshore.nl/2009/05/10/looking-for-a-wicket-training-in-the-netherlands/#comments</comments>
		<pubDate>Sun, 10 May 2009 18:32:10 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=762</guid>
		<description><![CDATA[<p>If you do not want commercial messages, or you do not want to learn about Wicket, it is safe to skip this post.</p> Wicket! June 8th and 9th <p>Web 2.0 applications are everywhere, and Apache Wicket technology is increasingly a part of them. Wicket is an exciting web development framework allowing an easy one [...]]]></description>
			<content:encoded><![CDATA[<p>If you do not want commercial messages, or you do not want to learn about Wicket, it is safe to skip this post.</p>
<h3>Wicket! June 8th and 9th</h3>
<p>Web 2.0 applications are everywhere, and Apache Wicket technology is increasingly a part of them. Wicket is an exciting web development framework allowing an easy one on one mapping between HTML and Java classes.</p>
<p>JTeam is proud to announce our partnership with <a href="http://www.jweekend.com/dev/LWUGReg/">jWeekend</a>, enabling us to offer you high quality and exclusive Wicket trainings in the Benelux. Check out <a href="http://blog.jteam.nl/2009/03/24/jteam-announces-wicket-training/">JTeam&#8217;s Blog</a> for more information about this partnership and the training options.</p>
<p><a href="http://www.regonline.co.uk/builder/site/Default.aspx?eventid=727194">Sign up now</a> for the Wicket traning on June 8&#038;9 and receive an early bird discount!</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%2F10%2Flooking-for-a-wicket-training-in-the-netherlands%2F&amp;title=Looking%20for%20a%20wicket%20training%20in%20the%20Netherlands%3F&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/looking-for-a-wicket-training-in-the-netherlands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

