<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CUMGRXk4fyp7ImA9WhBbF04.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182</id><updated>2013-05-16T21:43:44.737+02:00</updated><category term="idea" /><category term="scala" /><category term="gatling" /><category term="stress" /><category term="html5" /><category term="monad" /><category term="play2.0" /><category term="sbt" /><category term="sjon" /><category term="graph" /><category term="http" /><category term="mongodb" /><category term="help" /><category term="sjson" /><category term="rest" /><category term="shapeless" /><category term="dispatch" /><category term="cloudbees" /><category term="scalaz" /><category term="plugin" /><category term="non-blocking" /><category term="interceptor" /><category term="neo4j" /><category term="spine.js" /><category term="monad transformer" /><category term="functional" /><category term="salat" /><category term="akka" /><category term="d3.js" /><category term="arbor" /><category term="bootstrap" /><category term="heroku" /><category term="typesafe" /><category term="async" /><category term="json" /><category term="database" /><title>Ska La</title><subtitle type="html">Sounds like Playing with Scala</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://ska-la.blogspot.com/" /><author><name>andy petrella</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/OojqO" /><feedburner:info uri="blogspot/oojqo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;AkINQ3c_eSp7ImA9WhJWFE0.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-6595541021253189398</id><published>2012-08-13T23:05:00.000+02:00</published><updated>2012-08-19T22:36:32.941+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-08-19T22:36:32.941+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="salat" /><category scheme="http://www.blogger.com/atom/ns#" term="plugin" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="mongodb" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>MongoDB and Play2 at ease: using Play-Salat plugin and Embed Mongo plugin</title><content type="html">A while ago I've blogged about MongoDB with Play2 using Salat, &lt;a href="http://ska-la.blogspot.be/2012/03/play-20-and-salat-mongodb-dao-provider.html" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This post was describing how to integrate Salat easily with Play2 and gave some advice on actions to care of.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Preface&lt;/h4&gt;
Play 2 gained in popularity and an amazing plugin as emerge for this purpose: &lt;a href="https://github.com/leon/play-salat" target="_blank"&gt;play2-salat&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This plugin offers a lot of configuration to hit running instances including replicasets! It integrates very well by applying the advice I talked about in my post, but not only. It defines binders to enable us using Casbah stuffs in our routing and action definition (ObjectId, and so on).&lt;br /&gt;
&lt;br /&gt;
This post is not dedicated to explain how to use it, I'd recommend you to browse the project page (&lt;a href="https://github.com/leon/play-salat" target="_blank"&gt;play2-salat&lt;/a&gt;), plus the wiki that points to relevant URLs.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Goal&lt;/h4&gt;
&lt;div&gt;
This post is dedicated to developers teams that follows (or not...) the convention of Continuous Delivery, especially the&amp;nbsp;&lt;a href="http://refcardz.dzone.com/refcardz/continuous-delivery-patterns" target="_blank"&gt;Single Command Environment&lt;/a&gt;&amp;nbsp;pattern. That is, the environment must be set up in one single command... in Play2 =&amp;gt;&amp;nbsp;&lt;i&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;play run&lt;/span&gt;&lt;/i&gt;&amp;nbsp;OR&amp;nbsp;&lt;i&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;sbt run&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;h4&gt;
Context&lt;/h4&gt;
&lt;div&gt;
Create an application that uses MongoDB as (one of its) persistence backend service, use play2-sala to have access to the `&lt;i&gt;ORM&lt;/i&gt;` for our object and easy collections connections.&lt;/div&gt;
&lt;div&gt;
When runnning in production, of course, a MongoDB instance runs somewhere that can be configured (or a replicatset).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But in Dev?&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4&gt;
Embed Instance&lt;/h4&gt;
&lt;div&gt;
When another developer is cloning the related repo, knowing that it's a play application, he's best will would be to enter the directory and launch the application. &amp;gt; BANG &amp;lt;&lt;/div&gt;
&lt;div&gt;
No running instance...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So I created a Play2 plugin that uses this &lt;a href="https://github.com/michaelmosmann/embedmongo.flapdoodle.de" target="_blank"&gt;amazing work&lt;/a&gt; which retrieves a mongodb installer, installs it and enable us to launch/stop it... Keep in mind that MongoDB is not JVM based!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Adding this plugin to the application, setup the dev configuration to starts an embed MongoDB and Play2-Salat to target it, will gives the satisfaction to our developer... Moreover if he is a Designer (the only kind of guy that add values to any app ^^) who don't care about MongoDB, at all!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4&gt;
How To&lt;/h4&gt;
&lt;div&gt;
Add the plugin dependencies (used in &lt;b&gt;PlayProject&lt;/b&gt;):&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;//MY OWN REPO where is deployed the following plugin&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;val skalaCloudbeesSnapshots = "Ska La SNAPSHOTS" at "https://repository-andy-petrella.forge.cloudbees.com/snapshot/"&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; //THE NEW PLUGIN =&amp;gt; EMBED&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; lazy val embedMongoPlayPlugin &amp;nbsp; &amp;nbsp;= "be.nextlab" %% "play-plugins-embed-mongodb" % "0.0.1-SNAPSHOT" changing()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; //THE WORTH ONE&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; lazy val salatPlayPlugin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = "se.radley" %% "play-plugins-salat" % "1.0.8"&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; //DECLARE the deps&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; val appDependencies = Seq(&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; embedMongoPlayPlugin,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; salatPlayPlugin&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&amp;nbsp; &amp;nbsp; )&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
A bit of configuration (&lt;b&gt;application-dev.conf&lt;/b&gt;)&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;embed.mongodb.start=true&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;embed.mongodb.version=V2_1_1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;span style="color: #38761d;"&gt;embed.mongodb.port=27017&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;mongodb.default.db=meinGot&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;mongodb.default.host=localhost&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;mongodb.default.port=27017&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And the most only thing that requires a bit of explanation (in &lt;b&gt;conf/play.plugins&lt;/b&gt;)&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;600:se.radley.plugin.salat.SalatPlugin&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;550:be.nextlab.play.mongodb.EmbedMongoDBPlugin&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #38761d;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
See? Yes, the Play2-Salat plugin&amp;nbsp;&lt;b&gt;MUST&lt;/b&gt; be started &lt;b&gt;AFTER&lt;/b&gt;&amp;nbsp;the embed plugin... of course (what an explanation huh).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4&gt;
Code&lt;/h4&gt;
&lt;div&gt;
The one-single-file-of-33-lines plugin can be forked &lt;a href="https://github.com/andypetrella/play-plugins-embed-mongodb" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;hr /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-size: x-large;"&gt;&lt;b&gt;That's All, Folks!&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/0Nmrc9Px1eA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/6595541021253189398/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/08/mongodb-and-play2-at-ease-using-play.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6595541021253189398?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6595541021253189398?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/0Nmrc9Px1eA/mongodb-and-play2-at-ease-using-play.html" title="MongoDB and Play2 at ease: using Play-Salat plugin and Embed Mongo plugin" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/08/mongodb-and-play2-at-ease-using-play.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4MQX8_cSp7ImA9WhJRGEw.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-7899033498917671632</id><published>2012-07-20T22:39:00.003+02:00</published><updated>2012-07-20T22:43:00.149+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-20T22:43:00.149+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="help" /><category scheme="http://www.blogger.com/atom/ns#" term="stress" /><category scheme="http://www.blogger.com/atom/ns#" term="sbt" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><category scheme="http://www.blogger.com/atom/ns#" term="gatling" /><title>Gatling-Tool in SBT or Play : Sample Projects</title><content type="html">&lt;h2&gt;
Content&lt;/h2&gt;
This post is a direct follow up of this &lt;a href="http://ska-la.blogspot.com/2012/07/gatling-made-easy-for-sbt-orand-play2.html" target="_blank"&gt;one&lt;/a&gt; where I introduced a bit what I did in order to integrate Gatling in SBT and in Play2.&lt;br /&gt;
Where this post was more about bits and bytes necessary to accomplish the task, this one will talk about how to use this mess.

&lt;br /&gt;
&lt;h2&gt;
Gatling for SBT&lt;/h2&gt;
Now, that we've a dedicated SBT plugin in hand we can create a sample project that uses it (I already created one &lt;a href="https://github.com/andypetrella/gatling-sbt-sample" target="_blank"&gt;here&lt;/a&gt;).&lt;br /&gt;
In this new project, we'll need to create a file &lt;i&gt;plugins.sbt&lt;/i&gt; which will contains the reference to the &lt;i&gt;gatling-sbt-plugin&lt;/i&gt;.&lt;br /&gt;
Actually, it's the classical way to add a plugin to a SBT project (and the easier and the "semanticest").&lt;br /&gt;
We're now prepared to configure our build by using the pieces provided by the plugin.&lt;br /&gt;
&lt;span style="background-color: white;"&gt;At the end, we'll be able to write a first test and launch it.&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Project Build&lt;/h3&gt;
First of all, we must create a directory for your project with this basic structure:&lt;br /&gt;
&lt;code&gt;&lt;script src="https://gist.github.com/3152811.js?file=project-structure"&gt;
&lt;/script&gt;&lt;/code&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Looking at the structure, we can see a &lt;/span&gt;&lt;i style="background-color: white;"&gt;Build.scala&lt;/i&gt;&lt;span style="background-color: white;"&gt; that will define our project build, a &lt;/span&gt;&lt;i style="background-color: white;"&gt;build.properties&lt;/i&gt;&lt;span style="background-color: white;"&gt; that defines the SBT version with a single line :&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white;"&gt;&lt;i&gt;sbt.version=0.11.3&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;And the latest file in the &lt;/span&gt;&lt;i&gt;project&lt;/i&gt;&lt;span style="background-color: white;"&gt; folder is&amp;nbsp;&lt;/span&gt;&lt;i&gt;plugins.sbt&lt;/i&gt;&lt;span style="background-color: white;"&gt; which... declares the plugin.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Let's put the Build.scala aside for now, and have a look at the content of the latter.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/3152811.js?file=plugins.sbt"&gt;
&lt;/script&gt;&lt;span style="background-color: white;"&gt;Self descriptive isn't it? Yes, we've just told that SBT has to use our gatling plugin... that's all? Not yet.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Actually this line will provide us everything that have been declared in the plugin, such as the Gatling configuration keys, the command, and the basic SBT settings.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Now, we're gonna us them within our Build.scala.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;script src="https://gist.github.com/3152811.js?file=Build.scala"&gt;
&lt;/script&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Before going in specific details, note that we had to add my own repo (hosted at Cloudbees) in order to fetch the project... but you could also use the URI fetch provided by SBT...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;What are really important to point out is the &lt;/span&gt;&lt;i style="background-color: white;"&gt;allSettings&lt;/i&gt;&lt;span style="background-color: white;"&gt; declaration and the import of the GatlingPlugin.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;At first, we reuse the default one by using &lt;/span&gt;&lt;i style="background-color: white;"&gt;Project.defaultSettings&lt;/i&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;which is being appended the gatling settings, using &lt;/span&gt;&lt;i style="background-color: white;"&gt;&lt;b&gt;Gatling.gatlingSettings&lt;/b&gt;&lt;/i&gt;&lt;span style="background-color: white;"&gt;... that object comes from our plugin!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;This will add all relevant keys for the "&lt;i&gt;gatling-test&lt;/i&gt;" Configuration with default values.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;At this stage we've almost finish our build definition...

All that remain (and shouldn't... have to figure out &lt;/span&gt;&lt;small style="background-color: white;"&gt;&lt;span style="font-size: xx-small;"&gt;any help is welcomed?&lt;/span&gt;&lt;/small&gt;&lt;span style="background-color: white;"&gt;) is to add two things:&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Declare the test framework to have access to the gatling classes and the custom Simulation : &lt;pre&gt;"be.nextlab" %% "gatling-sbt-test-framework" % "0.0.1-SNAPSHOT" % "gatling-test"&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Declare the command : &lt;pre&gt;commands ++= Seq(gatlingTakatak)&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
After having used everything in your project (don't forget to add the &lt;i&gt;GatlingTest&lt;/i&gt; configuration...) you're so close to &lt;u&gt;write your first test&lt;/u&gt;.

&lt;br /&gt;
&lt;h3&gt;
Gatling Conf&lt;/h3&gt;
This section will cover the other folder &lt;i&gt;src&lt;/i&gt; wherein reside the classical &lt;i&gt;main&lt;/i&gt; and &lt;i&gt;test&lt;/i&gt; folders.&lt;br /&gt;
But there is an other one, &lt;i&gt;&lt;b&gt;gatling-test&lt;/b&gt;&lt;/i&gt; that is unknown at this stage.&lt;br /&gt;
In fact, this folder will be the root for our Gatling tests, holding the &lt;i&gt;configuration file&lt;/i&gt; (I provided a basic one in the sample app) and the &lt;i&gt;future simulations&lt;/i&gt; that you'll write.&lt;br /&gt;
&lt;br /&gt;
The first is dropped in &lt;i&gt;conf/galing.conf&lt;/i&gt;, where the latter is simply &lt;i&gt;simulations&lt;/i&gt;.

&lt;br /&gt;
&lt;h3&gt;
Write your first test&lt;/h3&gt;
At this stage, I'll make an assumption that you either know the Gatling api... Nah, the Gatling DSL is sufficiently self descriptive (otherwise check the &lt;a href="https://github.com/excilys/gatling/wiki/HTTP" target="_blank"&gt;wiki&lt;/a&gt;).&lt;br /&gt;
&lt;script src="https://gist.github.com/3152811.js?file=SampleSimulation.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
As you can see, it's very very easy (&lt;i&gt;that's why I like Gatling-Tool&lt;/i&gt;).&lt;br /&gt;
All we had to do, since we're benchmarking &lt;a href="https://www.google.com/" target="_blank"&gt;google&lt;/a&gt;, is to implemnent the &lt;i&gt;&lt;b&gt;apply&lt;/b&gt;&lt;/i&gt; method of a simple scenario within a class (with must have an empty constructor... &lt;u&gt;a limitation for now&lt;/u&gt;) that must extend our custom Simulation &lt;span style="font-size: xx-small;"&gt;(yeah! I know ... I'll choose another name for it that's why &lt;i&gt;GSimulation&lt;/i&gt; is needed)&lt;/span&gt;.&lt;br /&gt;
Note the dummy implementations of the interceptors whose aren't needed here.&lt;br /&gt;
This Simulation must be located somewhere under the &lt;i&gt;simulations&lt;/i&gt; folder.&lt;br /&gt;
&lt;br /&gt;
Now, we can launch it and see where are stored the results.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;
&lt;/code&gt;

That's enough boy...&lt;br /&gt;
Let it shot the server and generate the result.&lt;br /&gt;
&amp;nbsp;...&lt;br /&gt;
...&lt;br /&gt;
Done? ok.&lt;br /&gt;
&lt;br /&gt;
Now, that all bullets have been shot, you can go in this folder &lt;i&gt;&lt;b&gt;gatling-project/target/gatling-test/result&lt;/b&gt;&lt;/i&gt;.&lt;br /&gt;
See? True! Every run will create a specific folder under this one, named &lt;i&gt;run-${scenario-name}-time&lt;/i&gt;.&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Make some jump in it and locate the &lt;/span&gt;&lt;i style="background-color: white;"&gt;index.html&lt;/i&gt;&lt;span style="background-color: white;"&gt; file, open it in your browser and see the magic happened.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;NB: check &lt;a href="https://github.com/excilys/gatling/wiki/Reports" target="_blank"&gt;this page&lt;/a&gt; for information about the reports.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;So far, so good. But we're writing web apps and we want to stress them... we all know that the google server won't crash (that easy).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Let's move to &lt;b&gt;Play2&lt;/b&gt; (or you can write your own app w/o Play2 using Spray or another Java framework maybe, then mimic the following).&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;
Gatling for Play2&lt;/h2&gt;
For this part, I also wrote an &lt;a href="https://github.com/andypetrella/gatling-play2-sample" target="_blank"&gt;application&lt;/a&gt; that makes use of the "plugin" introduced in the previous post.
&lt;br /&gt;
It's quite complicated, not yet polished and might be a good topic for a future post, because I tried to make an application based on &lt;b&gt;Event Sourcing&lt;/b&gt; with some workflows and usages of pure functional structure like &lt;b&gt;Lens&lt;/b&gt;, &lt;b&gt;Writer&lt;/b&gt;, &lt;b&gt;State&lt;/b&gt;, &lt;b&gt;Monad&lt;/b&gt; and so forth.&lt;br /&gt;
&lt;br /&gt;
But let's stick with the actual topic, if you fork the project and browse a bit its build configuration you'll see that it is near from the one we just talked about.&amp;nbsp;&lt;span style="background-color: white;"&gt;But still that some particularities are presents...&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Definition&lt;/h3&gt;
First of all, since Play2 has its own convention for sources folders (&lt;i&gt;app&lt;/i&gt;, &lt;i&gt;test&lt;/i&gt; under the root) we'll redefine those folders for gatling as well.&lt;br /&gt;
In order to do that, we must &lt;u&gt;adapt&lt;/u&gt; the following configuration keys:&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;script src="https://gist.github.com/3152811.js?file=adaptKeys.sbt"&gt;
&lt;/script&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Actually, yeah, we've just skipped the "src" folder. Anyway.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;So far, so good...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;I heard you...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;But, do you known that we're already done?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;i&gt;Allez&lt;/i&gt;, let's write a test.&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Write&lt;/h3&gt;
If you started from scratch (without forking the sample app) you can now stress test your &lt;i&gt;&lt;b&gt;index&lt;/b&gt;&lt;/i&gt; page that will render the default &lt;i&gt;&lt;b&gt;welcome&lt;/b&gt;&lt;/i&gt; page defined in Play2.&lt;br /&gt;
See the below Gist for that, or its follower for a more complicated one using the app.&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;script src="https://gist.github.com/3152811.js?file=simple.scala"&gt;
&lt;/script&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/3152811.js?file=CreateAndLogin.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Look what I've done Dad!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;In the Simulations, all we had to do is to simply declare an available &lt;i&gt;port&lt;/i&gt; on which the framework can start the server, and its needed &lt;i&gt;FakeApplication&lt;/i&gt; to have access to the routing.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Then when we had to build a request path, we've just had to do the same as in our templates, that is, use the &lt;/span&gt;&lt;i style="background-color: white;"&gt;routes&lt;/i&gt;&lt;span style="background-color: white;"&gt; object under the controller package. &lt;span style="font-size: x-small;"&gt;Amazing&lt;/span&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Furthermore, we can also reuse our type checked &lt;/span&gt;&lt;i style="background-color: white;"&gt;Form&lt;/i&gt;&lt;span style="background-color: white;"&gt; to build our feeder. &lt;span style="font-size: x-small;"&gt;Waouw&lt;/span&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;But, at this stage, there still some boilerplate (parameters). &lt;span style="font-size: x-small;"&gt;Looser&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Launch&lt;/h3&gt;
And now, it's time to stress test our server and see how it'd behave on production. (Ok, that's not 100% true, since Gatling is running on the same machine...)&lt;br /&gt;
&lt;br /&gt;
For that, just do the following:&lt;br /&gt;
&lt;script src="https://gist.github.com/3152811.js?file=play.console"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;Wait.

Again.&lt;br /&gt;
&lt;br /&gt;
Now, go to you result directory (the path hasn't changed).&amp;nbsp;&lt;span style="background-color: white;"&gt;Open in your browser and let the shine comes in.&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;
Wrap Up&lt;/h2&gt;
At this stage, with small and few injuries we can use &lt;a href="http://gatling-tool.org/" target="_blank"&gt;Gatling-Tool&lt;/a&gt; without having to install or trick stuffs in order to have information about our web app.&lt;br /&gt;
&lt;span style="background-color: white;"&gt;This by using either a full SBT application or a Play2 based one.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;I know that there still a lot to do, but at least the basic features are there, and I'll enjoy anyone forking it, scrapping it if necessary and let me know.&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;
Last words&lt;/h2&gt;
I hope you liked these posts, otherwise I'd like to apologize because I did all projects and the blogs on the train, half asleep every morning and evening, back and forth from my actual mission's workplace.&lt;br /&gt;
&lt;br /&gt;
Now I'm gonna sleep in this train...&lt;br /&gt;
Oh no, I can't...&lt;br /&gt;
I've to write my book now.&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/rAnszk90q44" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/7899033498917671632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/07/gatling-tool-in-sbt-or-play-sample.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/7899033498917671632?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/7899033498917671632?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/rAnszk90q44/gatling-tool-in-sbt-or-play-sample.html" title="Gatling-Tool in SBT or Play : Sample Projects" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/07/gatling-tool-in-sbt-or-play-sample.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8BQXkyeip7ImA9WhJRGEw.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-4013736737708379687</id><published>2012-07-20T22:36:00.000+02:00</published><updated>2012-07-20T22:40:50.792+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-20T22:40:50.792+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="help" /><category scheme="http://www.blogger.com/atom/ns#" term="stress" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><category scheme="http://www.blogger.com/atom/ns#" term="gatling" /><title>Gatling made easy for SBT or/and Play2</title><content type="html">&lt;h2&gt;


Forewords&lt;/h2&gt;
These last few weeks, I took some time to understand a level deeper how SBT works and what it can provide.

Since this post is not related to this learning trip (which was along existing blogs and wikis), I'll jump directly to the idea this new understanding gave me.&lt;br /&gt;
A while ago I started (and paused) a work on Gatling-Tool to have it integrated with Play 2.0 (see these posts &lt;a href="http://ska-la.blogspot.com/2012/03/gatling-tool-plugin-for-play-20.html" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://ska-la.blogspot.com/2012/04/gatling-and-play20-continued.html" target="_blank"&gt;here&lt;/a&gt;), this work has been refactored to better integrate with SBT.

&lt;br /&gt;
&lt;h2&gt;


What we'll find in this post&lt;/h2&gt;
In this post, I'm gonna give you all tools in order to stress test you Web based application, either built upon Play 2.0, either only using SBT. By directly starting writing your tests rather than having to configure stuffs or to start others...

So this post is composed of two parts:
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;How I built these tools (can be skipped -- definitively)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.be/2012/07/gatling-tool-in-sbt-or-play-sample.html" target="_blank"&gt;How to use these tools&lt;/a&gt; (it's probably the useful part)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;


Gatling shot 3 aside projects... for goods&lt;/h2&gt;
This part is related to what was necessary to have gatling-tool easily integrated with SBT, and after with Play2.

&lt;br /&gt;
&lt;h3&gt;


Gatling SBT Test Framework&lt;/h3&gt;
This project (on &lt;a href="https://github.com/andypetrella/gatling-sbt-test-framework" target="_blank"&gt;github&lt;/a&gt;) has a sole and simple goal, to implement the Test Interface (&lt;a href="https://github.com/harrah/test-interface" target="_blank"&gt;see&lt;/a&gt;) used by SBT to integrate new Test Framework (like was done for ScalaTest, Specs, JUnit, and...).

This project contains only 2 classes and one convenient trait.

&lt;br /&gt;
&lt;h4&gt;


GatlingBootstrap&lt;/h4&gt;
This class is one of the helper that avoid boilerplates in the future, because it starts the GatlingConfiguration stuff needed by Gatling-Tool to execute.

This class requires two things "the path to the gatling configuration file" and "the path to the folder where will be stored the stress results".

&lt;br /&gt;
&lt;h4&gt;


Simulation&lt;/h4&gt;
This trait is another tool in hand that extends the &lt;i&gt;com.excilys.ebi.gatling.core.Predef.Simulation&lt;/i&gt; provided by Gatling in order to add it two interceptors whose are &lt;i&gt;pre&lt;/i&gt; and &lt;i&gt;post&lt;/i&gt;.

Those interceptors will be really useful in the future, in order to start/stop a server for instance (e.g. &lt;i&gt;FakeServer&lt;/i&gt; in Play2).


&lt;br /&gt;
&lt;h4&gt;


GatlingTestFramework&lt;/h4&gt;
This class is the real processor of the project.

Actually, it's also the implementation of the interfaces declared by the SBT test framework which are &lt;i&gt;Framework&lt;/i&gt;, &lt;i&gt;Runner2&lt;/i&gt; and some &lt;i&gt;Fingerprint&lt;/i&gt;s.

Basically, what is done there are those tasks:
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Create the gatling bootstrap based on sys properties&lt;/li&gt;
&lt;li&gt;Declare fingerprint to discover Stress Test based on the parent class being &lt;i&gt;be.nextlab.gatling.sbt.plugin.Simulation&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;Create the stress tests instances (only classes are handled for now) by reflection&lt;/li&gt;
&lt;li&gt;Call the &lt;i&gt;pre&lt;/i&gt; interceptor&lt;/li&gt;
&lt;li&gt;Execute the stress test using the gatling api&lt;/li&gt;
&lt;li&gt;Call the &lt;i&gt;post&lt;/i&gt; interceptor&lt;/li&gt;
&lt;li&gt;Generate the reports using the gatlin api&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;


Gatling SBT Plugin&lt;/h3&gt;
This project (&lt;a href="https://github.com/andypetrella/gatling-sbt-plugin" target="_blank"&gt;here&lt;/a&gt; on github) aims to provide the basics to use the test framework easily within an SBT project&lt;span style="background-color: white;"&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Its intent is to have testers able to write stress tests directly, just after having imported the module in SBT.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;It basically provides an SBT Configuration (&lt;/span&gt;&lt;b style="background-color: white;"&gt;gatling-test&lt;/b&gt;&lt;span style="background-color: white;"&gt;) that extends the SBT's Test one and one Command (&lt;/span&gt;&lt;b style="background-color: white;"&gt;takatak&lt;/b&gt;&lt;span style="background-color: white;"&gt;).

The other goodies are &lt;i&gt;settings&lt;/i&gt; which are common for all such stress tested projects using gatling.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;Those settings are essentially the conf file path, the result directories, the libraries (gatling ones principally) and so on.

The last important thing that it does is to add the gatling test framework to the already existing list of test frameworks supported out of the box by SBT.&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;


Gatling Play2 Plugin&lt;/h3&gt;
This misnamed project &lt;small&gt;&lt;span style="font-size: xx-small;"&gt;(no more a Play2 plugin, neither a SBT one... but it's ok for now)&lt;/span&gt;&lt;/small&gt; brings only one little thing.

It comes with a base implementation the custom &lt;i&gt;Simulation&lt;/i&gt; declared in the Gatling Test Framework.&lt;br /&gt;
&lt;br /&gt;
This base implementation is Play2 specific while creating a fake server and starting it in the &lt;i&gt;pre&lt;/i&gt; interceptor, stoping it in the &lt;i&gt;post&lt;/i&gt; one.&lt;br /&gt;
&lt;br /&gt;
This will ease further tests in the Play2 environment.

&lt;br /&gt;
&lt;h2&gt;


Save Point&lt;/h2&gt;
So far so good, if you read this you can now navigate the small projects that were necessary to do what we'll discuss in the next blog...&lt;br /&gt;
&lt;br /&gt;
This one is already too long...&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/6bTKDC7YPko" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/4013736737708379687/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/07/gatling-made-easy-for-sbt-orand-play2.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/4013736737708379687?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/4013736737708379687?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/6bTKDC7YPko/gatling-made-easy-for-sbt-orand-play2.html" title="Gatling made easy for SBT or/and Play2" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/07/gatling-made-easy-for-sbt-orand-play2.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAESHw8eyp7ImA9WhVaGEs.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-3513340163391845816</id><published>2012-06-16T18:38:00.000+02:00</published><updated>2012-06-16T18:38:29.273+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-16T18:38:29.273+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="interceptor" /><category scheme="http://www.blogger.com/atom/ns#" term="help" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="shapeless" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Type-safed Composable Interceptors in Play2.0</title><content type="html">This post is just a quick follow-up of this &lt;a href="http://ska-la.blogspot.be/2012/06/attempt-of-play20-action-interceptor.html" target="_blank"&gt;post&lt;/a&gt;, which introduced my latest utility for Play 2.0.&lt;br /&gt;
I recommend you to have a quick overview on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Type-safe composition of interceptors : Premises&lt;/h2&gt;
&lt;br /&gt;
Briefly, we'll just see how the first "future work" as been addressed. That is, &lt;i&gt;avoid boilerplate for interceptors composition&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
A quick recall, when we had to compose such &lt;i&gt;Interceptors&lt;/i&gt;&amp;nbsp;we had to take care our-selves of the validation results and the combined result (tuple or whatever).&lt;br /&gt;
The real problem that is under the sea here, is that tuples are not so easily generalizable (no append method, roughly).&lt;br /&gt;
&lt;br /&gt;
So I decided to use the Shapeless library (thx to @milessabin).&lt;br /&gt;
&lt;br /&gt;
Shapeless has an amazing core structure that enables type-and-value chaining (somehow). The &lt;i&gt;HList&lt;/i&gt;&amp;nbsp;type is a kind of list but each element is one &lt;i&gt;value&lt;/i&gt; and one &lt;i&gt;type&lt;/i&gt;. For instance, it has the &lt;i&gt;head value&lt;/i&gt; and the &lt;i&gt;Head type&lt;/i&gt; on top of the Stack. Here is the kind of stuffs that we can do with Shapeless:&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;i&gt;val | = false&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;i&gt;val thisIsNotAPipe = "this" :: 15 :: false :: "a" :: | :: HNil&lt;/i&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;b&gt;&amp;gt;&amp;nbsp;thisIsNotAPipe: shapeless.::[java.lang.String,shapeless.::[Int,shapeless.::[Boolean,shapeless.::[java.lang.String,shapeless.::[Boolean,shapeless.HNil]]]]] = this :: 15 :: false :: a :: false :: HNil&lt;/b&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;gt;Type-safe list of stuffs&amp;lt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;/i&gt;&lt;br /&gt;
&lt;h2&gt;
&lt;i&gt;In Action...&lt;/i&gt;&lt;/h2&gt;
&lt;br /&gt;
While trying to use &lt;i&gt;HList&lt;/i&gt;&amp;nbsp;generically I had problem with the implicits that are needed to prepend two lists, but StackOverflow has brought me the answer &lt;a href="http://stackoverflow.com/questions/11036334/shapeless-prepend-implicit-not-found/11037915" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;
I'm not gonna tackle here how I did, by I'll demonstrate what is now possible with the new composition functionalities added to &lt;i&gt;Interceptors&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
First of all, I had to declare an Interceptor for HList and the related implicit conversion. After what, I added three methods:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;hlist&lt;/b&gt;&amp;nbsp;this method on &lt;i&gt;Intercept&lt;/i&gt;&amp;nbsp;is able to convert a classical one to a &lt;i&gt;HList&lt;/i&gt;&amp;nbsp;one&lt;/li&gt;
&lt;li&gt;&lt;b&gt;~::~ &lt;/b&gt;this one is available to compose any interceptors that is not defined using HList with an HList one. It will create a new Interceptor with the new composed HList as result&lt;/li&gt;
&lt;li&gt;&lt;b&gt;~:::~ &lt;/b&gt;this one enable to compose two Interceptor defined with HList, the results will be the concatanation of the two HList.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Note: concatanation of HLists preserves the type sequence, actually we can see that as if it concat two lists of values and two list of types.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Let's see how we can deal with them:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2941878.js?file=security.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Easy no? Combine interceptors and use compile-time type-checking to validate the required kinds of items.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Without boilerplate&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/Tw3RXtYckbI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/3513340163391845816/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/06/type-safed-composable-interceptors-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3513340163391845816?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3513340163391845816?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/Tw3RXtYckbI/type-safed-composable-interceptors-in.html" title="Type-safed Composable Interceptors in Play2.0" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/06/type-safed-composable-interceptors-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEAQH45eCp7ImA9WhVaF0Q.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-6616326932131956907</id><published>2012-06-15T23:10:00.001+02:00</published><updated>2012-06-15T23:10:41.020+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-15T23:10:41.020+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="functional" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scalaz" /><category scheme="http://www.blogger.com/atom/ns#" term="shapeless" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>An Attempt of Play2.0 Action Interceptor</title><content type="html">In this post, I'm gonna introduce a piece of code that I laid with the help of two stuffs.&lt;br /&gt;
The &lt;a href="https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/mvc/Security.scala" target="_blank"&gt;Security&lt;/a&gt;&amp;nbsp;object provided by Play 2.0 out of the box and somehow the &lt;a href="https://github.com/typesafehub/play-plugins/blob/master/util/src/main/scala/com/typesafe/plugin/package.scala" target="_blank"&gt;Secured&lt;/a&gt; one provided by the TypeSafe's plugin &lt;i&gt;util&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
The idea here is to leverage the actual functionality wich only enables to provide one &lt;i&gt;Option[String]&lt;/i&gt;&amp;nbsp;as result.&lt;br /&gt;
What I wanted at first is to satisfy my use case, which is : &lt;i&gt;a lot of actions are secured and I need a username &lt;/i&gt;&lt;i style="font-weight: bold;"&gt;and its id&lt;/i&gt;. Where &lt;b&gt;id&lt;/b&gt;&amp;nbsp;is an Int.&lt;br /&gt;
&lt;br /&gt;
Here we are, the actual &lt;i&gt;Security&lt;/i&gt; and &lt;i&gt;Secured&lt;/i&gt; don't permit me to have several extracted values, or to have an Int.&lt;br /&gt;
&lt;br /&gt;
That's why I created this project :&amp;nbsp;&lt;a href="https://github.com/andypetrella/steal-play2"&gt;https://github.com/andypetrella/steal-play2&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Steal&amp;nbsp;&lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Steal_(basketball)" target="_blank"&gt;&lt;span style="font-size: xx-small;"&gt;help&lt;/span&gt;&lt;/a&gt;&lt;/i&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;br /&gt;
The idea is to enable any actions to be preceded by some interceptors that are stealing values either from the request, the cache, the database (or...) and set them as the parameters of a closure that outputs an Action.&lt;br /&gt;
&lt;br /&gt;
But we must also care of the cases when something went wrong during the stealing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Interceptor&lt;/h3&gt;
&lt;br /&gt;
&lt;br /&gt;
This trait is the core of the solution, it defines:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;b&gt;stealing&lt;/b&gt; operation: a function that takes (currently) the request and outputs a validated output (Validation from ScalaZ)&lt;/li&gt;
&lt;li&gt;the &lt;b&gt;err&lt;/b&gt; callback: &amp;nbsp;a function that takes the request and the failure (when computing the stolen value) and outputs a valid Result to send back to the client.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;apply&lt;/b&gt;: a closure that takes the result (not a Validation) and output an &lt;i&gt;Action&lt;/i&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
At this stage and looking at the code below (I've omitted the apply impl because not important here -- just wrapping and unwrapping), it's fairly simple to know how to define such interceptor.&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2938623.js?file=interceptor.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I provided the simplest implementation of this trait that is a case class extending it by defining the two callbacks as fields. Like so:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2938623.js?file=intercept.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So now we're armed to do stuff like that:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2938623.js?file=both.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Where we defined two interceptors that takes a string from the cache and an Int form the cache also (just an illustration). After what, we combined them in an another &lt;i&gt;Intercept&lt;/i&gt;&amp;nbsp;using a for-comprehension.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So far, so good, now how to use such combined interceptor within an &lt;i&gt;Action&lt;/i&gt;. Check this out:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2938623.js?file=bothAction.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
Monoid&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
With the help of Monoid (from ScalaZ) and if the case permits it, I defined an implementation of &lt;i&gt;Interceptor&lt;/i&gt;&amp;nbsp;that append the successive results one after the another. Reducing and simplifying the composition. Like so:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2938623.js?file=dummyMonoidComposition.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Note: we used the classical&amp;nbsp;case class. Thanks to an&amp;nbsp;&lt;i&gt;implicit def&lt;/i&gt;&amp;nbsp;that wraps the&amp;nbsp;&lt;i&gt;Intercept&lt;/i&gt; into the Monoid implementation, using the TypeClass bound declaration. &lt;a href="https://github.com/andypetrella/steal-play2/blob/master/app/steal/intercept.scala#L106" target="_blank"&gt;see&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;
What will come next&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
The next step I've already started is to try using &lt;a href="https://github.com/milessabin/shapeless" target="_blank"&gt;Shapeless&lt;/a&gt;&amp;nbsp;to avoid the composition boilerplate. Things are ongoing. Stay tune for that.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
One step further, I'll add another parameter to the &lt;i&gt;steal&lt;/i&gt;&amp;nbsp;callback, which will be the optional result&amp;nbsp;of the previous computations of other interceptors. That in order to combine them at the function and result levels.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And probably, add all boileplate my self that creates the tuples out-of-th-box in the compose function.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;i&gt;That's all folks!&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/kS5TfE4SnM4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/6616326932131956907/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/06/attempt-of-play20-action-interceptor.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6616326932131956907?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6616326932131956907?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/kS5TfE4SnM4/attempt-of-play20-action-interceptor.html" title="An Attempt of Play2.0 Action Interceptor" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/06/attempt-of-play20-action-interceptor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU4ERX84fSp7ImA9WhVaFE0.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-7331980204120090814</id><published>2012-06-11T11:45:00.000+02:00</published><updated>2012-06-11T11:45:04.135+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-11T11:45:04.135+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="rest" /><category scheme="http://www.blogger.com/atom/ns#" term="async" /><category scheme="http://www.blogger.com/atom/ns#" term="functional" /><category scheme="http://www.blogger.com/atom/ns#" term="monad" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="monad transformer" /><category scheme="http://www.blogger.com/atom/ns#" term="non-blocking" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>How Monad Transformer saved my time</title><content type="html">&lt;br /&gt;
&lt;h2&gt;
Context&lt;/h2&gt;
&lt;br /&gt;
These days (this week-end) I wanted to put some work on a &lt;a href="https://github.com/andypetrella/neo4j-rest-play-plugin" target="_blank"&gt;Neo4J Rest driver&lt;/a&gt; that I'm writing for Play 2.0 in Scala.&lt;br /&gt;
The only thing I wanted, actually, is to have the current embryo more functional. I mean &lt;i&gt;I was throwing exceptions&lt;/i&gt; (frightening... huh!).&lt;br /&gt;
Since this driver is meant to be fully asynchronous (man... it's http, it MUST be) and &amp;nbsp;non-blocking (Play's philosophy), I was hardly using the &lt;code&gt;Promise&lt;/code&gt; thing via the use of the WS api of Play.&lt;br /&gt;
This is the kind of thing I've got (briefly):&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; def getNode(id:Int) : Promise[Neo4JElement]&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Where &lt;code&gt;Neo4JElement&lt;/code&gt; stands for the wrapper of all Neo4J Rest response (Json). Hence, it can be either a &lt;b&gt;Failure&lt;/b&gt; response (Json with stacktrace and message), it can be a &lt;b&gt;Node&lt;/b&gt;, or .... throw an &lt;b&gt;Exception&lt;/b&gt; (br...) when the service crashed (f.i.).&lt;br /&gt;
&lt;br /&gt;
Hmm, not so intuitive and goes against the functional paradigm that orders: "you can't ever introduce side-effects, boy!". An exception that blows in my face, is one side effect (head-aches, ...).&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;strike&gt;Diego&lt;/strike&gt;&amp;nbsp;Validation to the rescue&lt;/h2&gt;
&lt;br /&gt;
Validation is a very simple thing, it holds either a value, either an error...&lt;br /&gt;
Ok, why not just &lt;code&gt;Either&lt;/code&gt; then. Actually, you're right but &lt;code&gt;Validation&lt;/code&gt; that I took in the ScalaZ library contains a lot of thing very helpful for the purpose of validation. But if you worry it, just replace &lt;code&gt;Validation&lt;/code&gt; by &lt;code&gt;Either&lt;/code&gt; in your mind from here.&lt;br /&gt;
Now, here is the &lt;code&gt;getNode&lt;/code&gt; signature:&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; def getNode(id:Int) : Promise[Validation[Aoutch, Node]]&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Isn't it more intuitive? For sure, you get back our relevant type in the signature : &lt;code&gt;Node&lt;/code&gt;. Great!&lt;br /&gt;
&lt;br /&gt;
So far, so good now what the heck is &lt;code&gt;Aoutch&lt;/code&gt; : something that hurts... and what could hurt a runtime execution... exceptions yeah! Thus, &lt;code&gt;Aoutch&lt;/code&gt; is just a shortcut for &lt;code&gt;Either[NonEmptyList[String], Failure]&lt;/code&gt;. We can see that we represent with one single type an &lt;i&gt;unexpected exception&lt;/i&gt; and a &lt;i&gt;failure&lt;/i&gt; (missing node f.i.).&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Monad&lt;/h2&gt;
&lt;br /&gt;
&lt;small&gt;If you don't know what a Monad is, from here thing about a structure that can evolve in a for-comprehension (in scala it must implement &lt;code&gt;flatMap&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt;).&lt;/small&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;Promise&lt;/code&gt; and &lt;code&gt;Validation&lt;/code&gt; are Monads. And their used one over the another. But what really interests us is the leaf of the chain &lt;code&gt;Node&lt;/code&gt;. That introduced some boilerplate code when you try to sequence actions like that:&lt;br /&gt;
&lt;script src="https://gist.github.com/2909215.js?file=without.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
See... yes we have to skip the first level (validation) to be able to work with the meaningful objects.&lt;br /&gt;
But still that we can extract some pattern... no?&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Monad Transformer&lt;/h2&gt;
&lt;br /&gt;
The pattern that we can extract is kind of two-level composition. I did this composition my-self trying to figure out what we'll be possible.&lt;br /&gt;
It was successful but, I've have to introduce a new type and a new method, that was like a &lt;code&gt;flatMap&lt;/code&gt;.&lt;br /&gt;
So I asked on StackOverflow ^^ (and it was my first question, yeepeee). You can find it &lt;a href="http://stackoverflow.com/questions/10968057/async-computation-with-validation-in-scala-using-scalaz" target="_blank"&gt;here&lt;/a&gt;. So I want explain how I did, because the question explains it. But the real question was, &lt;b&gt;is there a well-known functional construction for this problem?&lt;/b&gt;.&lt;br /&gt;
Thanks to @purefn, I knew that it was the case!&lt;br /&gt;
&lt;br /&gt;
It was time to use &lt;i&gt;Monad Transformer&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Monad Transformer&lt;/h2&gt;
&lt;br /&gt;
Briefly (and very roughly), a Monad Transformer is a construction that is able to transform a &lt;code&gt;M[N[_]]&lt;/code&gt; into a &lt;code&gt;P[_]&lt;/code&gt;, where M, N, P are Monads.&lt;br /&gt;
I won't explain here how it does, because it would be long, but here is a good &lt;a href="http://en.wikibooks.org/wiki/Haskell/Monad_transformers" target="_blank"&gt;link&lt;/a&gt;&amp;nbsp;(you've to understand Haskell a bit, sorry).&lt;br /&gt;
With the help of such transformer, you'll get you back the opportunity to use for-comprehension... with the wrapped-twice type as bound value.&lt;br /&gt;
Here is the the transformer for our &lt;code&gt;Promise[Validation[E, A]]&lt;/code&gt;:&lt;br /&gt;
&lt;script src="https://gist.github.com/2909215.js?file=monadTransformer.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
And how we can now link nodes:&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/2909215.js?file=with.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Awesome! No! We get 3 async and non-blocking calls, totally typed checked and resistant to exceptions and failures... In 5 lines.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Future work&lt;/h2&gt;
&lt;br /&gt;
At the SO question, @purefn tolds me that scalaz 7 (snapshot) is defining (fully) this kind of &lt;i&gt;Validation Transformer&lt;/i&gt;.&lt;br /&gt;
Why didn't I used it, yet:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;I'm trying to use not Snapshot (not a good reason, but still)&lt;/li&gt;
&lt;li&gt;In order to use &lt;code&gt;ValidationT&lt;/code&gt;, I'll have first to create an instance of the Type Class &lt;code&gt;Monad&lt;/code&gt;. Because the &lt;code&gt;flatMap&lt;/code&gt; signature needs it in the context.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
&lt;br /&gt;
I love functional (even if I'm still learning -- back -- the basis ^^)&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/UjXzeDnQCKw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/7331980204120090814/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/06/how-monad-transformer-saved-my-time.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/7331980204120090814?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/7331980204120090814?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/UjXzeDnQCKw/how-monad-transformer-saved-my-time.html" title="How Monad Transformer saved my time" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/06/how-monad-transformer-saved-my-time.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4NQXk4fip7ImA9WhVWEU0.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-8488312540226309020</id><published>2012-04-22T17:03:00.000+02:00</published><updated>2012-04-22T17:03:10.736+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-22T17:03:10.736+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="stress" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><category scheme="http://www.blogger.com/atom/ns#" term="gatling" /><title>Gatling and Play2.0: continued</title><content type="html">This blog entry is a follow-up of this &lt;a href="http://ska-la.blogspot.com/2012/03/gatling-tool-plugin-for-play-20.html" target="_blank"&gt;entry&lt;/a&gt;&amp;nbsp;where I introduced a spike I did on Play 2.0 stress tested using &lt;a href="http://gatling-tool.org/" target="_blank"&gt;Gatling-tool&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
At the time writing the above entry, I had to quickly hack gatling to use Akka 2.0 as Play 2.0 uses it, and I didn't wanted to have clashes.&lt;br /&gt;
&lt;br /&gt;
But, thanks to &lt;a href="https://twitter.com/#!/slandelle" target="_blank"&gt;Stéphane Landelle&lt;/a&gt;,&lt;b&gt; Gatling is now Akka 2.0 enabled &lt;/b&gt;(since 1.1.2).&lt;br /&gt;
&lt;br /&gt;
So that, it was time to give the &lt;a href="https://github.com/andypetrella/gatling-play2-plugin" target="_blank"&gt;plugin&lt;/a&gt;'s embryo a refresh. For that I used another &lt;a href="https://github.com/andypetrella/neo4j-play2.0-plugin-test" target="_blank"&gt;project&lt;/a&gt; that aims testing the &lt;a href="https://github.com/andypetrella/neo4j-rest-play-plugin" target="_blank"&gt;neo4j rest plugin&lt;/a&gt; for Play2.0 I'm also writing. In case of, I've also introduced what I did in this project in this &lt;a href="http://ska-la.blogspot.com/2012/04/still-playing-but-new-players-are-in.html" target="_blank"&gt;post&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Content&lt;/h2&gt;
Using the Gatling I first tested how I've been able to stress test:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;simple (get) urls&lt;/li&gt;
&lt;li&gt;mutating (post) urls using server&amp;nbsp;&lt;a href="http://www.playframework.org/documentation/2.0/ScalaForms" target="_blank"&gt;form&lt;/a&gt; underground to compile excepted data.&lt;/li&gt;
&lt;li&gt;duration tests (stress testing on a given period basis)&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
What I liked so much, even in this embryos+, is the ease to create stress tests when coupled with Play2.0 functionalities and Gatling's DSL.&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;
Foreword&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
The Gatling plugin I'm currently building is located on github &lt;a href="https://github.com/andypetrella/gatling-play2-plugin" target="_blank"&gt;here&lt;/a&gt;&amp;nbsp;and is based on sbt to build it.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But it's based on the version 1.1.4-SNAPSHOT version of Gatling's libraries (due to some fixes the Stéphane did "for me", while he was at devoxx fr, isn't he gentle !!!).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #f3f3f3;"&gt;&lt;i&gt;At the time writing, you'll have to build &lt;a href="https://github.com/excilys/gatling" target="_blank"&gt;gatling&lt;/a&gt; and &lt;a href="https://github.com/excilys/gatling-highcharts" target="_blank"&gt;gatling-highcharts&lt;/a&gt; locally using maven (quick fast!).&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;
How to&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
Set up&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Having created a Play 2.0 app, you now have to powerful of sbt in hands (especially if you've installed the TypeSafe stack 2.0). So, to stress test your app, you'll have first to build to plugin I told above.&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Plugin&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
First of all, clone/fork this library project on github&amp;nbsp;&lt;a href="https://github.com/andypetrella/gatling-play2-plugin" target="_blank"&gt;plugin&lt;/a&gt;, after what, you'll just have to run&amp;nbsp;&lt;code&gt;sbt publish-local&lt;/code&gt; in the related folder. That's it, you now have the plugin in your local repo.&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Project&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
In your Play 2.0 app, you now are able to define the plugin as `test` dependency, using the following&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=deps.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
That's it...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
Use&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Specs&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
Personally, for testing I use&amp;nbsp;&lt;i&gt;org.specs2.Specification&lt;/i&gt;, for using it with the plugin (at the time writing) you'll have to create the following:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=boilerplate.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
This listing is creating a fake server to enable urls to be tested, and some functions to deal with it.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To create the server, the plugin defines a Util object (&lt;i&gt;be.nextlab.play.gatling.Util&lt;/i&gt;), which also defines rough helpers to be used in stress tests.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
A full spec should look the following:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=gatling-specs.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Simple Url&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
You saw, in the provided gist above, that Util also defines a way to simply defines a gatling Simulation (basically a Function0 that returns a scenario builder: Gatling DSL result).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Having that in hand, here is the fragment to stress test the root url:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=root_stress_test.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As you can see, it's pretty simple, but nothing can really be checked in the body of the specs (I'm working on having relevant information to check).&lt;/div&gt;
&lt;div&gt;
But, at least you can run this test to hit 10 times the root url ramping the numbers of users by 2.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Running it (&lt;i&gt;sbt test&lt;/i&gt;) you'll have a new &lt;i&gt;gatling&lt;/i&gt;&amp;nbsp;folder in your target folder that contains a &lt;i&gt;&amp;nbsp;results&lt;/i&gt;&amp;nbsp;directory where are located all stress results in an html report (with great charts)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And all you had to do is to define the request headers and the url...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Mutating the server&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
If you have controllers that mutates the server, you should have define POST urls, which are using the Form feature provided by Play 2.0.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Having did so, you'll be able to stress it very easily using Map, JsObject or in the best case your &lt;b&gt;Model&lt;/b&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Let's say we have a controller &lt;code&gt;controllers.Stuffs&lt;/code&gt; that uses case classes &lt;code&gt;models.Stuff&lt;/code&gt;. The controller defines a &lt;i&gt;stuffForm&lt;/i&gt;&amp;nbsp;and a &lt;i&gt;createStuff&lt;/i&gt;&amp;nbsp;action.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Your stress test can now be defined like the following:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=mutating-server.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In the gist, you can see 5 points to note, they are key-clues to create reusable stress tests.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Nothing is really hardcoded, neither the path to the http end point nor the parameters data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;That's http stress testing using &lt;span style="background-color: yellow;"&gt;type checked&lt;/span&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;&lt;/span&gt;requests&lt;/b&gt;. CoOl isn't it? Hey, man, we got back our lovin' type cheking (one of the best scala feature).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;
Heavy check, duration based&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
This part is more a Gatling feature highlighting.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This last example is an heavy test that uses looping over a configuration for a given period. This gives you how many users could use your application.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Such test might be shaped the following:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2464268.js?file=heavy_test.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;
Note&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
For now, it's &lt;b&gt;NOT&lt;/b&gt;&amp;nbsp;an official plugin neither a gatling nor a play 2.0 one, but discussions are on the way for that... stay tuned on &lt;a href="https://twitter.com/#!/noootsab" target="_blank"&gt;twitter&lt;/a&gt; or here.&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/UAt0mr1ZFuQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/8488312540226309020/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/04/gatling-and-play20-continued.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/8488312540226309020?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/8488312540226309020?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/UAt0mr1ZFuQ/gatling-and-play20-continued.html" title="Gatling and Play2.0: continued" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/04/gatling-and-play20-continued.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkECSHk8eyp7ImA9WhVXF00.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-3066728397177952222</id><published>2012-04-18T00:11:00.000+02:00</published><updated>2012-04-18T00:11:09.773+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-18T00:11:09.773+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="d3.js" /><category scheme="http://www.blogger.com/atom/ns#" term="html5" /><category scheme="http://www.blogger.com/atom/ns#" term="akka" /><category scheme="http://www.blogger.com/atom/ns#" term="heroku" /><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="cloudbees" /><category scheme="http://www.blogger.com/atom/ns#" term="rest" /><category scheme="http://www.blogger.com/atom/ns#" term="bootstrap" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="graph" /><category scheme="http://www.blogger.com/atom/ns#" term="spine.js" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Still Playing... but new players are in</title><content type="html">&lt;h2&gt;
Why?&lt;/h2&gt;
Because I love to play, with &lt;a href="http://www.playframework.org/" target="_blank"&gt;Play 2.0&lt;/a&gt;&amp;nbsp;and&amp;nbsp;scala (still learning).&lt;br /&gt;
But also because I'm currently investigating technologies that I might choose for a new product line currently building in my company, &lt;a href="http://www.nextlab.be/" target="_blank"&gt;NextLab&lt;/a&gt; (in Belgium).&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;




With ?&lt;/h2&gt;
This time, I've more played with client side libraries or frameworks (no I won't post yet another entry on JQuery...), but I also tried how it is easy to create totally async code (so parallelized) using server side ones.&lt;br /&gt;
The technologies that will be quickly introduced in this post can be found hereafter, but everything has been packaged in a &lt;a href="https://github.com/andypetrella/neo4j-play2.0-plugin-test" target="_blank"&gt;github&lt;/a&gt; repo, and a running &lt;a href="http://neo4j-play20-plugin-test.herokuapp.com/" target="_blank"&gt;&lt;span style="background-color: yellow; color: blue;"&gt;&lt;b&gt;instance&lt;/b&gt;&lt;/span&gt;&lt;/a&gt; on &lt;a href="http://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
At first the current spike was dedicated to the slowly growing &lt;a href="https://github.com/andypetrella/neo4j-rest-play-plugin" target="_blank"&gt;Play 2.0's Neo4J REST plugin&lt;/a&gt;, we are creating at NextLab. But, in order to demonstrate what could be done with the coupling of these two technologies, I've extended the spike's scope to something more funny.&lt;br /&gt;
&lt;br /&gt;
So let's introduce the technologies:&lt;br /&gt;
&lt;h4&gt;




Client Side&lt;/h4&gt;
&lt;div&gt;
&lt;h5&gt;




&lt;a href="http://twitter.github.com/bootstrap/"&gt;Twitter Bootstrap&lt;/a&gt;&lt;/h5&gt;
An amazing toolbelt helping building responsive website without having to bother boilerplates in HTML, CSS. &lt;br /&gt;
&lt;br /&gt;
Even if it is neat, complete and well thought, Bootstrap comes with another handy factor... it has been built using LESS. And by chance (I know, chance is not part of the equation) LESS is supported by Play 2.0 by default.&lt;br /&gt;
&lt;br /&gt;
Just a note, LESS will let you reuse color codes, mixins, etc etc that Bootstrap has already defined.&lt;br /&gt;
&lt;h5&gt;




&lt;a href="http://spinejs.com/"&gt;Spine.js&lt;/a&gt;&lt;/h5&gt;
As we'll below, we'll have to discuss with WS (json), upon which a REST interface has been added for meaningful resources.&lt;br /&gt;
&lt;br /&gt;
That's where Spine.js comes in the game. This lightweight MVC library brought me the small tools that I needed for fetching, saving resources without having to write not even a single request by hand...&lt;br /&gt;
&lt;h5&gt;



&lt;a href="http://mbostock.github.com/d3/"&gt;d3.js&lt;/a&gt;&lt;/h5&gt;
Probably my favorite&amp;nbsp;(that might be my mathematician part who's talking), this powerful Data-Drive Document toolkit has taken the right thing by the right end.&lt;br /&gt;
&lt;br /&gt;
Its functional approach of decoupling data from the document, and link them using layouts helps you to concentrate on each part of the data usage independently:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;the incoming/rought data mapping to a representative data&lt;/li&gt;
&lt;li&gt;the mapping from represented data to document (most of the time, one data for one element)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h4&gt;




Communication&lt;/h4&gt;
The communication layer is of course HTTP, with a little help from the emerging HTML5 features. One in particular, Server-Sent Events (&lt;a href="http://www.html5rocks.com/en/tutorials/eventsource/basics/"&gt;here&lt;/a&gt; is a great intro).&lt;br /&gt;
&lt;br /&gt;
This, stable, HTML5 feature comes with the handy functionality to let the server sent events to connected client, without hacks; that said Comet or Polling.&lt;br /&gt;
&lt;br /&gt;
Open a connection, push data, and that ONLY when the server needs to.&lt;br /&gt;
&lt;div&gt;
&lt;h4&gt;




Server Side&lt;/h4&gt;
&lt;h5&gt;



&lt;span style="font-size: small;"&gt;
Play 2.0 (Scala)&lt;/span&gt;&lt;/h5&gt;
Of course... But I used some "advanced" feature like,&lt;br /&gt;
&lt;h6&gt;



&lt;span style="font-size: x-small;"&gt;
Async&lt;/span&gt;&lt;/h6&gt;
Async is a Play 2.0 feature that let the server deal with the tasks it has to schedule.&lt;br /&gt;
&lt;br /&gt;
That is, when you think that the server might have to wait for actions being executed before being able to respond a request, Play 2.0 let you, really simply, create Async request (non blocking).&lt;br /&gt;
&lt;br /&gt;
Very handy when you have to call third parties services for instance...&lt;br /&gt;
&lt;div&gt;
&lt;h6&gt;



&lt;span style="font-size: x-small;"&gt;
Iteratee&lt;/span&gt;&lt;/h6&gt;
&lt;/div&gt;
&lt;div&gt;
The only way I would consider from now to consume data. Iteratee is a fairly difficult thing to understand (read this &lt;a href="https://github.com/playframework/Play20/wiki/Iteratees"&gt;wiki&lt;/a&gt;) but it gives you the same smart decomposition that in d3.js, that is, decoupling the management of a sources, its useful representation and its computed result.&lt;/div&gt;
&lt;h5&gt;




&lt;a href="http://akka.io/"&gt;&lt;span style="font-size: x-small;"&gt;Akka&lt;/span&gt;&lt;/a&gt;&lt;/h5&gt;
Powerful, actor-based, parallelizer, asynchronous task, scheduler library.&lt;br /&gt;
&lt;br /&gt;
Actually I needed, a request to launch async tasks (you know like event generation and dispatching)... so what else!&lt;br /&gt;
&lt;h5&gt;




&lt;a href="http://neo4j.org/"&gt;Neo4J&lt;/a&gt;&lt;/h5&gt;
A database for storing graph... let's use a graph database.&lt;br /&gt;
&lt;br /&gt;
Within NextLab, we started a open sourced &lt;a href="https://github.com/andypetrella/neo4j-rest-play-plugin"&gt;Play2.0 plugin&lt;/a&gt; for calling the REST api provided by a Neo4J Server (helpful on Heroku). It's still emerging, and continue to evolve a lot because features are implemented on the fly (need), and a re-pass is forecasted to add a meaningful DSL (like &lt;a href="https://github.com/FaKod/neo4j-scala"&gt;FaKod&lt;/a&gt; did).&lt;br /&gt;
&lt;br /&gt;
Why do we make this choice to implement a distinct plugin instead of wrapping the java library?&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;yet another library, which brings me too much (I need REST only)&lt;/li&gt;
&lt;li&gt;I want requests being async and under control&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;




Libraries Repo&lt;/h4&gt;
See below, we'll use Heroku. So in order to deploy this application wich uses our plugin, I needed to publish somewhere.&lt;br /&gt;
&lt;br /&gt;
This is what can offer &lt;a href="http://www.cloudbees.com/"&gt;Cloudbees&lt;/a&gt;.&amp;nbsp;Among other great things like git repo, CI and so on, Cloudbees provides you &lt;b&gt;for free&lt;/b&gt; four maven repositories that you can make public if you wish.&lt;br /&gt;
&lt;br /&gt;
So I used sbt to publish on my "snapshot" repo on cloudbees, letting heroky has access to it for downloading the plugin dependency.&lt;br /&gt;
&lt;h4&gt;




Platform&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
Free, reliable, easy to use with scala and Play 2.0... which else than &lt;a href="http://www.heroku.com/"&gt;Heroku&lt;/a&gt;?&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;



&lt;/h2&gt;
&lt;h2&gt;




So what&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
I think that this post is already too long... However, I can let you play with the resulting app &lt;a href="http://neo4j-play20-plugin-test.herokuapp.com/"&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Check out the code (and fork it) &lt;a href="https://github.com/andypetrella/neo4j-play2.0-plugin-test"&gt;there&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Depending on the comment, I will expand this post to other ones to respond potential demands (if there is any ^^).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Good play.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Oh yes, one last note, the application is to &lt;b&gt;Create Stuff&lt;/b&gt; which contains dummies. Stuff are created using a simple form that must be fulfilled. Stuffs can be linked one to another by clicking the graph.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Please create Stufs and links, it will be a good test for Neo4J, the plugin and Play 2.0.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Hope you've reach this.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
SMAK. &lt;span style="font-size: xx-small;"&gt;hehe&lt;/span&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/l0rMRxeAOcE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/3066728397177952222/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/04/still-playing-but-new-players-are-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3066728397177952222?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3066728397177952222?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/l0rMRxeAOcE/still-playing-but-new-players-are-in.html" title="Still Playing... but new players are in" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/04/still-playing-but-new-players-are-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ENR3w7fip7ImA9WhVRFEg.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-1036139682725467555</id><published>2012-03-22T22:28:00.000+01:00</published><updated>2012-03-22T22:28:16.206+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-22T22:28:16.206+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="help" /><category scheme="http://www.blogger.com/atom/ns#" term="typesafe" /><category scheme="http://www.blogger.com/atom/ns#" term="sbt" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>TypeSafe Stack 2.0 missing "play debug" like feature</title><content type="html">A quick one to help players that are using TypeSafe stack instead of the Play! 2.0 distribution package.&lt;br /&gt;
Because I discussed some points on the groups and I saw related StackOverflow entries, that this post might &amp;nbsp;avoid in the future ^^.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
TypeSafe Stack&lt;/h3&gt;
&lt;br /&gt;
With its second version, the &lt;a href="http://typesafe.com/stack" target="_blank"&gt;TypeSafe stack&lt;/a&gt; stroke a hit integrating &lt;a href="http://akka.io/" target="_blank"&gt;Akka 2.0&lt;/a&gt;, &lt;a href="http://www.playframework.org/" target="_blank"&gt;Play 2.0&lt;/a&gt; and... its amazing &lt;a href="http://typesafe.com/products/console" target="_blank"&gt;console&lt;/a&gt; built on top of &lt;a href="http://www.mrspeaker.net/2012/03/15/typesafe-console/" target="_blank"&gt;both&lt;/a&gt; technologies.&lt;br /&gt;
&lt;br /&gt;
With the &lt;a href="http://scala-ide.org/" target="_blank"&gt;Scala IDE 2.0&lt;/a&gt;&amp;nbsp;(yeah a lot of 2.0), this stack is ready to tackle the SpringSource Tool Suite, but I don't want to make the comparison here neither explain all of these components... would be long and longer.&lt;br /&gt;
&lt;br /&gt;
But once you've installed the stack and you want to Play! around, they recommend you to use the giter8 template from the &lt;i&gt;&lt;a href="https://github.com/typesafehub" target="_blank"&gt;typesafehub&lt;/a&gt;&lt;/i&gt;&amp;nbsp;on github (it also contains a lot of plugins, which you might want).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
SBT instead of Play launcher&lt;/h3&gt;
&lt;br /&gt;
Using the stack, you won't have the play tool in your hands to generate application and so on, because the way to go is to use &lt;i&gt;g8&lt;/i&gt;&amp;nbsp;and &lt;i&gt;sbt&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
This is not an issue but there are some points you'll need to have in mind:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;the secret is not generated at creation&lt;/b&gt;: they're not so far, because the secret is only a random string, and an issue on giter8 is on-going. So, you can &lt;b&gt;create a random string by your own&lt;/b&gt; until it will be done. I've also proposed that a new command in sbt might be helpful to regenerate the secret.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;play debug&lt;/b&gt;&amp;nbsp;isn't available: when you need to debug your Play! 2.0 app you need sbt to activate the &lt;span style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;"&gt;&lt;span style="font-size: 14px; line-height: 18px;"&gt;&lt;i&gt;jdwp&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;when running. For that, there is a MVN_OPTS like &lt;b&gt;SBT_OPTS&lt;/b&gt; that comes in your help. Set it with the regular options&amp;nbsp;(&lt;i&gt;-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999&lt;/i&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
HTH&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/kre-S4MCc0s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/1036139682725467555/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/03/typesafe-stack-20-missing-play-debug.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1036139682725467555?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1036139682725467555?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/kre-S4MCc0s/typesafe-stack-20-missing-play-debug.html" title="TypeSafe Stack 2.0 missing &quot;play debug&quot; like feature" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/03/typesafe-stack-20-missing-play-debug.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcCSXY6fSp7ImA9WhVSF0s.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-3026369611200307290</id><published>2012-03-15T00:01:00.000+01:00</published><updated>2012-03-15T00:01:08.815+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-15T00:01:08.815+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="stress" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><category scheme="http://www.blogger.com/atom/ns#" term="gatling" /><title>Gatling-Tool Plugin for Play 2.0</title><content type="html">&lt;div&gt;
&lt;h2&gt;

Goal&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
This post will be a kind of write-up of what I'm trying to do now. And for what I already achieved some tasks.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Since I'll soon start products in my company that will be based on technologies like Scala, Play 2.0, Neo4J, MongoDB, Heroku and misc, and that I'm a bit control freak; I wanted to be sure that what I'll build will mach the requirements in terms of capacity.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This is where Gatling-Tool comes in the equation, this is a very powerful (and scala based) stress testing tool, which the name recall.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We're about to have some words on it, but first let me tell you that a GitHub ready to be fork is available with my first step into a gatling plugin, find it &lt;a href="https://github.com/andypetrella/gatling-play2-plugin" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;

Gatling Tool&lt;/h2&gt;
&lt;div&gt;
&lt;a href="http://gatling-tool.org/" target="_blank"&gt;Gatling Tool&lt;/a&gt; is a cute, smart and intuitive stress testing tool for web application, which a neat DSL for http request and asserts.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The DSL written in scala, and following the good conventions for it will aim anybody to be able to write stress tools. In a way that even non-programmer peoples with a basic understanding will be able to do basic stress tests with a good learning curve.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
It's integration with browsers (Firefox, through a proxy) ease much more the work because you'll be able to register like macros (or like &lt;a href="http://www.badboy.com.au/" target="_blank"&gt;badboy&lt;/a&gt; does) your scenario to be repeated again and again. This is what is called the &lt;a href="https://github.com/excilys/gatling/wiki/Gatling-Recorder" target="_blank"&gt;recorder&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Scenarios could be written with a custom external DSL, but they're also available as regular scala code (internal DSL) and there is where the coupling with Play 2.0 scala should pay.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;

Integration with Play2.0&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;

Akka 2.0&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Fact: since the RC-5, Play 2.0 comes with the Akka 2.0 support. &lt;/div&gt;
&lt;div&gt;
Fact: Gatling being it-self based on Akka (and they're right for that) but on a previous version for the stable version (logical because Akka 2.0 is pretty new).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So an integration must go through an update of the Gatling-Tool to the same version of Akka 2.0 in order to be able to use them correctly using the same project (testing phase, but still).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
That's why I decided to fork the Gatling-Tool on GitHub (aaah the great world of open source), in order to switch the support of Akka from their 1.x to 2.0.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Even if it is true that I did it roughly (at first), it remains that it works and is the two needed projects for the following are:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;https://github.com/andypetrella/gatling&lt;/li&gt;
&lt;li&gt;https://github.com/andypetrella/gatling-highcharts&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
So fork, clone them and build them locally using maven using the classical &lt;code&gt;mvn clean install&lt;/code&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You'll have a brand new version of gatling 1.1.0-SNAPSHOT.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;NOTE&lt;/u&gt;&lt;/b&gt;: I had some difficult choices when doing the migration, some are breaking the runtime behavior (a bit) and I'll have to discuss them further with the Gatling team. I've already been contacted by &lt;a href="https://twitter.com/#!/slandelle" target="_blank"&gt;Stéphane Landelle&lt;/a&gt;&amp;nbsp;who told me that we was interested by the work since it was planned the 1.2 release.&lt;/div&gt;
&lt;div&gt;
So don't be afraid, the official release will match the needs soon. (But ping me if you want more info and help me.)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;

Typesafe Stack 2.0&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
I recommend you to install this brand new stack that integrates all stuffs that you'll need for scala development, including Play 2.0 project.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Now, simply follows this &lt;a href="http://typesafe.com/stack/download" target="_blank"&gt;link&lt;/a&gt; for further steps, and then create a play-scala project.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;

Sbt&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Since Play 2.0 is using Sbt for building its project, and the custom gatling library we built is in our .m2 repo, we have first to add our local maven repo to the repositories list this way (updating your Build.scala):&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2039848.js?file=Build.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Tada, now we have a Play 2.0 project having our custom gatling as dependency.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;

Plugin&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Before going in further details with integrating Gatling as a Play 2.0 plugin, I'm gonna talk about an uncovered subject in Play 2.0 (or not easy to track); the Plugin feature.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Play 2.0 comes with a pretty easy simple Plugin integration, this through the specific file, in the &lt;i&gt;conf&lt;/i&gt;&amp;nbsp;folder, named &lt;i&gt;play.plugins&lt;/i&gt;. This file is meant to contain one single line by&amp;nbsp;&lt;u&gt;defined&lt;/u&gt;&amp;nbsp;plugin, shaped this way: &lt;code&gt;{priority}:{plugin's class path}&lt;/code&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But what is a plugin finally, this is a classical class extending &lt;i&gt;play.api.Plugin...&amp;nbsp;&lt;/i&gt;simply. This &lt;i&gt;Plugin&lt;/i&gt;&amp;nbsp;trait only defines three methods which are:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;onStart: this adds a hook when the application starts, helpful for initializing objects.&lt;/li&gt;
&lt;li&gt;onStop: cleaning the fields.&lt;/li&gt;
&lt;li&gt;enabled: helpful to disable the plugin in some specific cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Another point, that I have to highlight is that it &lt;u&gt;seems&lt;/u&gt;&amp;nbsp;that such Plugin's constructor must have an argument being the &lt;i&gt;application&lt;/i&gt; it-self.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;

Test only&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
Hey wait gatling should be available in tests only ?! Right!&lt;/div&gt;
&lt;div&gt;
The first way to achieve this is the easies also, while implementing &lt;i&gt;isEnabled&lt;/i&gt;, you can use the &lt;i&gt;application&lt;/i&gt; (remember it is part of the constructor) which has a method &lt;i&gt;isTest&lt;/i&gt;&amp;nbsp;that should toggle the plugin.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The second way is to create a Specification that starts a FakeServer (since we'll stress the entire Play 2.0 flows) and give it a FakeApplication which is defined with the Plugins you wish. 1000 words replaced by one Gist:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2039848.js?file=TestStress_brief.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4&gt;

Gatling integration&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
Now you're wondering what the heck is that Gatling Plugin class, don't you?&lt;/div&gt;
&lt;div&gt;
&lt;h5&gt;

Gatling Plugin&lt;/h5&gt;
&lt;/div&gt;
&lt;div&gt;
The &lt;a href="https://github.com/andypetrella/gatling-play2-plugin/blob/master/test/gatling/Gatling.scala" target="_blank"&gt;Gatling&lt;/a&gt; plugin class, located in my repo under the &lt;i&gt;test/gatling&lt;/i&gt; folder, is extending the &lt;i&gt;play.Plugin&lt;/i&gt;&amp;nbsp;class (which defines dummy implementation of the three methods), this way I can concentrate on the only method I need, &lt;i&gt;onStart&lt;/i&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Actually I need some initialization in order to use gatling, it needs some folder to be defined, including the one interesting use the more: &lt;i&gt;results&lt;/i&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So, the &lt;i&gt;Gatling#onStart&lt;/i&gt;&amp;nbsp;method is creating ephemeres folders under the target directory (that can be cleaned) and also the needed Gatling configuration file. &lt;u&gt;And that's it&lt;/u&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We can now stress test our app.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h5&gt;
How?&lt;/h5&gt;
&lt;/div&gt;
&lt;div&gt;
Gatling is able to understand Scala written scenarios, those Scala script have only one constraint: being an instance of&amp;nbsp;&lt;i&gt;com.excilys.ebi.gatling.core.scenario.configuration.Simulation&lt;/i&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This trait is actually a &lt;i&gt;Function0&lt;/i&gt;&amp;nbsp;and thus defines only one helpful method which is &lt;i&gt;apply()&lt;/i&gt;. The latter method is the container for building the stress test that we want to execute.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What is very common now is that you can write Gatling scenarios using the Scala Type System being checked in your favorite IDE, and they will be compiled by Sbt it self when requested (and hot swapped ^^). Where the classical Gatling workflow is to compile them on the fly, using their internal routines.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h5&gt;
Run 'em&lt;/h5&gt;
&lt;/div&gt;
&lt;div&gt;
Having simulations written (example &lt;a href="https://github.com/andypetrella/gatling-play2-plugin/blob/master/test/stress/SampleSimulations.scala" target="_blank"&gt;here&lt;/a&gt;), you can now ask Gatling to run them by creating a gatling runner instance on them. I won't go into deep details because it is not the purpose here, but here is how you can do.&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2039848.js?file=RunAndGenerate.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h5&gt;
See 'em in action&lt;/h5&gt;
&lt;/div&gt;
&lt;div&gt;
That's the easiest part, entering the play environment using &lt;code&gt;sbt&lt;/code&gt; in console, you can launch the tests by typing &lt;code&gt;test&lt;/code&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What'll be done is:&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;enter the specification&lt;/li&gt;
&lt;li&gt;create the fake application&lt;/li&gt;
&lt;li&gt;load the additional plugin&lt;/li&gt;
&lt;li&gt;create the gatling folder and conf&lt;/li&gt;
&lt;li&gt;configure the gatling system&lt;/li&gt;
&lt;li&gt;create the fake server on 3333&lt;/li&gt;
&lt;li&gt;create the simulations&lt;/li&gt;
&lt;li&gt;run them&lt;/li&gt;
&lt;li&gt;generate reports on them (located in the target folder =&amp;gt; look 'em in your browser and you'll see how they're cute)&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;h2&gt;
Problems&lt;/h2&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
There are problems for now when executing several tests, because streams are closed (while generating further reports), that comes from a choice that I've have to do and which is commented on github &lt;a href="https://github.com/andypetrella/gatling/commit/270c11eb14509ae253b1fdf20650c01f26feb1f5#L14R147" target="_blank"&gt;here&lt;/a&gt;. This is mainly related to a feature that is no more available in Akka 2.0 (for good reasons, I'd say).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;
To be continued&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
If you want to help me going further, don't hesitate to contact me on my mailbox, or comment this post or on &lt;a href="https://twitter.com/#!/noootsab" target="_blank"&gt;twitter&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What I like to have in the future is :&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;clear Specification for Gatling (preventing the need to define each time the server and plugin)&lt;/li&gt;
&lt;li&gt;website for enabling test one by one, or any, or...&lt;/li&gt;
&lt;li&gt;redirecting to results reports&lt;/li&gt;
&lt;li&gt;more&lt;/li&gt;
&lt;li&gt;and more&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/BB318mjD8Lc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/3026369611200307290/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/03/gatling-tool-plugin-for-play-20.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3026369611200307290?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3026369611200307290?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/BB318mjD8Lc/gatling-tool-plugin-for-play-20.html" title="Gatling-Tool Plugin for Play 2.0" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/03/gatling-tool-plugin-for-play-20.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYHQXw5eCp7ImA9WhJTE0w.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-65572432298568585</id><published>2012-03-11T13:12:00.001+01:00</published><updated>2012-06-21T22:22:10.220+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-21T22:22:10.220+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="salat" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="mongodb" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Play 2.0 and Salat (MongoDB DAO provider)</title><content type="html">&lt;br /&gt;
&lt;h1&gt;









Play 2.0 using MongoDB document storage through Salat&lt;/h1&gt;
&lt;br /&gt;
In this post, I'll cover some points and library that ease such use case.&lt;br /&gt;
&lt;br /&gt;
I won't go into deep details about Play and MongoDB, instead I'll jump straight to the MongoDB usage.&lt;br /&gt;
&lt;br /&gt;
Let's talk a bit about Salat&lt;br /&gt;
&lt;h2&gt;









Salat&lt;/h2&gt;
This free library available on github &lt;a href="https://github.com/novus/salat" target="_blank"&gt;here&lt;/a&gt;&amp;nbsp;(and deployed on ivy repo, so that easily usable with sbt and Play) is able to deal with case classes and MongoDB as we'd do with JPA.&lt;br /&gt;
&lt;br /&gt;
That say, &lt;i&gt;case classes&lt;/i&gt; can be used directly for storing document by simply declaring a DAO and with the help of some annotations (not mandatory).&lt;br /&gt;
&lt;h3&gt;








Grater&lt;/h3&gt;
Salat as the notion of Grater that is responsible to the de/serialization of a case class. This through two simple functions, let have a Grater for the type T:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;asDBObject(t:T) &lt;/i&gt;: returns a MongoDB representation of &lt;i&gt;t&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;asObject(dbo:DBObject)&lt;/i&gt;&amp;nbsp;: returns a T instance based on the provided MongoDB content&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The latter thing to note is how to create such Grater? What do we have to do? The answer is &lt;i&gt;almost nothing&lt;/i&gt;, in the package &lt;i&gt;com.novus.salat&lt;/i&gt;&amp;nbsp;is available the very handy method&amp;nbsp;&lt;i&gt;grater[Y &amp;lt;: AnyRef]&lt;/i&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What that grater method does is to parse your case class provided as the method generic, and create the related Grater instance. The important thing to note at this stage is that the latter Grater is &lt;b&gt;cached&lt;/b&gt;&amp;nbsp;for further needs.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So now, you're already able to deal with you case class. What is missing is the DAO part, that will ease again your job.&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;








SalatDAO&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Salat provides another handy structure named &lt;i&gt;SalatDAO&lt;/i&gt;. This trait defines all lifecycle operations that you might need for your domain objects.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Its usage is very simple, you just have to define an object that extends this trait by giving the Domain Specific class and Id type for your structure. The last parameter it needs is a reference to the collection.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is an excerpt I pulled from the salat &lt;a href="https://github.com/novus/salat/wiki/SalatWithPlay" target="_blank"&gt;wiki&lt;/a&gt;:&lt;br /&gt;
&lt;span class="k" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;code&gt;object&lt;/code&gt;&lt;/span&gt;&lt;code&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt; &lt;/span&gt;&lt;span class="nc" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #445588; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;UserDao&lt;/span&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt; &lt;/span&gt;&lt;span class="k" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;extends&lt;/span&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt; &lt;/span&gt;&lt;span class="nc" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #445588; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SalatDAO&lt;/span&gt;&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;[&lt;/span&gt;&lt;span class="kt" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #445588; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;User&lt;/span&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt;, &lt;/span&gt;&lt;span class="kt" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #445588; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;ObjectId&lt;/span&gt;&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;](&lt;/span&gt;&lt;span class="n" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;collection&lt;/span&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt; &lt;/span&gt;&lt;span class="k" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;=&lt;/span&gt;&lt;span style="background-color: white; color: #333333; line-height: 19px;"&gt; &lt;/span&gt;&lt;span class="nc" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #445588; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;DB&lt;/span&gt;&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;.&lt;/span&gt;&lt;span class="n" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;connection&lt;/span&gt;&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;(&lt;/span&gt;&lt;span class="s" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #dd1144; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;"users"&lt;/span&gt;&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;))&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;






&lt;span class="o" style="background-color: white; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Play 2.0&lt;/span&gt;&lt;/h2&gt;
&lt;span style="color: #333333;"&gt;Having covered the basic of Salat, it's time to use it in our Play 2.0 application.&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #333333;"&gt;There is a cool wiki page, that I wished have discovered before which explain how to use salat with Play 1.2.x. I recommend you to &lt;/span&gt;&lt;a href="https://github.com/novus/salat/wiki/SalatWithPlay" target="_blank"&gt;read it&lt;/a&gt;&lt;span style="color: #333333;"&gt;, even if I'm gonna cover some of the important steps here too.&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #333333;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;






&lt;span style="color: #333333;"&gt;Dependencies&lt;/span&gt;&lt;/h3&gt;
&lt;span style="color: #333333;"&gt;This step is more easy that for the previous version of Play. Because now the only two things required are:&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="color: #333333;"&gt;add the novus repo&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #333333;"&gt;add the deps to salat&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style="color: #333333;"&gt;Both in the Build.scala in the project folder of your Play 2.0 app.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;**Edit (on 21th June 2012)**&lt;/b&gt;&lt;br /&gt;
Before you continue, this post that explains some basics about how to deal with Salat and Play, you can now choose to simply move to this module&amp;nbsp;&lt;a href="https://github.com/novus/salat/wiki/SalatWithPlay2"&gt;https://github.com/novus/salat/wiki/SalatWithPlay2&lt;/a&gt;.&lt;br /&gt;
It introduced the tricks that I'll explain below, and add amazing functionalities for Model and DAO creation.&lt;br /&gt;
So starting at this point, it's no more mandatory to read this post... unless you're curious ;-)&lt;br /&gt;
&lt;b&gt;**end of EDIT**&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Context&lt;/b&gt;
&lt;br /&gt;
Here is the &lt;b&gt;main&lt;/b&gt;&amp;nbsp;thing I have to discuss here: Salat makes intensive usage of a structure named Context which holds a reference to what have been processed along the classes and structures.&lt;br /&gt;
&lt;br /&gt;
Such instance is created by default in the package object &lt;i&gt;com.novus.salat.global&lt;/i&gt;, and the quick start of Salat recommend to import it along with &lt;i&gt;salat&lt;/i&gt;&amp;nbsp;and &lt;i&gt;annotations&lt;/i&gt;. &lt;b&gt;&lt;span style="color: red;"&gt;Don't!&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
Doing so will fail when using &lt;b&gt;Play 2.0 in DEV&lt;/b&gt; mode (only) because of the cool-hot-reload-on-change feature of Play. The specific case where it will fail is the following:&lt;br /&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style="font-size: large;"&gt;If you want to keep a static reference to the Grater instance of a specific case class.&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;script src="https://gist.github.com/2016161.js?file=Model.scala"&gt;
&lt;/script&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Why? Because of the (needed for sure!) graters' cache which keeps a reference to the &lt;i&gt;Class&lt;/i&gt;&amp;nbsp;instance.&lt;/div&gt;
&lt;div&gt;
But this class instance might change on bytecode refresh, moreover the fact that Play has a specific ClassLoader for that (&lt;b&gt;ReloadableClassLoader&lt;/b&gt;).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The result is incomprehensible errors when you change your code, which errors saying the there is a mismatch between classes that you even not change yet...&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3&gt;



The solution (which is referred in the wiki page I told above)&lt;/h3&gt;
&lt;h3&gt;



&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Instead of importing &lt;i&gt;com.novus.salat.gobal._&lt;/i&gt;&amp;nbsp;which only contains an implicit definition of the Context object to use in Salat core system, create a new one using the correct ClassLoader.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/2016161.js?file=salatcontext.scala"&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In the above Gist, we can see that we simply created a Context that will refer to the provided ClassLoader by the Play app itself.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
That will keep enabled the class reloading, without impacting caches instances.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2&gt;



&lt;i&gt;That's all folks!&lt;/i&gt;&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
Now you're ready to use both Play 2.0 and Salat without messing around with conversion between DSM and MongoDB and so on.&lt;/div&gt;
&lt;div&gt;
Have a gode work.&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/XtyspKTBf0M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/65572432298568585/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/03/play-20-and-salat-mongodb-dao-provider.html#comment-form" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/65572432298568585?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/65572432298568585?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/XtyspKTBf0M/play-20-and-salat-mongodb-dao-provider.html" title="Play 2.0 and Salat (MongoDB DAO provider)" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>6</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/03/play-20-and-salat-mongodb-dao-provider.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcDSXY6eyp7ImA9WhVTFUg.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-2324391230343800062</id><published>2012-02-29T23:03:00.001+01:00</published><updated>2012-02-29T23:04:38.813+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-29T23:04:38.813+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="heroku" /><category scheme="http://www.blogger.com/atom/ns#" term="graph" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 9) :: Final</title><content type="html">&lt;h2 class="custom"&gt;

Note&lt;/h2&gt;
&lt;div&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html" target="_blank" title="part 4"&gt;this post&lt;/a&gt;&amp;nbsp;(which started &lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part.html"&gt;there&lt;/a&gt;), which is the last part of a blog suite that aims the use of Neo4j and Play2.0 together on &lt;a href="http://www.heroku.com/" target="_blank"&gt;Heroku&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
What have been accomplished so far:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;install Play 2.0&lt;/li&gt;
&lt;li&gt;install Neo4J&lt;/li&gt;
&lt;li&gt;use Dispatch&lt;/li&gt;
&lt;li&gt;create model&lt;/li&gt;
&lt;li&gt;create persistence service in Neo4J&lt;/li&gt;
&lt;li&gt;create views and controllers&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Ok, where almost done. Let's see how to deploy the whole app on Heroku.&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;h1&gt;




















Heroku, here I come&lt;/h1&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 class="custom"&gt;




















But wait, who're you?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
Heroku is simply one of the best cloud players of the moment, I won't talk too much about it, because i'd have to talk a lot otherwise.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But here are some very interesting features and paradigms followed by Heroku.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;


















Process Centric&lt;/h3&gt;
&lt;div&gt;
Where almost all other cloud providers are binding their services to server instances, CPU flop count, memory usages, and other similar metrics, it is a fact that their aren't easily forecastable and hard to track in development phases (even if I encouraged to do it, though).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Heroku comes with a much more easy concept, that is, &lt;i&gt;Web Dynos&lt;/i&gt;. A Web Dynos is simply a process&amp;nbsp;that can handle requests. So, what if the requests are too numerous? Just add Dynos. Note that Dynos are existsing for background process, one Dyno by worker.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Costs are very simple too, you have one free Dyno by month, and the rest is billed at low cost by hour.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks for simplicity.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
















Remote CLI&lt;/h3&gt;
&lt;div&gt;
We've just ask how to handle more requests in an efficient way, and answered by adding dynos.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So far so good, but how? That's where comes the Heroku remote CLI that is able to operate remotely on a deployed application behavior.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thus, adding a dyno is doing that in console : &lt;code&gt;$&amp;gt; heroku dynos 1&lt;/code&gt;&lt;/div&gt;
&lt;br /&gt;
Now, alerts on performance are quickly resolved.&lt;br /&gt;
&lt;br /&gt;
Thanks for rapidity.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
















Continuous Deployment&lt;/h3&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
The paradigm followed by Heroku to deploy their app are based on Continuous Deployment.&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
Having that, you app should define how you app must be deployed using their &lt;i&gt;Procfile&lt;/i&gt;.&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
And it will be deployed automatically when the sources are pushed to the Git repo that is created for each application.&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
This ensure you to at any time be able to retrieve the sources related to the running instance (for example).&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
Thanks for debugging ease.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-size: medium; font-weight: normal;"&gt;
&lt;/div&gt;
&lt;h3&gt;
















Add-Ons&lt;/h3&gt;
What to say? A good sdk to create add-ons, a good architecture and service level. It makes a pleiade of powerful add-ons including Neo4J running instances.&lt;br /&gt;
&lt;br /&gt;
Thanks to be open.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h2 class="custom"&gt;
















Can I &lt;i&gt;Play!&lt;/i&gt; with Heroku?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
Of course, you can!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Actually, Heroku has already integrated Play! starting with its first version, and has also added the scala support some time ago.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And finally the Play 2.0 &lt;a href="https://github.com/playframework/Play20/wiki/ProductionHeroku" target="_blank"&gt;wiki&lt;/a&gt; is explaining how to do...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 class="custom"&gt;


Ok, let's Go then.&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;

Getting started&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
First of all, you must have been registered too Heroku.&amp;nbsp;Hopefully, it's free and fast. So go on, and create your account &lt;a href="https://api.heroku.com/signup" target="_blank"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Having your account, you can now &lt;a href="http://devcenter.heroku.com/articles/quickstart#step_2_install_the_heroku_toolbelt" target="_blank"&gt;install&lt;/a&gt; the Heroku toolkit belt. This will gives you acces to your Heroku CLI that can manage your account, apps, and app configuration.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
When you're done with the installation, you just have to login using the console command: &lt;code&gt;$&amp;gt; heroku login&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3&gt;















Play! app side&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;br /&gt;
What is needed for your app is to have a Git repo and to contain a Heroku process description file.&lt;br /&gt;
Since everything is already explain &lt;a href="https://github.com/playframework/Play20/wiki/ProductionHeroku" target="_blank"&gt;there&lt;/a&gt;, I won't go into deep details.&lt;br /&gt;
&lt;div&gt;
&lt;h3&gt;















Create Heroku app&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Since we are using Play! and scala, we need a JVM, that stack at Heroku is called &lt;i&gt;&lt;a href="http://devcenter.heroku.com/articles/cedar" target="_blank"&gt;Cedar&lt;/a&gt;&lt;/i&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So, to create your app, open a shell and do the following:&lt;/div&gt;
&lt;code&gt;heroku create my-playing-app-with-neo4j --stack cedar&lt;/code&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;br /&gt;
Now, you have an up and running environment to setup and deploy your application. And the application will be named &lt;i&gt;my-playing-app-with-neo4j&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3&gt;














Neo4J add-on&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Ok, but I've to use a Neo4J database, not embedded (too heavy for a cloud). Do I have to install it somewhere and host it myself. Na!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Neo4J's team is actually working on an integration in the Heroku platform, and a beta test add-on is available at the time writing.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
That says that to have a running database that we can use, we just have to open a shell (in our app folder) and drop the following command:&amp;nbsp;&lt;code&gt;heroku addons:add neo4j&lt;/code&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
You don't believe it, huh?

&lt;br /&gt;
&lt;br /&gt;
Since you'll need to retrieve the database url and credentials, either you go to the Heroku site and...&lt;br /&gt;
Na, just keep your shell and do:&amp;nbsp;&lt;code&gt;heroku addons:open neo4j&lt;/code&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
Ta da!&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3&gt;












App update&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
In my previous post, for the sake of simplicity I left the Neo4J database hard coded to &lt;i&gt;localhost:7474&lt;/i&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But now, we have to update this to use our deployed Neo4J instance and credentials.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We should have (must) define an application configuration property for such paramater, but It is not what I want to illustrate here so let's keep it simple and hard coded.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But we have to add something to the Neo4J's Dispatch url, the credentials. For that we just have to do the following:&lt;/div&gt;
&lt;div&gt;
&lt;script src="https://gist.github.com/1944456.js?file=Neo4JRestService.scala"&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;h3&gt;






SSH key&lt;/h3&gt;
&lt;div&gt;
Just a note, to remember you to add your ssh key to Heroku. This is simply accomplished (after you've have created 'em) using the CLI: &lt;code&gt;$&amp;gt; heroku keys:add&lt;/code&gt;&lt;/div&gt;
&lt;br /&gt;
Beginning to love this CLI, no?&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;








Procfile&lt;/h3&gt;
&lt;div&gt;
This is the Heroku configuration file that tells the continuous deployer (if I can say) how the application will be deployed and are its needs.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This file is located at the root of the Play's application folder and only contains one line:&lt;/div&gt;
&lt;code&gt;web: target/start -Dhttp.port=${PORT} ${JAVA_OPTS}&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div&gt;
This simple line tells that we need a web process for the staging application located under target/start
&lt;/div&gt;
&lt;div&gt;
Actually, this folder will contains the staging Play! application after Heroku will run &lt;code&gt;sbt clean compile stage&lt;/code&gt; on it.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;






Aaaaand Deploy! (push)&lt;/h3&gt;
Getting closer to the end!&lt;br /&gt;
&lt;br /&gt;
After having added all the necessary sources to the local git repo for your app, (including last update and the Procfile), we can now commit everything and push it to the git repo that Heroku holds for our application.&lt;br /&gt;
&lt;br /&gt;
Actually, when created the Heroku app, the CLI has updated the git local configuration to add the related remote repo called &lt;i&gt;heroku&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
So, the only thing that left to do is to push: &lt;code&gt;$&amp;gt; git push heroku master&lt;/code&gt;
&lt;br /&gt;
To test if it is ok: &lt;code&gt;$&amp;gt; heroku ps&lt;/code&gt;. This will display the proceses running on Heroku.&lt;br /&gt;
&lt;br /&gt;
If the process is shown, let's open the application in our default brower (leave your mouse alone and...): &amp;nbsp;&lt;code&gt;$&amp;gt; heroku open&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
I hope that I didn't made too many mistakes and you are now able to see your application running and using Neo4J.&lt;br /&gt;
&lt;br /&gt;
At least, here is the one I succeed to deploy: &lt;a href="http://scala-plays-with-neo4j.herokuapp.com/"&gt;http://scala-plays-with-neo4j.herokuapp.com/&lt;/a&gt;.&lt;br /&gt;
I've also shared this app on Heroku's &lt;a href="http://gensen.herokuapp.com/" target="_blank"&gt;GenSen&lt;/a&gt; that is meant to share project template on Heroku.
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Now, you should love the CLI&lt;/span&gt;, but also Heroku, and Neo4J &lt;span style="font-size: x-small;"&gt;and Play! 2.0 and Scala&lt;/span&gt; &lt;span style="font-size: xx-small;"&gt;and Dispatch and arbor.js and...

&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;
Thanks for reading, if someone do have ^^.
&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/sAAoBrrLV-c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/2324391230343800062/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_29.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2324391230343800062?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2324391230343800062?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/sAAoBrrLV-c/neo4j-with-scala-play-20-on-heroku-part_29.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 9) :: Final" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_29.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYFRHk-eSp7ImA9WhVTFUg.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-3041431832099055995</id><published>2012-02-27T23:43:00.000+01:00</published><updated>2012-02-29T23:05:15.751+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-29T23:05:15.751+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="arbor" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="json" /><category scheme="http://www.blogger.com/atom/ns#" term="graph" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 8) :: Scala template+Arbor.js to browse Neo4J via Play 2.0</title><content type="html">&lt;br /&gt;
&lt;div&gt;
&lt;h2&gt;












Note&lt;/h2&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html" target="_blank" title="part 4"&gt;this post&lt;/a&gt;, which is the seventh part of a blog suite that aims the use of Neo4j and Play2.0 together on Heroku.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h1&gt;












Viewing Neo4J Model Object in Play2.0&lt;/h1&gt;
&lt;h2&gt;












Goal&lt;/h2&gt;
&lt;div&gt;
In this post, I'll talk about some functionalities that Play2.0 offers to create web application/site.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The main goal will be to have html views that enable us to create User, Group and link them, but not only, we'll use &lt;a href="http://arborjs.org/" target="_blank"&gt;arbor.js&lt;/a&gt; to view what's being created or linked in Neo4J as a... graph of course.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Basically, it will consist into one html page, containing several forms for creating model instance (or link) through AJAX call on Json controllers.&lt;br /&gt;
&lt;br /&gt;
So let's begin by explaining how to define a querying and persisting controllers using Play 2.0 &lt;i&gt;Form&lt;/i&gt;.&lt;br /&gt;
&lt;h2&gt;











Controllers&lt;/h2&gt;
&lt;div&gt;
&lt;/div&gt;
In that case, we'll take basic needs for our use case, that is, to retrieve the users list stored in Neo4J or create a new group.&lt;br /&gt;
&lt;h3&gt;











Get Users&lt;/h3&gt;
&lt;div&gt;
Briefly, Play 2.0 as the notion of controllers to handle server request, such controllers are bound to urls using a route configuration.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So what we have to do here is to create a controller, let's say &lt;i&gt;Users&lt;/i&gt;, with a handler named &lt;i&gt;j_all&lt;/i&gt;&amp;nbsp;for list of users rendered in Json.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Using what we've discussed in previous posts, such controller and definition are rather simple, check this out:&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/1927260.js?file=Users.scala"&gt;
&lt;/script&gt;
As we can see, we have simple call the Model persistence utility object to retrieve all defined User in Neo4J. Which we are rendering directly in Json thanks to their Formatter. And finally, we stream the result in the http response.&lt;br /&gt;
Mmmh, simple no ? Here we did:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;send a Json request to Neo4J requesting all nodes that are linked to the root using the kind &lt;i&gt;users&lt;/i&gt;&amp;nbsp;(found using the User's ClassManifest)&lt;/li&gt;
&lt;li&gt;retrieve the Json response from Neo4J and un-marshall them in a &lt;i&gt;List[User]&lt;/i&gt;&amp;nbsp;(using the User Formatter)&lt;/li&gt;
&lt;li&gt;re-render them into the expected Model Json Format (again using the Fomatter)&lt;/li&gt;
&lt;li&gt;generate the String representation&lt;/li&gt;
&lt;li&gt;append it in the response body&lt;/li&gt;
&lt;li&gt;define the content type as being Json&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
In one single line.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To test it, roughly, just use this url&amp;nbsp;&lt;a href="http://localhost:9000/users.json" target="_blank"&gt;http://localhost:9000/users.json&lt;/a&gt;. This will return a Json encoded response.&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;









Create Group&lt;/h3&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
Now, we want to add the possibility to create a new group remotely. For that, we'll create a controller &lt;i&gt;Groups&lt;/i&gt; which defines a &lt;i&gt;create&lt;/i&gt;&amp;nbsp;handler.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This handler expects to receive a group name. After what, it creates the group instance and persist it in Neo4J.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To recover such request parameter (in a POST since we are creating something and changing the server state), we use a Play 2.0 construction &lt;i&gt;play.api.data.Form&lt;/i&gt;&amp;nbsp;that offers a lot of helpers to parse the body into a map of values (can be embedded).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In the following example, the goup name is extracted form the request's body (url encoded) as a &lt;i&gt;nonEmptyText&lt;/i&gt;&amp;nbsp;mapped as &lt;i&gt;name&lt;/i&gt;. This is a helper mapping for extracting String that cannot be empty.&lt;/div&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/1927260.js?file=Groups.scala"&gt;
&lt;/script&gt;

As we can see, the Form can be directly rendered in the Model instance by giving an apply and unapply functions after the mapping definition.&lt;br /&gt;
&lt;div&gt;
&lt;h2&gt;






Javascript Routing&lt;/h2&gt;
&lt;div&gt;
Using static urls are cool... no ok, let's try to use what some calls Web 2.0, you know Ajax.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The problem comes when you have to deal with Urls within Ajax calls. How to keep track of your urls changes for instances.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Pretty hard, so let's forget about hard coded urls in your javascript and use a routes file that can be downloaded client side. This routes file contains all your controllers' url mapping that you want to be exposed in javascript (if I can say).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
How it works is simple:&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;Use &lt;i&gt;&lt;a href="https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/Routes.scala" target="_blank"&gt;Routes&lt;/a&gt;.javascriptRouter&lt;/i&gt; to define a javascript object and the controllers to be remoted&lt;/li&gt;
&lt;li&gt;For each of them, you must use the following object&amp;nbsp;&lt;i&gt;controllers.routes.javascript.&lt;controller&gt;.&lt;function&gt;&lt;/function&gt;&lt;/controller&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;This object is created at compile time when defining the controller in the route conf file&lt;/li&gt;
&lt;li&gt;defines a handler (in the Application controller f.i.) that return the result of the javascriptRouter as being javascript file&lt;/li&gt;
&lt;li&gt;route this new controller to what you want (like &lt;i&gt;/js/routes&lt;/i&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Having done that, you are now ready to use the created object in the javascript part.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If we take the controller &lt;i&gt;controllers.Users.j_one&amp;nbsp;&lt;/i&gt;(returns a User base on its given id), we'll have in our javascript access to a js function&amp;nbsp;&lt;i&gt;playRoutes.controllers.Users.j_one(id)&lt;/i&gt;&amp;nbsp;that can takes an id.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
By using this js function, you'll have in return a js object that defines at least two useful properties:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;url: the formatted url for the controller (having compiled the parameter in the url)&lt;/li&gt;
&lt;li&gt;ajax(c): a jquery (by default) ajax function that takes a payload object, but already defines the url and the method.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
So far so good, but to use all of these stuffs, let's see in a coffeescript (thanks &lt;a href="https://github.com/playframework/Play20/wiki/AssetsCoffeeScript" target="_blank"&gt;Play 2.0&lt;/a&gt;) example:&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/1927260.js?file=get_users.coffee"&gt;
&lt;/script&gt;

In the previous example, I wrote the ajax call my-self using jQuery... so I could have simply use the ajax property. But nevermind, I love sometime to be control freak.
&lt;br /&gt;
&lt;br /&gt;
C'est chic! No?&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;






Arbor.js&lt;/h2&gt;
&lt;div&gt;
For browsing our model graph, I've used arbor.js as the rendering framework, because it's the best one for graph... that's it.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Since my intent here isn't to explain it, I'll leave you alone with that part. But I recommend you to browse its site &lt;a href="http://arborjs.org/" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
So what I did is simply using Users as nodes, all linked to a central root node. Clicking one them will show you their inter-relationships.&lt;br /&gt;
&lt;br /&gt;
I've also added a select box that helps you showing all users in a chosen group.&lt;br /&gt;
&lt;br /&gt;
Taking that the next post will be on how to deploy the whole stuff on Heroku. I don't have at this time any instance in the wild, but if you wish you can clone (and fork) &lt;a href="https://github.com/andypetrella/Play20WithNeo4J" target="_blank"&gt;my repo on github&lt;/a&gt; for this posts' suite.&lt;br /&gt;
&lt;br /&gt;
But here is a preview of what has been achieved.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-UHeP3vJf3WA/T0wGNElHqTI/AAAAAAAAAwE/CnPvABqf-Pg/s1600/neo4j-and-play2.0.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="355" src="http://2.bp.blogspot.com/-UHeP3vJf3WA/T0wGNElHqTI/AAAAAAAAAwE/CnPvABqf-Pg/s400/neo4j-and-play2.0.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Fun but not so cute &amp;nbsp;-&amp;gt; I'm not a designer... :'(&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
Next &lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_29.html"&gt;post&lt;/a&gt;, the last, will talk about how to deploy this whole thing onto the Heroku PaaS.&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/7TY8Pa-CRXQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/3041431832099055995/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_27.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3041431832099055995?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/3041431832099055995?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/7TY8Pa-CRXQ/neo4j-with-scala-play-20-on-heroku-part_27.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 8) :: Scala template+Arbor.js to browse Neo4J via Play 2.0" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-UHeP3vJf3WA/T0wGNElHqTI/AAAAAAAAAwE/CnPvABqf-Pg/s72-c/neo4j-and-play2.0.tiff" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_27.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEANQH0zcSp7ImA9WhVTE0U.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-4249707833241997051</id><published>2012-02-25T00:40:00.000+01:00</published><updated>2012-02-27T23:46:31.389+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-27T23:46:31.389+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sjson" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="json" /><category scheme="http://www.blogger.com/atom/ns#" term="dispatch" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 7) :: DSM+DAO+Neo4J+Play</title><content type="html">&lt;br /&gt;
&lt;div&gt;
&lt;h2&gt;












Note&lt;/h2&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_21.html" target="_blank" title="part 4"&gt;this post&lt;/a&gt;, which is the sixth part of a blog suite that aims the use of Neo4j and Play2.0 together on Heroku.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h1&gt;












Using Neo4J in Play 2.0... and simple DAO&lt;/h1&gt;
&lt;div&gt;
What I'll intent to show is a way to use a Domain Specific Model, persisted in a Neo4J back end service. For such DSM, we'll have an abstract magic Model class that defines generic DAO operations.&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
For simplicity, we'll try to link each category of classes to the root/entry node. For instance, all the Users will be bound to the entry node by a reference of kind &lt;i&gt;user&lt;/i&gt;.&lt;/div&gt;
&lt;h3&gt;








Model&lt;/h3&gt;
I'll choose the very common use case, that is, Users and Groups. Here is its shape:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;A User has a first name&lt;/li&gt;
&lt;li&gt;A Group has a name&lt;/li&gt;
&lt;li&gt;A User can be in several Groups&lt;/li&gt;
&lt;li&gt;A Group can contain several Users&lt;/li&gt;
&lt;li&gt;A User can know several Users&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Let's keep the classes definition aside for a few, and stick to the persistence service.&lt;/div&gt;
&lt;h3&gt;







Graph Service&lt;/h3&gt;
&lt;div&gt;
The Graph Service is an abstraction of what is needed for a Graph Persistence Layer. It is bound to a generic type that defines the model implementation and defines traversal and persistence operations of graph's nodes.
&lt;/div&gt;
&lt;script src="https://gist.github.com/1903936.js?file=GraphService.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;





Graph Service for Neo4J&lt;/h3&gt;
&lt;div&gt;
Let's update now, the service that has been used in the previous post, for Neo4J persistence, in order to have it able to deal with model instance.&lt;br /&gt;
&lt;br /&gt;
Let's start with the &lt;i&gt;saveNode&lt;/i&gt;&amp;nbsp;operation to see what is needed in the model and elsewhere.&lt;/div&gt;
&lt;script src="https://gist.github.com/1903936.js?file=Neo4JRestService_1.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;div&gt;
In this Gist above, I've enlighted some points that must be found around the Model construction. (A) and (C) are composing a Json Format (as SJson propose), (B) is more related to model abstraction.&lt;br /&gt;
&lt;br /&gt;
(C) has a special need when used with Dispatch, we could have a Dispatch Handler that can do both action parsing/unmarshalling and direct use in a continuation.
&lt;/div&gt;
&lt;h4&gt;





Model&lt;/h4&gt;
Now, we are at the right point to talk the Model, since we've met almost all its requirement. So let's build a Magic Model class that can be extended by all concrete model classes.
&lt;br /&gt;
&lt;h5&gt;





Skeleton&lt;/h5&gt;
That's the easy part, we just define the id property that is an id (part of the Rest Url in Neo4J).
&lt;br /&gt;
&lt;h5&gt;





Formatter&lt;/h5&gt;
&lt;div&gt;
Ok, this part is simple too in this abstract Model definition because, a Format implementation must be part of the concrete DSM classes. That is, &lt;i&gt;User&lt;/i&gt; that extends &lt;i&gt;Model&lt;/i&gt; must define a &lt;i&gt;Format[User]&lt;/i&gt; instance, and put it in the implicit context.
&lt;/div&gt;
&lt;div&gt;
So, at this stage we have Model and User like this:
&lt;/div&gt;
&lt;script src="https://gist.github.com/1903936.js?file=ModelUser_1.scala"&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;h5&gt;





Class -- Relation's kind : F-Bounded&lt;/h5&gt;
As we saw in the &lt;i&gt;saveNode&lt;/i&gt; method needs to associate the concrete class to a relation kind. But what I wanted is to have a &lt;i&gt;save&lt;/i&gt; method in Model, that implies that we cannot (at first glance) give the &lt;i&gt;saveNode&lt;/i&gt; the information needed, that is the concrete class.&lt;br /&gt;
&lt;br /&gt;
For that, we'll use a F-Bounded type for Model, that way we'll be able to give the &lt;i&gt;saveNode&lt;/i&gt; method what is the really class... Mmmh ok, let me show you:

&lt;script src="https://gist.github.com/1903936.js?file=Model_FBounded.scala"&gt;
&lt;/script&gt;

But that's not sufficient, the &lt;i&gt;saveNode&lt;/i&gt; method will need to use such available &lt;i&gt;ClassManifest&lt;/i&gt; to find the relation it must create.&lt;br /&gt;
&lt;br /&gt;
I choose a very common and easy solution, which is having a function in the Model companion that helps in registering classes against relation kind.

&lt;script src="https://gist.github.com/1903936.js?file=ModelObject.scala"&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;h4&gt;




Model Dispatch Handler&lt;/h4&gt;
&lt;div&gt;
Now we'll discuss something I find really useful and easy in Dispatch, create a Handler that can handle a Json response from Neo4J into a Model instance.&lt;br /&gt;
For that, we have already defined in previous post a way to handle json response into Play's JsValue.&lt;br /&gt;
&lt;br /&gt;
Now, what we need is to use the implicit formatter of all model concrete classes to create instances. And it'll be the way to reach the goal, except that a problem comes from the Json response of Neo4J: the data is not present at the Json root, but is the value of the data property.&lt;br /&gt;
So it breaks our Format if we use it directly.&lt;br /&gt;
&lt;br /&gt;
That's why the above definition of the Handler takes an extra parameter which is the conversion between JsValue to JsValue, that is to say, a function that goes directly to the data definition.

&lt;script src="https://gist.github.com/1903936.js?file=ModelHandlers.scala"&gt;
&lt;/script&gt;

&lt;/div&gt;
&lt;h4&gt;




saveNode&lt;/h4&gt;
&lt;div&gt;
Finally, let's gather all our work in a simple implementation of a generic saveNode function:
&lt;script src="https://gist.github.com/1903936.js?file=saveNode.scala"&gt;
&lt;/script&gt;

As we can see, it's very easy to handle Neo4J response as DSO and use them directly in the continuation method of the Handler.
&lt;/div&gt;
&lt;h3&gt;



Usage&lt;/h3&gt;
having all pieces in places (check out the related Git repo &lt;a href="https://github.com/andypetrella/Play20WithNeo4J" target="_blank"&gt;here&lt;/a&gt;).

We can now really simply create a User and retrieve it updated with its id, or even get it from the database using its id.

&lt;script src="https://gist.github.com/1903936.js?file=spec.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;hr /&gt;
In the next &lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_27.html"&gt;Post&lt;/a&gt;, we'll create some Play template for viewing such data, but create them also.&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/QQ6uko-lWkw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/4249707833241997051/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/4249707833241997051?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/4249707833241997051?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/QQ6uko-lWkw/neo4j-with-scala-play-20-on-heroku-part_25.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 7) :: DSM+DAO+Neo4J+Play" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcHRHo7fSp7ImA9WhVTEU8.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-1369586308355189817</id><published>2012-02-21T00:29:00.000+01:00</published><updated>2012-02-25T00:43:55.405+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-25T00:43:55.405+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="rest" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="json" /><category scheme="http://www.blogger.com/atom/ns#" term="dispatch" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 6) :: Dispatch+Play 2.0</title><content type="html">&lt;div&gt;
&lt;h2&gt;













Note&lt;/h2&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_2470.html" target="_blank" title="part 4"&gt;this post&lt;/a&gt;, which is the fifth part of a blog suite that aims the use of Neo4j and Play2.0 together on Heroku.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h1&gt;











Using Neo4J in Play 2.0&lt;/h1&gt;
In this post, we'll create a Dispatch Handler that handles Neo4J Rest Json calls in Play's Json object.&lt;br /&gt;
Having this in our hands, we'll be able to create a really simple service for dispatching Neo4J operations and use them in Play's views.&lt;br /&gt;
&lt;br /&gt;
I've compiled the Play app on github, &lt;a href="https://github.com/andypetrella/Play20WithNeo4J" target="_blank"&gt;fork me&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
NB: we'll use Dispatch but in case you wish to, you could use the Play's WS feature that might help you a lot (&lt;a href="https://github.com/playframework/Play20/wiki/ScalaWS" target="_blank"&gt;check this out&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;






Declare Dispatch deps&lt;/h2&gt;
First of all, we have to update our Play app with the Dispatch dependency. For that, we have to update the sbt configuration file in order to add the related line.&lt;br /&gt;
&lt;script src="https://gist.github.com/1872053.js?file=Build.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
Now, that we have updated the project, let update the application by reloading the configuration (if you're already in sbt console) and rebuild our IDEA project.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/1872053.js?file=gistfile1.sh"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;



Play's Json Handler&lt;/h2&gt;
Our goal is to use the Neo4J Rest Api that returns responses Json encoded.&lt;br /&gt;
So here, I'll show how we could have such response directly unmarshalled in Json object. In further posts, we'll use such handling feature to get Model instances directly (which is far more interesting).&lt;br /&gt;
&lt;br /&gt;
What is necessary for that is to create a piece of code that is capable to take a subject and convert it to a JsValue. And since we love functional programming, let us have this method taking a continuation that accepts a JsValue.&lt;br /&gt;
&lt;script src="https://gist.github.com/1872053.js?file=handler.scala"&gt;
&lt;/script&gt;

In this listing, we see that we use the text parser to consume the response payload, then we ask the Play's Json parse function do its job.&lt;br /&gt;
Finally, we use the continuation applied to the parsed result.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Neo4J Service&lt;/h2&gt;
Let's gather some utility urls to retrieve node, relations. In other words, urls for common usages.
This service is left simple for further enhancements (next post).
&lt;script src="https://gist.github.com/1872053.js?file=basic_neo4j.scala"&gt;
&lt;/script&gt;
We see that most functions are there to create urls based on ids, but there is also the root one that directly fetches the entry node.

&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



A Controller To Rule Them All&lt;/h2&gt;
For the sake of this basic usage of our Handler with Neo4J, here are some examples of such requests. (full controller &lt;a href="https://github.com/andypetrella/Play20WithNeo4J/blob/master/app/controllers/Neo4J.scala" target="_blank"&gt;here&lt;/a&gt;).&lt;br /&gt;
&lt;script src="https://gist.github.com/1872053.js?file=controller.scala"&gt;
&lt;/script&gt;
As we can see, all we had to do is to create the correct url by using id, or Neo4J path conventions, then using the Handler operator (&amp;nbsp;&lt;span style="background-color: white; font-family: 'Bitstream Vera Sans Mono', 'Courier New', monospace; font-size: 12px; font-weight: bold; line-height: 16px; text-align: left; white-space: pre;"&gt;&amp;gt;!&amp;nbsp;&lt;/span&gt;... how it's Play, no ?!), we have the facility to use directly JsValue instance to consume the result.&lt;br /&gt;
Okay, it's repetitive and the Json traversal is not shared. Let's us put this aside until the next post.&lt;br /&gt;
And before going ahead, I've created a pretty simple and naive view and url mapping. So check the sources on github, play it and tests the &lt;i&gt;/rest&lt;/i&gt;&amp;nbsp;et al. urls.&lt;br /&gt;
&lt;hr /&gt;
&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html"&gt;Next post: Enhance the handler and service to manage Domain Object.&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/e-ivagHEnno" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/1369586308355189817/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_21.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1369586308355189817?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1369586308355189817?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/e-ivagHEnno/neo4j-with-scala-play-20-on-heroku-part_21.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 6) :: Dispatch+Play 2.0" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_21.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkECSX89fCp7ImA9WhRaF0U.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-2517362842129918768</id><published>2012-02-19T22:32:00.001+01:00</published><updated>2012-02-21T00:31:08.164+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-21T00:31:08.164+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="http" /><category scheme="http://www.blogger.com/atom/ns#" term="dispatch" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 5) :: Dispatch</title><content type="html">&lt;h2&gt;




Note&lt;/h2&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/note-this-post-is-continuation-of-this.html" target="_blank" title="part 4"&gt;this post&lt;/a&gt;, which is the fourth part of a blog suite that aims the use of Neo4j and Play2.0 together on Heroku.&lt;br /&gt;
&lt;h1&gt;




Intro&lt;/h1&gt;
In this suite, we're gonna use Neo4J graph database through its HTTP REST api, which is quickly introduced in &lt;a href="http://noootsab.tumblr.com/post/17172741154/neo4j-with-scala-play-2-0-on-heroku-part-2" target="_blank" title="Neo4J"&gt;this post&lt;/a&gt;.&lt;br /&gt;
So that, we'll have to communicate with the server using HTTP, here comes the &lt;a href="http://dispatch.databinder.net/" target="_blank" title="Dispatch wiki"&gt;Dispatch&lt;/a&gt; scala library.&lt;br /&gt;
Neo4J uses Json as the resources representation, we've already discussed this subject in Play 2.0 in &lt;a href="http://noootsab.tumblr.com/post/17447408368/neo4j-with-scala-play-2-0-on-heroku-part-4" target="_blank" title="Json and Play 2.0"&gt;this post&lt;/a&gt;.&lt;br /&gt;
How to stick them together will be discussed in the next post.&lt;br /&gt;
Here we'll concentrate on some introduction to Dispatch's DSL for making HTTP requests and on a powerful abstraction of the body parser, that is, the &lt;a href="http://dispatch.databinder.net/Response+Bodies.html" target="_blank" title="Parse Bodies"&gt;Handlers&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;




Dispatch&lt;/h1&gt;
&lt;h2&gt;




The DSL&lt;/h2&gt;
Dispatch is a very powerful library for communicating through the HTTP protocol, offering a DSL for making such queries, but also for using their responses.&lt;br /&gt;
Where we all know, that response can be of different content-type, the DSL presents easy handler for them.&lt;br /&gt;
Getting back to queries, an HTTP request has been given a method like GET or POST, when dealing with RESTful services, we'll see PUT and DELETE in the game.&lt;br /&gt;
When data must be provided we'll have to pass some arguments/parameters in the request payload (or url).&lt;br /&gt;
Let's see how those actors compose in the Dispatch's DSL.&lt;br /&gt;
&lt;h3&gt;




URL&lt;/h3&gt;
The url of the HTTP request is basically composed of the host and port, followed by path elements. Here is how to create an url such url&amp;nbsp;&lt;a href="http://dispatch.databinder.net/URLs+and+Paths"&gt;http://dispatch.databinder.net/URLs+and+Paths.html&lt;/a&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=url.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;




Attributes and Headers&lt;/h3&gt;
After having build a Request (see above), you now have access to some modifier on it.&lt;br /&gt;
The probably best way to learn all of them will to check the source code &lt;a href="https://github.com/dispatch/dispatch/blob/master/core/src/main/scala/requests.scala" target="_blank" title="Request"&gt;here&lt;/a&gt;.&lt;br /&gt;
But here is some examples:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=attr_headers.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;




Method&lt;/h3&gt;
The method is the quite more simple... juste append the name to the request, in order to change the method from 'GET' to another:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=methods.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;




Payload&lt;/h3&gt;
As for headers, you better check the code for know every tools, the library put in your hands. Here is some conventions I understood from the code:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=payload.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;




Executors&lt;/h2&gt;
Dispatch works with executors that execute the queries and accepts handlers for handling reponse.&lt;br /&gt;
Such response waiting is configurable by choosing among several implementations, the documentation is well suited on the &lt;a href="http://dispatch.databinder.net/Choose+an+Executor.html" target="_blank" title="Executor"&gt;wiki&lt;/a&gt;.&lt;br /&gt;
But in our case, what we need is synchronousity, because the RESTful service is also out backend service. So the executor comes with the `dispatch` package, this way:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=executor.scala"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;




Handlers (Response's Body)&lt;/h2&gt;
Here's come the &lt;strike&gt;s&lt;/strike&gt;fun... Handling responses.&lt;br /&gt;
Actually, this piece of code comes in the game just before we apply the request to the executor, but ok, let's takle it now.&lt;br /&gt;
A handler can also be called the response parser, that said, it is responsible to parse the whole content into a new form.&lt;br /&gt;
Some existing handlers are:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865900.js?file=handlers.scala"&gt;
&lt;/script&gt;
Basically, a handler defines an operator, a result type and takes a block that deals with such result type instance.&lt;br /&gt;
Some examples of such handlers are made on the wiki, especially for Json or html (&lt;a href="http://dispatch.databinder.net/Lift+JSON.html" target="_blank" title="Lift"&gt;here&lt;/a&gt;, &lt;a href="http://dispatch.databinder.net/TagSoup.html" target="_blank" title="tagsoup"&gt;here&lt;/a&gt; and &lt;a href="http://dispatch.databinder.net/JSoup.html" target="_blank" title="jsoup"&gt;here&lt;/a&gt;).&lt;br /&gt;
Others handlers exists by default, for redirecting to outstream, to compose or chain handlers.&lt;br /&gt;
&lt;hr /&gt;
In the &lt;a href="http://getting%20close%20to%20the%20real%20use%20of%20neo4j%20with%20play%21/"&gt;next post&lt;/a&gt;, we'll see how to use Neo4J Json Rest Api with Play! framework through Dispatch.&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/LJC21npnJtU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/2517362842129918768/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_2470.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2517362842129918768?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2517362842129918768?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/LJC21npnJtU/neo4j-with-scala-play-20-on-heroku-part_2470.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 5) :: Dispatch" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_2470.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMHQHs4fip7ImA9WhRaFkU.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-6807482360390535167</id><published>2012-02-19T22:19:00.000+01:00</published><updated>2012-02-19T22:20:31.536+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-19T22:20:31.536+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="json" /><category scheme="http://www.blogger.com/atom/ns#" term="sjon" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 4) :: Play 2.0/Json</title><content type="html">&lt;h2&gt;




Note&lt;/h2&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_19.html" target="_blank" title="part 3"&gt;this post&lt;/a&gt;, which is the thrid part of a blog suite that aims the use of Neo4j and Play2.0 together on Heroku.&lt;br /&gt;
&lt;h1&gt;




Play2.0 - Scala - Json&lt;/h1&gt;
I'm about to write a quick wrap up, of some Play20's &lt;a href="https://github.com/playframework/Play20/wiki/Scalajson" target="_blank" title="Main Json Page"&gt;wiki&lt;/a&gt; &lt;a href="https://github.com/playframework/Play20/wiki/ScalaJsonRequests" target="_blank" title="Json Request"&gt;entries&lt;/a&gt;&amp;nbsp;and &lt;a href="http://stackoverflow.com/questions/8695335/how-to-render-json-response-in-play-framework-v2-0-latest-build-from-git" target="_blank" title="Question on SO"&gt;stackoverflow&lt;/a&gt;&amp;nbsp;that were all related to Json in Play2.0.&lt;br /&gt;
For that, I'll take some usage examples, but also present the underlying libraries (&lt;a href="https://github.com/codahale/jerkson" target="_blank" title="Jerkson on Github"&gt;Jerkson&lt;/a&gt;) and the used paradigm, &lt;a href="http://debasishg.blogspot.com/2010/07/sjson-now-offers-type-class-based-json.html" target="_blank" title="SJson by debasishg"&gt;SJson&lt;/a&gt;.&lt;br /&gt;
&lt;h2&gt;




Scope&lt;/h2&gt;
Giving that the wiki pages are really clean and self-explaining, I'm not gonna enter deeply in how Json must be used with Play 2.0 albeit I'll give some prerequesites in order to help you understand how I'll use the Neo4J REST API.&lt;br /&gt;
&lt;h2&gt;




play.api.libs.json&lt;/h2&gt;
This package contains everything you'll need in order to work with Json in Play 2.0.&lt;br /&gt;
It defines important structure like &lt;em&gt;JsObject&lt;/em&gt;, &lt;em&gt;JsArray&lt;/em&gt; and even some like &lt;em&gt;JsUndefined&lt;/em&gt;.&lt;br /&gt;
They usage is very easy since they are based on classical scala's &lt;em&gt;Map&lt;/em&gt;&amp;nbsp;and &lt;em&gt;List&amp;nbsp;&lt;/em&gt;of&amp;nbsp;&lt;em&gt;JsValue&lt;/em&gt;(parent type).&lt;br /&gt;
Here is an example of creating a &lt;em&gt;JsArray&lt;/em&gt;&amp;nbsp;and iterating items. To test it in a REPL, I recommend you to enter the &lt;em&gt;Play console&lt;/em&gt; by using &lt;strong&gt;play&lt;/strong&gt; in your repo and the &lt;strong&gt;console&lt;/strong&gt;&amp;nbsp;in sbt (to have all libraries loaded).&lt;br /&gt;
&lt;script src="https://gist.github.com/1865780.js?file=play-repl-test.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
For arrays, it's quite easy (maybe wrapping could be annoying but a little of pimping can resolve that).&lt;br /&gt;
The Jerkson library powerful comes with &lt;em&gt;JsObject&lt;/em&gt;&amp;nbsp;usages. It has defined a very clean DSL for querying Json. Here is an example for querying a property or catch a descendant property.&lt;br /&gt;
&lt;script src="https://gist.github.com/1865780.js?file=play-repl-test.scala"&gt;
&lt;/script&gt;


&lt;br /&gt;
&lt;h2&gt;

play.api.libs.json.{Format, Reads, Writes}&lt;/h2&gt;
Until now, you saw that Json is usable with Play. But, I guess that you hope more than that, since this framework is here to ease the work.&lt;br /&gt;
And you're right.&lt;br /&gt;
Play is coming with a SJson flavor for serialization and deserialization of DSO.&lt;br /&gt;
Three traits come in the game.&lt;br /&gt;
&lt;h3&gt;




Reads&lt;/h3&gt;
Reads defines a simple method &lt;em&gt;reads&lt;/em&gt;:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=Reads.scala"&gt;
&lt;/script&gt;
Having a &lt;em&gt;Reads&lt;/em&gt; defined for a type T, we can now extract such instance from Json.&lt;br /&gt;
With the object &lt;em&gt;Reads&lt;/em&gt; that defines an &lt;em&gt;implicit Reads&lt;/em&gt; instance for most common types like &lt;em&gt;Option&lt;/em&gt;, &lt;em&gt;String&lt;/em&gt;, &lt;em&gt;Short&lt;/em&gt; ...&lt;br /&gt;
&lt;h3&gt;




Writes&lt;/h3&gt;
Writes, like Reads, is very simple and defines a simple method &lt;em&gt;writes&lt;/em&gt;:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=Writes.scala"&gt;
&lt;/script&gt;
Obviously, its purpose is to convert a value of type &lt;em&gt;T&lt;/em&gt; into its Json representation and is the inverse function &lt;em&gt;reads&lt;/em&gt;.&lt;br /&gt;
A &lt;em&gt;Writes&lt;/em&gt; object is defined too with conversion to common types.&lt;br /&gt;
&lt;h3&gt;




Format&lt;/h3&gt;
This trait is there to put the pieces together&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=Format.scala"&gt;
&lt;/script&gt;
With the help of this trait, we can now have a serializer of custom domain object from/to Json.&lt;br /&gt;
A good practice is to define such Format into the &lt;em&gt;companion&lt;/em&gt;&amp;nbsp;object of your DSO, so that it will come in the scope at once when using it.&lt;br /&gt;
Here is an example:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=example.scala"&gt;
&lt;/script&gt;
Let's see how to use this Format easily to go back and forth from DSO instances.&lt;br /&gt;
&lt;h2&gt;

play.api.libs.json.Json._&lt;/h2&gt;
This object is an handy one, that defines four convenient methods.   Two are here to play with String and JsValue. The other are to play with types and JsValue.&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=Json.scala"&gt;
&lt;/script&gt;
Back to our simple DSO class, we can now do this:&lt;br /&gt;
&lt;script src="https://gist.github.com/1865840.js?file=usage.scala"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h2&gt;




Enhancement&lt;/h2&gt;
In order to have more control on effects of your serialization, I would recommend you to consider the &lt;a href="http://code.google.com/p/scalaz/" target="_blank" title="Scalaz home page"&gt;Scalaz&lt;/a&gt; library's &lt;a href="https://github.com/scalaz/scalaz/blob/master/core/src/main/scala/scalaz/Validation.scala" target="_blank" title="Validation scala code"&gt;Validation&lt;/a&gt; construct.&lt;br /&gt;
Indeed, it will help you having more relevant information and all at once if you &lt;em&gt;reads&lt;/em&gt;&amp;nbsp;is wrong.&lt;br /&gt;
Here is a talk about &lt;a href="http://debasishg.blogspot.com/2011/02/applicatives-for-composable-json.html" target="_blank" title="Scalaz Validation SJson"&gt;this&lt;/a&gt; (but not in Play).&lt;br /&gt;
&lt;hr /&gt;
In the next post, we'll talk about the Dispatch library. See it &lt;a href="http://www.blogger.com/#" target="_blank" title="Dispatch"&gt;here&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/WDKnxtLxevQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/6807482360390535167/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/note-this-post-is-continuation-of-this.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6807482360390535167?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/6807482360390535167?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/WDKnxtLxevQ/note-this-post-is-continuation-of-this.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 4) :: Play 2.0/Json" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/note-this-post-is-continuation-of-this.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIASXg7fSp7ImA9WhVTFUg.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-5539821579814765799</id><published>2012-02-19T22:04:00.000+01:00</published><updated>2012-02-29T23:12:28.605+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-29T23:12:28.605+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="idea" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 3) :: Play 2.0/Idea</title><content type="html">&lt;h1&gt;


Play!2.0 Scala and Idea CI&lt;/h1&gt;
This post is a continuation of&amp;nbsp;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-this-post-is-continuation-of-this.html" target="_blank"&gt;this post&lt;/a&gt;, where I’ve introduced Neo4J and how to install it. But it requires that you already followed &lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part.html" target="_blank" title="install Play20"&gt;this post&lt;/a&gt;.&lt;br /&gt;
&lt;h2&gt;


Goal&lt;/h2&gt;
Event if the ScalaIDE 2.0 has just been &lt;a href="http://scala-ide.org/" target="_blank" title="scala ide"&gt;released&lt;/a&gt;. I still prefer Intellij for editing Scala, because even it's &lt;a href="http://www.jetbrains.com/idea/free_java_ide.html" target="_blank" title="idea ci"&gt;community edition&lt;/a&gt;&amp;nbsp;has a powerful and polish Scala support (after having installed the plugin...).&lt;br /&gt;
And while, playing with the 2.0 version of Play! you'll enjoy the use of CoffeeScript to heal your JS head aches, you'll also loved the CoffeeBrew plugin.&lt;br /&gt;
Here the goal is to help you create a Play! 2.0 RC1 scala project, update the sbt configuration for sbt-idea, and finally generate the IDEA module.&lt;br /&gt;
Having done such easy tasks, you'll have the full IDEA powerfull in your hands.&lt;br /&gt;
&lt;h2&gt;


Create the project&lt;/h2&gt;
First of all, we need to create the project for what we'll try to do (using Neo4J through it's REST API).&lt;br /&gt;
For that, you should have the &lt;em&gt;play&lt;/em&gt;&amp;nbsp;executable in your &lt;em&gt;PATH&lt;/em&gt;&amp;nbsp;setup, and able to run the following in console.&lt;br /&gt;
&lt;code&gt;play new Play20WithNeo4J&lt;/code&gt; Which will prompt you some questions, that you'll answer the following (no color question, don't worry but a little remark later if you're using Windows ^^):&lt;br /&gt;
&lt;code&gt; What is the application name? &amp;gt; &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;Play20WithNeo4J &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;Which template do you want to use for this new application? &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; 1 - Create a simple Scala application &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; 2 - Create a simple Java application &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; 3 - Create an empty project &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; &amp;gt; 1 &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; OK, application Play20WithNeo4J is created. &lt;/code&gt;&lt;br /&gt;
&lt;code&gt; Have fun! &lt;/code&gt;&lt;br /&gt;
Basically, it asks you the name of your app, and it's language (note that we've chosen the scala way).&lt;br /&gt;
&lt;h2&gt;


Setting sbt-idea&lt;/h2&gt;
Play! in the new 2.0 version is using sbt to configure the project and run tasks (such as deploy start/run and so on). The sbt version in used is the 0.11.2 at the time writing, and is embedded with the install.&lt;br /&gt;
So that, you can already launch the sbt console by either run &lt;em&gt;play&lt;/em&gt;&amp;nbsp;or &lt;em&gt;play console&lt;/em&gt;&amp;nbsp;to have all Play! deps on classpath.&lt;br /&gt;
Before running any command, let's modify some sbt conf files to have sbt-idea being able to create an IDEA module for our project.&lt;br /&gt;
Play 2.0 comes with a default configuration for sbt, so that, those files are already present under the&amp;nbsp;&lt;em&gt;project&lt;/em&gt;&amp;nbsp;folder:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Build.scala : contains the app information&lt;/li&gt;
&lt;li&gt;build.properties : contains the sbt version&amp;nbsp;&lt;/li&gt;
&lt;li&gt;plugins.sbt : contains default resolver and play 2.0 RC1 Snapshot deps&lt;/li&gt;
&lt;/ul&gt;
Starting from there three actions are required in order to import sbt-idea.&lt;br /&gt;
&lt;strong&gt;Create build.sbt&lt;/strong&gt;&lt;br /&gt;
We have to create a new file name &lt;em&gt;built.sbt&lt;/em&gt;&amp;nbsp;in which you'll add the TypeSafe (Scala company) as a searchable repository.&lt;br /&gt;
&lt;pre class="brush: scala"&gt;resolvers += Classpaths.typesafeResolver&lt;/pre&gt;
&lt;strong&gt;Update the plugins.sbt&lt;/strong&gt;&lt;br /&gt;
Add the needed reference to the plugin sbt-idea and add it to the plugin list of sbt.&lt;br /&gt;
&lt;pre class="brush: scala"&gt;resolvers ++= Seq(
    DefaultMavenRepository,
    Resolver.url("Play", url("http://download.playframework.org/ivy-releases/"))(Resolver.ivyStylePatterns),
    "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)

addSbtPlugin("play" % "sbt-plugin" % "2.0-RC1-SNAPSHOT")

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.1-SNAPSHOT")

libraryDependencies += "play" %% "play" % "2.0-RC1-SNAPSHOT"
&lt;/pre&gt;
&lt;strong&gt;Update the Build.scala&lt;/strong&gt;&lt;br /&gt;
Add the sbt-idea plugin repository in the resolvers' list.&lt;br /&gt;
&lt;pre class="brush: scala"&gt;import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

  val appName = "playbasket"
  val appVersion = "1.0"

  val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

  val appDependencies = Seq(
  )

  val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
    // Add your own project settings here
    resolvers ++= Seq(
      sbtIdeaRepo
    )
  )

}&lt;/pre&gt;
&lt;h2&gt;


Create IDEA module&lt;/h2&gt;
Now everything is quite simple. Get back to the project root and use &lt;em&gt;play&lt;/em&gt;. When entered the console, the module will be build by simply running &lt;em&gt;idea&lt;/em&gt;.&lt;br /&gt;
Having the &lt;em&gt;iml&lt;/em&gt;&amp;nbsp;created, all you have to do is to open Idea, create a project and import the module file right after.&lt;br /&gt;
Note, if you're &lt;strong&gt;encountering problem with the scala environment&lt;/strong&gt; (that happens at first time). You'll have to create another module (short-lived), then add it the Scala facet where you'll be able to configure the Scala compiler.&lt;br /&gt;
When done, you can delete the module, and getting back to the original, you'll be able now to refer to the Scala compiler/libraries.&lt;br /&gt;
&lt;hr /&gt;
&lt;a href="http://ska-la.blogspot.com/2012/02/note-this-post-is-continuation-of-this.html" target="_blank" title="Json and Play"&gt;Let's move to Json and Play&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/NGAu9KYVKlw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/5539821579814765799/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_19.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/5539821579814765799?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/5539821579814765799?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/NGAu9KYVKlw/neo4j-with-scala-play-20-on-heroku-part_19.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 3) :: Play 2.0/Idea" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_19.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QCQH09eSp7ImA9WhRaFkU.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-1251416196679171711</id><published>2012-02-19T21:58:00.000+01:00</published><updated>2012-02-19T22:02:41.361+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-19T22:02:41.361+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="rest" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="graph" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 2) :: Neo4J</title><content type="html">&lt;h1&gt;


Neo4J&lt;/h1&gt;
This post is a continuation of this &lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part.html" target="_blank"&gt;post&lt;/a&gt;, where I've introduced for what is dedicated this suite.&lt;br /&gt;
In the current post, we'll talk a bit of &lt;a href="http://neo4j.org/" target="_blank" title="Neo4J"&gt;&lt;strong&gt;Neo4J&lt;/strong&gt; &lt;/a&gt;and why I've considered it as a back end service for storing data in one of my later spikes.&lt;br /&gt;
&lt;h2&gt;


Some works on Graph DB&lt;/h2&gt;
A graph database is a kind of &lt;a href="http://en.wikipedia.org/wiki/NoSQL"&gt;NoSQL&lt;/a&gt;, that stores neither data as KVP nor as Column even nor as Collection of document, but as... Graph.&lt;br /&gt;
Ok, ok, it's quite obvious but what to say more, maybe that it's querying is very interesting because it relies on a notion of traversal, that would require joins on joins in classical RDMBS.&lt;br /&gt;
The main purpose of such graph storing is high dergeed inter-connected data, as Social data are.&lt;br /&gt;
&lt;h2&gt;


Neo4J&lt;/h2&gt;
I quickly fall on this product for handling my test domain model that figures the social network use case, where users are connected to users, and participates in groups.&lt;br /&gt;
Neo4J is written in Java, where a lot of NoSQL database are C++ based. Moreover, where most of NoSQL databases requires standalone installation to work, Neo4J is able to create &lt;a href="http://docs.neo4j.org/chunked/snapshot/tutorials-java-embedded.html" target="_blank" title="Embedded"&gt;Embedded&lt;/a&gt; databases running instances (look like the jetty revolution for servlet containers).&lt;br /&gt;
Finally, my choice was arrested when I saw its &lt;a href="http://docs.neo4j.org/chunked/snapshot/rest-api.html" target="_blank" title="RESTful Interface"&gt;RESTful interface&lt;/a&gt;;&amp;nbsp;still in working status but which is promising, with url patterns auto-discovery using the service root response.&lt;br /&gt;
Final Finally (I promise), I saw that Neo4J community was huge, that &lt;a href="https://github.com/neo4j/spatial" target="_blank"&gt;Spatial&lt;/a&gt; was already taken into account (GIS has highly inter-connected data, and it'll be probably my next spike). But also, it offers good usage of Lucene as back end indexing provider.&lt;br /&gt;
&lt;h2&gt;


Install It, Start&lt;/h2&gt;
Quite simple, and I wouldn't expand my self to much on the topic rather than pointing the extractable&amp;nbsp;&lt;a href="http://neo4j.org/download" target="_blank" title="Neo4J Bundle"&gt;http://neo4j.org/download&lt;/a&gt;.&lt;br /&gt;
Drop the extracted folder wherever you want, and set your &lt;em&gt;PATH&lt;/em&gt;&amp;nbsp;to target the &lt;em&gt;Neo4J/bin&lt;/em&gt;&amp;nbsp;folder where is located the &lt;em&gt;neo4j&lt;/em&gt;&amp;nbsp;executable.&lt;br /&gt;
When it's done two choices are up to you:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;install as a service:&amp;nbsp; &lt;a href="http://docs.neo4j.org/chunked/snapshot/server-installation.html"&gt;http://docs.neo4j.org/chunked/snapshot/server-installation.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;run it by hand by simply do the following in console: $&amp;gt;&amp;nbsp;&lt;em&gt;Neo4J start&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;


Sanity check...&lt;/h2&gt;
The server will run listening on your&amp;nbsp;&lt;a href="http://localhost:7474/" target="_blank" title="http://localhost:7474"&gt;localhost:7474/&lt;/a&gt;. Using your browser you'll directly be redirected to the&amp;nbsp;&lt;a href="http://localhost:7474/webadmin" target="_blank"&gt;webadmin&lt;/a&gt;&amp;nbsp;interface.&lt;br /&gt;
Since I can talk further on this web admin, I'll introduce some features I loved.&lt;br /&gt;
&lt;h2&gt;


... WebAdmin (is your friend)&lt;/h2&gt;
The Neo4J &lt;a href="http://docs.neo4j.org/chunked/snapshot/tools-webadmin.html" target="_blank"&gt;web amin interface&lt;/a&gt; offers a way to query your graph very easily through a simple string using tags (like Lucene query string) in order to match nodes, relationships, paths, indexes and so on.&lt;br /&gt;
So far so good, and? Ok it presents you the result in an editable table...&lt;br /&gt;
Mmmmh exiting... Ok and you can see your graph using their &lt;a href="http://arborjs.org/" target="_blank"&gt;arbor.js&lt;/a&gt; based viewing tool. Ha ha!&lt;br /&gt;
The other tool I like is the web based console for trying &lt;a href="http://docs.neo4j.org/chunked/snapshot/cypher-query-lang.html" target="_blank"&gt;Cypher &lt;/a&gt;or Gremlin queries or even to try the HTTP REST interface.&lt;br /&gt;
&lt;hr /&gt;
&lt;a href="http://www.blogger.com/blogger.g?blogID=5531553525163261182" target="_self" title="Create Project, setup IDEA"&gt;Let's create the project and configure IDEA&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/kDX-OckCNGE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/1251416196679171711/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-this-post-is-continuation-of-this.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1251416196679171711?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/1251416196679171711?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/kDX-OckCNGE/neo4j-this-post-is-continuation-of-this.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 2) :: Neo4J" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-this-post-is-continuation-of-this.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQMSXs4eip7ImA9WhBbF04.&quot;"><id>tag:blogger.com,1999:blog-5531553525163261182.post-2958348096997134643</id><published>2012-02-19T21:54:00.000+01:00</published><updated>2013-05-16T21:43:08.532+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-16T21:43:08.532+02:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="rest" /><category scheme="http://www.blogger.com/atom/ns#" term="sjson" /><category scheme="http://www.blogger.com/atom/ns#" term="neo4j" /><category scheme="http://www.blogger.com/atom/ns#" term="play2.0" /><category scheme="http://www.blogger.com/atom/ns#" term="dispatch" /><category scheme="http://www.blogger.com/atom/ns#" term="scala" /><title>Neo4J with Scala Play! 2.0 on Heroku (Part 1)</title><content type="html">&lt;h1&gt;








Neo4J with Scala Play! 2.0 on Heroku&lt;/h1&gt;
In this new posts series I’ll try to gather all steps of a spike I did building a prototype using scala and a graph database.
&lt;br /&gt;
&lt;h1&gt;








Chosen Technologies&lt;/h1&gt;
&lt;b&gt;Play! Framework&lt;/b&gt; as the web framework, in its 2.0 version built from sources.
&lt;br /&gt;
&lt;b&gt;Neo4J&lt;/b&gt; as the back end service for storing graph data.
&lt;br /&gt;
&lt;b&gt;Scala&lt;/b&gt; for telling the computer what it should do...
&lt;br /&gt;
Here is an overview of what will be covered in the current suite.
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;How to install Play! 2.0 from Git (or download the last version that must be &amp;gt; beta)&lt;/li&gt;
&lt;li&gt;I&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-this-post-is-continuation-of-this.html"&gt;nstall Neo4J and run it in a Server Mode. Explain its REST/Json Interface.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_19.html"&gt;Create a Play! project. Update it to open it in IDEA Community Edition.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/note-this-post-is-continuation-of-this.html"&gt;An introduction of the Json facilities of Play! Scala. With the help of the SJson paradigm.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_2470.html"&gt;Introduction of the Dispatch Scala library for HTTP communication.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.be/2012/02/neo4j-with-scala-play-20-on-heroku-part_21.html"&gt;How to use effeciently Dispatch’s Handler and Play!’s Json functionality together. Create generic Neo4J nodes using the result.&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_25.html"&gt;Enhance the previous work to create a persistent service that can re/store &lt;i&gt;domain model instances&lt;/i&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_27.html"&gt;Create some views (don’t bother me for ‘em … I’m not a designer ^^) using Scala templates and Jquery ajax for browsing model and creating instances.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part_29.html"&gt;Deploy the whole stuffs on Heroku.&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;
&lt;h1&gt;








Play 2.0 Framework&lt;/h1&gt;
This post intent is not to explain how powerful is Play framework (2.0) is. For that I'd recommend this &lt;a href="https://github.com/playframework/Play20/wiki/Philosophy" target="_blank"&gt;wiki page&lt;/a&gt;.
&lt;br /&gt;
However we'll explain all needed steps to build it from sources.
&lt;br /&gt;
When I first wronte this post, the released version wasn't suficient for what I needed to do with Neo4J. But now you could just download the RC2 and unzip it somewhere, find it &lt;a href="http://download.playframework.org/releases/play-2.0-RC2.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;h2&gt;








Prerequesites&lt;/h2&gt;
In this section, we’ll assume that you’ve already setup your scala and git environment (oh yeah and the JDK as well, and not the JRE only! we’ll need javac). If not please refer to those sites:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;http://www.scala-lang.org/node/201&amp;nbsp;&lt;/li&gt;
&lt;li&gt;http://help.github.com/set-up-git-redirect&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;h2&gt;








G[e/i]t sources&lt;/h2&gt;
First of all, open your preferred Git tool and retrieve the sources (warn: choose a unix like path, otherwise you might encountered problems with spaces for instance).&lt;br /&gt;
&lt;br /&gt;
Use &lt;i style="background-color: #eeeeee;"&gt;git clone git://github.com/playframework/Play20.git&lt;/i&gt;. And wait for having all sources downloaded.
&lt;br /&gt;
&lt;h2&gt;








First step in sbt&lt;/h2&gt;
Seconds later, open a console and do the following to run the built tool used by Play 2.0, that is sbt.&lt;br /&gt;
&lt;i style="background-color: #eeeeee;"&gt;cd&amp;nbsp;Play20/framework&lt;/i&gt;&lt;br /&gt;
&lt;i style="background-color: #eeeeee;"&gt;build&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This will launch the embedded sbt (0.11.2) which needs some libraries automatically fetched.
&lt;br /&gt;
&lt;h2&gt;








Build and fetch&lt;/h2&gt;
While being in the sbt-console, you can now ask sbt to build the framework and fill in the local Ivy repository with needed libraries (Play2.0 runtime deps).&lt;br /&gt;
&lt;br /&gt;
Enter &lt;i style="background-color: #eeeeee;"&gt;build-repository&lt;/i&gt; in the console and hit enter.&lt;br /&gt;
&lt;br /&gt;
Minutes later, you”ll be able to quit the console by CTRL+D, and to check what happens in you Play20 folder.&lt;br /&gt;
&lt;br /&gt;
Actually, aside the framework folder, you have now a folder named&amp;nbsp;&lt;i&gt;repository&lt;/i&gt; that contains every needed deps (includind play).&lt;br /&gt;
&lt;br /&gt;
Let’s check by listing all files in play: &lt;i style="background-color: #eeeeee;"&gt;ls Play20/repository/local/play&lt;/i&gt; and find libraries such &lt;i&gt;play&lt;/i&gt;, &lt;i&gt;anorm&lt;/i&gt;, &lt;i&gt;template&lt;/i&gt; for the scala 2.9.1 version.
&lt;br /&gt;
&lt;h2&gt;








Done!&lt;/h2&gt;
Great!&lt;br /&gt;
&lt;br /&gt;
You’ve just finished the Play2.0 installation.&lt;br /&gt;
You can, for convenience, update your PATH to point to the Play20 folder (where resides the play executable)
&lt;br /&gt;
&lt;hr /&gt;
Let’s move to the Neo4J setup&lt;img src="http://feeds.feedburner.com/~r/blogspot/OojqO/~4/YVVVFlShKd0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ska-la.blogspot.com/feeds/2958348096997134643/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2958348096997134643?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5531553525163261182/posts/default/2958348096997134643?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/OojqO/~3/YVVVFlShKd0/neo4j-with-scala-play-20-on-heroku-part.html" title="Neo4J with Scala Play! 2.0 on Heroku (Part 1)" /><author><name>andy petrella</name><uri>https://plus.google.com/114291535446112438353</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh5.googleusercontent.com/-I_Av7C-i6Jo/AAAAAAAAAAI/AAAAAAAAAoE/4edgy8PXjHQ/s512-c/photo.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://ska-la.blogspot.com/2012/02/neo4j-with-scala-play-20-on-heroku-part.html</feedburner:origLink></entry></feed>
