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

<channel>
	<title>Life As An Evangelist &#187; James Ward</title>
	<atom:link href="http://lifeasanevangelist.com/author/james-ward/feed/" rel="self" type="application/rss+xml" />
	<link>http://lifeasanevangelist.com</link>
	<description>Keep up to date with Adobe's Platform Evangelists</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:13:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Run Grails on the Cloud with Heroku</title>
		<link>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=run-grails-on-the-cloud-with-heroku</link>
		<comments>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=run-grails-on-the-cloud-with-heroku#comments</comments>
		<pubDate>Tue, 07 Feb 2012 23:27:17 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3038</guid>
		<description><![CDATA[Support for Grails on Heroku was recently announced and I&#8217;d like to walk you through the steps to create a simple Grails app and then deploy it on the cloud with Heroku. Before you get started install Grails 2.0.0, install the Heroku toolbelt, install git, and signup for a Heroku.com account. Don&#8217;t worry, you won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Support for <a href="http://blog.heroku.com/archives/2011/12/15/grails/">Grails on Heroku was recently announced</a> and I&#8217;d like to walk you through the steps to create a simple Grails app and then deploy it on the cloud with Heroku.  Before you get started <a href="http://grails.org/">install Grails 2.0.0</a>, <a href="http://toolbelt.heroku.com">install the Heroku toolbelt</a>, <a href="http://git-scm.com/">install git</a>, and <a href="http://heroku.com/signup">signup for a Heroku.com account</a>.  Don&#8217;t worry, you won&#8217;t need to enter a credit card to give this a try because Heroku gives you <a href="http://devcenter.heroku.com/articles/how-much-does-a-dyno-cost">750 free dyno hours per application, per month</a>.  (Wondering what a &#8220;dyno&#8221; is?  Check out: <a href="http://www.heroku.com/how">How Heroku Works</a>)  Let&#8217;s get started.</p>
<p><strong>Step 1)</strong> Create the app:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-app grailbars</pre></div></div>

<p>You&#8217;ll need to do the rest of this from inside the newly created &#8220;grailbars&#8221; directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> grailbars</pre></div></div>

<p><strong>Step 2)</strong> Create a new domain object:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-domain-class com.jamesward.grailbars.Bar</pre></div></div>

<p><strong>Step 3)</strong> Edit the <em>grails-app/domain/com/jamesward/grailbars/Bar.groovy</em> file so it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #a1a100;">com.jamesward.grailbars</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bar <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">String</span> name
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Step 4)</strong> Create a controller for the Bar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-controller com.jamesward.grailbars.Bar</pre></div></div>

<p><strong>Step 5)</strong> Edit the <em>grails-app/controllers/com/jamesward/grailbars/BarController.groovy</em> file so it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #a1a100;">com.jamesward.grailbars</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BarController <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">def</span> scaffold <span style="color: #66cc66;">=</span> Bar
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Step 6)</strong> Run the app locally to test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails run-app</pre></div></div>

<p>Now open it in your browser: <a href="http://localhost:8080/grailbars">http://localhost:8080/grailbars</a></p>
<p><strong>Step 7)</strong> Update the data source configuration to use the free Postgres database on Heroku.  First edit the <em>grails-app/conf/DataSource.groovy</em> file and replace the &#8220;production&#8221; section with:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">production <span style="color: #66cc66;">&#123;</span>
    dataSource <span style="color: #66cc66;">&#123;</span>
        dbCreate <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;update&quot;</span>
        driverClassName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;org.postgresql.Driver&quot;</span>
        dialect <span style="color: #66cc66;">=</span> org.<span style="color: #006600;">hibernate</span>.<span style="color: #006600;">dialect</span>.<span style="color: #006600;">PostgreSQLDialect</span>    
        uri <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">env</span>.<span style="color: #006600;">DATABASE_URL</span><span style="color: #66cc66;">?</span>:<span style="color: #ff0000;">&quot;postgres://test:test@localhost/test&quot;</span><span style="color: #66cc66;">&#41;</span>
        url <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;jdbc:postgresql://&quot;</span><span style="color: #66cc66;">+</span>uri.<span style="color: #006600;">host</span><span style="color: #66cc66;">+</span>uri.<span style="color: #006600;">path</span>
        username <span style="color: #66cc66;">=</span> uri.<span style="color: #006600;">userInfo</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>
        password <span style="color: #66cc66;">=</span> uri.<span style="color: #006600;">userInfo</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now add the Postgres JDBC driver as a dependency by adding the following to the &#8220;dependencies&#8221; section of the <em>grails-app/conf/BuildConfig.groovy</em> file:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">runtime <span style="color: #ff0000;">'postgresql:postgresql:9.1-901-1.jdbc4'</span></pre></div></div>

<p><strong>Step 8)</strong> Setup a git repository for the project which will be used for transferring the files to Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails integrate-with <span style="color: #660033;">--git</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> init
<span style="color: #c20cb9; font-weight: bold;">git</span> add application.properties grails-app <span style="color: #7a0874; font-weight: bold;">test</span> web-app
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-m</span> init</pre></div></div>

<p><strong>Step 9)</strong> Login with the Heroku CLI:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

<p><strong>Step 10)</strong> Ceate a new application using the &#8220;cedar&#8221; stack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">-s</span> cedar</pre></div></div>

<p><strong>Step 11)</strong> Upload your application to Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

<p>Now open the application running on Heroku in your browser (the URL was in the &#8220;heroku create&#8221; and &#8220;git push&#8221; output).  Verify that it works.  Awesome!  You just built a Grails app and deployed it on the Cloud with Heroku!  For more details on using Grails on Heroku, visit the <a href="http://devcenter.heroku.com/articles/grails">Heroku Dev Center</a>.  Let me know if you have any questions.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next Gen Web Apps with Scala, BlueEyes, and MongoDB</title>
		<link>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=next-gen-web-apps-with-scala-blueeyes-and-mongodb</link>
		<comments>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=next-gen-web-apps-with-scala-blueeyes-and-mongodb#comments</comments>
		<pubDate>Mon, 06 Feb 2012 16:48:35 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2998</guid>
		<description><![CDATA[Web application architecture is in the midst of a big paradigm shift. Since the inception of the web we&#8217;ve been treating the browser like a thin client. Apps just dump markup to the browser which is then rendered. Every interaction requires a request back to the server which then returns more logic-less markup to the [...]]]></description>
			<content:encoded><![CDATA[<p>Web application architecture is in the midst of a big paradigm shift.  Since the inception of the web we&#8217;ve been treating the browser like a thin client.  Apps just dump markup to the browser which is then rendered.  Every interaction requires a request back to the server which then returns more logic-less markup to the browser.  In this model our web applications are server applications.  There are certainly advantages to this model &#8211; especially when the markup consumers don&#8217;t have the capabilities to do anything more (or have inconsistent capabilities).</p>
<p>Web browser modernization has paved the way to move from the old &#8220;browser as a thin client&#8221; model to more of a Client/Server model where the client-side of the application actually runs in the browser.  There are a lot of names for this new model, Ajax being a step along the way, and perhaps HTML5 being the full realization of Client/Server web apps.</p>
<p>There are hundreds of new libraries, tools, programming languages, and services that support the creation of these next generation web (and mobile) apps.  One thing that is certainly lacking is one cohesive, end-to-end solution.  I have no doubt that we will be seeing those crop up soon, but in the mean time lets pick a few libraries and build a couple simple apps to get a better understanding of what this new model looks like.</p>
<p>I&#8217;ve decided to try this with a stack consisting of <a href="http://www.scala-lang.org/">Scala</a> for my back-end code, <a href="https://github.com/jdegoes/blueeyes">BlueEyes</a> for handling data access and serialization with transport over HTTP, <a href="http://mongodb.org">MongoDB</a> for data storage, and JavaScript with <a href="http://jquery.com/">jQuery</a> for the client-side.  I&#8217;m going to keep this very simple and not pull in anything else.  In future articles I&#8217;ll expand on this foundation.</p>
<p>So lets dive into some code.  All of the code is <a href="https://github.com/jamesward/helloblueeyes">on GitHub</a>.  If you want to get a local copy just do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jamesward<span style="color: #000000; font-weight: bold;">/</span>helloblueeyes.git</pre></div></div>

<p>This project uses the <a href="https://github.com/harrah/xsbt">Scala Build Tool (SBT)</a> for downloading dependencies, compiling, and packaging.  Follow the <a href="https://github.com/harrah/xsbt/wiki/Getting-Started-Setup">SBT setup instructions</a> if you want to be able to compile the code on your machine.  If you want to use IntelliJ or Eclipse then run one of the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt gen-idea</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt eclipse</pre></div></div>

<p>Lets start with some BlueEyes basics.  BlueEyes is a lightweight web framework built on Netty (a really high performance, NIO-based HTTP library).  BlueEyes makes it easy to define a tree of HTTP request handling patterns.  I chose BlueEyes because it&#8217;s really lightweight and utilizes some nice features of the Scala language to make the code very concise.  It&#8217;s kinda like a <a href="http://martinfowler.com/dsl.html">DSL</a> for HTTP request handling.</p>
<p>To get started with BlueEyes we first need to create an <strong>AppServer</strong> that provides a way to start the server and a place to plug services into.  Here is the code for the <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/AppServer.scala">AppServer</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">package</span> net.<span style="color: #000000;">interdoodle</span>.<span style="color: #000000;">example</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> AppServer <span style="color: #0000ff; font-weight: bold;">extends</span> EnvBlueEyesServer <span style="color: #0000ff; font-weight: bold;">with</span> HelloHtmlServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloJsonServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloStartupShutdownServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloMongoServices</pre></div></div>

<p>My <strong>AppServer</strong> is an <strong>object</strong> which means it&#8217;s a singleton (that makes sense because I can&#8217;t have more than one of these in a single instance).  The <strong>AppServer</strong> extends <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/EnvBlueEyesServer.scala">EnvBlueEyesServer</a></strong> which is a wrapper around the base <strong>BlueEyesServer</strong> that provides a way to get the HTTP port via an environment variable (this is necessary for running on Heroku &#8211; which we will get to later).  The <strong>AppServer</strong> composes in a bunch of Services that actually setup HTTP request pattern trees.</p>
<p>Starting with the simplest one, <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloHtmlServices.scala">HelloHtmlServices</a></strong> we have:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloHtmlServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> helloHtml <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloHtml&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> context <span style="color: #000080;">=&gt;</span>
      request <span style="color: #F78811;">&#123;</span>
        path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request <span style="color: #000080;">=&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>Hello, world<span style="color: #000080;">!&lt;</span>/body<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> response <span style="color: #000080;">=</span> HttpResponse<span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>response<span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>Using the <strong>BlueEyesServiceBuilder</strong> the <strong>HelloHtmlServices</strong> trait creates a service that consists of a big pattern match that goes something like this: For a request to path &#8220;/&#8221;,  produce an HTML response when there is a HTTP GET request.  Notice that the <strong>response</strong> is actually wrapped in a <strong>Future</strong>.  This is an important part of the next generation web app architecture.  Because the underlying HTTP server is NIO-based (non-blocking), the actual HTTP handling threads can be very efficiently managed so that a thread is only in use when actual IO is happening.  BlueEyes supports this by using <strong>Future</strong> wrapped responses, allowing the HTTP thread to be unblocked by back-end processing.</p>
<p>If you want to try this out locally run the following to compile the app and create a Unix script that makes it easy to start the <strong>AppServer</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt stage</pre></div></div>

<p>Now start the <strong>AppServer</strong> process:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">target<span style="color: #000000; font-weight: bold;">/</span>start net.interdoodle.example.AppServer</pre></div></div>

<p>Verify that <strong>HelloHtmlServices</strong> is working by opening the following URL in your browser:<br />
<a href="http://localhost:8080/">http://localhost:8080/</a></p>
<p>Now lets walk through a few steps to deploy this application on the cloud with Heroku.<br />
<b>Step 1)</b> <a href="https://api.heroku.com/signup">Sign up for a Heroku account</a><br />
<b>Step 2)</b> <a href="http://toolbelt.herokuapp.com/">Install the Heroku Toolbelt</a><br />
<b>Step 3)</b> Login to Heroku from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

<p><b>Step 4)</b> Create a new application on Heroku using the Cedar stack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">-s</span> cedar</pre></div></div>

<p><b>Step 5)</b> Deploy the app on Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

<p><b>Step 6)</b> Verify that the app works in your browser:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku open</pre></div></div>

<p>Great!  We have an app built with Scala and BlueEyes running on the cloud.  Now for the next piece of the architecture. The UI of the application will be written in JavaScript and will run on the client-side.  But we need to have a way to transfer data between the client and the server.  JSON has become the regular way to do this because it is parsed easily and quickly on the client.  So a BlueEyes service will generate some JSON data that can then be consumed by a JavaScript application running on the client.  But how do we get that JavaScript application running on the client?  This is the next piece of the architecture.</p>
<p>Ideally the JSON services are served separately from the client-side of the application (where the client-side includes all HTML, JavaScript, CSS, images, and other static assets).  It is also ideal to serve the client-side from a Content Delivery Network (CDN) so that it&#8217;s edge cached and loads super fast.  Dynamic assets (the JSON services) can&#8217;t be edge cached so there is a logical (and functional) separation between the client-side and the server-side.  But there is a problem with this approach.</p>
<p>The CDN and the JSON services hosts each have different DNS names and browsers don&#8217;t allow cross-origin requests (actually they don&#8217;t allow access to the responses).  There are a few different ways to deal with this (JSONP, iframe hackery, etc) but the approach I&#8217;m taking is simple.  The JSON services server will serve an entry point / thin shim web page.  That shim then loads the rest of the client-side from the CDN and since the origin of the web page is the same as the JSON services, there is no need to make a cross-origin request.  (Side note: There is a new way to do cross-origin requests cleanly and natively in the browser, but it&#8217;s not ubiquitously supported yet.)</p>
<p>Here is <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloJsonServices.scala">HelloJsonServices</a></strong> that illustrates these patterns:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloJsonServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkJson <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> helloJson<span style="color: #000080;">:</span>HttpService<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloJson&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> context<span style="color: #000080;">:</span>HttpServiceContext <span style="color: #000080;">=&gt;</span>
    request <span style="color: #F78811;">&#123;</span>
      path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/json&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jstring <span style="color: #000080;">=</span> JString<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello World!&quot;</span><span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jfield <span style="color: #000080;">=</span> JField<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;result&quot;</span>, jstring<span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jobject <span style="color: #000080;">=</span> JObject<span style="color: #F78811;">&#40;</span>jfield <span style="color: #000080;">::</span> Nil<span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> response <span style="color: #000080;">=</span> HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>jobject<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
            Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>response<span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span> ~
        produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> contentUrl <span style="color: #000080;">=</span> System.<span style="color: #000000;">getenv</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;CONTENT_URL&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
            <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html xmlns<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>head<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;jquery-1.7.min.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;hello_json.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/head<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/body<span style="color: #000080;">&gt;</span>
            <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
            Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This service handles requests to &#8220;/json&#8221; and if the requested content type is JSON then a simple JSON object is returned.  If the requested content is HTML then the shim web page is returned.  Inside the shim web page an environment variable, <strong>CONTENT_URL</strong>, is used to specify the URLs to load the JavaScript for the application.</p>
<p>The first JavaScript is the minified jQuery library.  This abstracts some browser differences, makes doing the JSON request and modifying the webpage very simple.  Here is the main client application <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/webapp/hello_json.js">hello_json.js</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/json&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This application has a function handler for when the page has loaded.  That function makes an ajax request to &#8220;/json&#8221; with the &#8220;application/json&#8221; content type.  Then on a successful response it just appends the result into the web page.</p>
<p>To run this locally first set the <strong>CONTENT_URL</strong> environment variable to the CDN where I&#8217;ve put the JavaScript files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CONTENT_URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>cdn-helloblueeyes.interdoodle.net<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now start (or restart) the server and open:<br />
<a href="http://localhost:8080/json">http://localhost:8080/json</a></p>
<p>To test the JSON service locally run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">--header</span> <span style="color: #ff0000;">&quot;Content-Type:application/json&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>json</pre></div></div>

<p>You can also use a local static file server for testing, just run <strong>net.interdoodle.example.httpstaticfileserver.HttpStaticFileServer</strong> and set <strong>CONTENT_URL</strong> accordingly.</p>
<p>If you want to try this on Heroku then set <strong>CONTENT_URL</strong> for your application:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku config:add <span style="color: #007800;">CONTENT_URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>cdn-helloblueeyes.interdoodle.net<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>This will set the environment variable and restart the application.  Then navigate to the your Heroku application&#8217;s &#8220;/json&#8221; URL in your browser.  Now both the server-side and client-side are cloudified!</p>
<p>Side Note: I&#8217;m using <a href="http://aws.amazon.com/cloudfront/">Amazon CloudFront</a> as the CDN for this example.  But any CDN would work fine.  There are various ways to upload files to Amazon CloudFront (actually they get uploaded to Amazon S3) but one thing I&#8217;m looking into is a SBT plugin that will do this.</p>
<p>Now lets add some simple data access into the mix.  I&#8217;ve chosen <a href="http://www.mongodb.org/">MongoDB</a> because it has native support for JSON and we can take advantage of <a href="https://github.com/bwmcadams/hammersmith">Hammersmith</a> &#8211; a non-blocking MongoDB driver.  In this example I&#8217;m not using Hammersmith since support for it hasn&#8217;t been officially added to BlueEyes (but at least there is the opportunity to easily switch to Hammersmith in the future).</p>
<p>Here is the code for <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloMongoServices.scala">HelloMongoServices</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloMongoServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> MongoQueryBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkJson <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> helloMongo <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloMongo&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    logging <span style="color: #F78811;">&#123;</span> log <span style="color: #000080;">=&gt;</span> context <span style="color: #000080;">=&gt;</span>
      startup <span style="color: #F78811;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// use MONGOLAB_URI in form: mongodb://username:password@host:port/database</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> mongolabUri <span style="color: #000080;">=</span> Properties.<span style="color: #000000;">envOrElse</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;MONGOLAB_URI&quot;</span>, <span style="color: #6666FF;">&quot;mongodb://127.0.0.1:27017/hello&quot;</span><span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> mongoURI <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> MongoURI<span style="color: #F78811;">&#40;</span>mongolabUri<span style="color: #F78811;">&#41;</span>
&nbsp;
        HelloConfig<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">new</span> EnvMongo<span style="color: #F78811;">&#40;</span>mongoURI, context.<span style="color: #000000;">config</span>.<span style="color: #000000;">configMap</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;mongo&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">future</span>
      <span style="color: #F78811;">&#125;</span> -<span style="color: #000080;">&gt;</span>
      request <span style="color: #F78811;">&#123;</span> helloConfig<span style="color: #000080;">:</span> HelloConfig <span style="color: #000080;">=&gt;</span>
        path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/mongo&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              helloConfig.<span style="color: #000000;">database</span><span style="color: #F78811;">&#40;</span>selectAll.<span style="color: #000000;">from</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;bars&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> map <span style="color: #F78811;">&#123;</span> records <span style="color: #000080;">=&gt;</span>
                HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>JArray<span style="color: #F78811;">&#40;</span>records.<span style="color: #000000;">toList</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span> ~
          contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            post <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              request.<span style="color: #000000;">content</span> map <span style="color: #F78811;">&#123;</span> jv<span style="color: #000080;">:</span> JValue <span style="color: #000080;">=&gt;</span>
                helloConfig.<span style="color: #000000;">database</span><span style="color: #F78811;">&#40;</span>insert<span style="color: #F78811;">&#40;</span>jv --<span style="color: #000080;">&gt;</span> classOf<span style="color: #F78811;">&#91;</span>JObject<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">into</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;bars&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
                Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> request.<span style="color: #000000;">content</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span> getOrElse <span style="color: #F78811;">&#123;</span>
                Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>status <span style="color: #000080;">=</span> HttpStatus<span style="color: #F78811;">&#40;</span>BadRequest<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span> ~
          produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> contentUrl <span style="color: #000080;">=</span> System.<span style="color: #000000;">getenv</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;CONTENT_URL&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
              <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html xmlns<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>head<span style="color: #000080;">&gt;</span>
                                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;jquery-1.7.min.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;hello_mongo.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>/head<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>/body<span style="color: #000080;">&gt;</span>
                            <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
              Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span> -<span style="color: #000080;">&gt;</span>
      shutdown <span style="color: #F78811;">&#123;</span> helloConfig<span style="color: #000080;">:</span> HelloConfig <span style="color: #000080;">=&gt;</span>
        Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This service has a startup hook that creates a MongoDB connection based on the <strong>MONGOLAB_URI</strong> environment variable or a default value.  Then there are three request handlers for the &#8220;/mongo&#8221; path.  The first handles JSON HTTP GET requests by fetching some data from MongoDB and returning it.  A JSON HTTP POST handler inserts the JSON that was sent into MongoDB.  Then there is a HTML HTTP GET request handler that returns the web page shim that loads the JavaScript from the CDN.</p>
<p>Here is the client-side of the application <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/webapp/hello_mongo.js">hello_mongo.js</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;h4&gt;Bars:&lt;/h4&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul id=&quot;bars&quot;&gt;&lt;/ul&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input id=&quot;bar&quot;/&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;button id=&quot;submit&quot;&gt;GO!&lt;/button&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#submit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>addbar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bar&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            addbar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    loadbars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> loadbars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/mongo&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bars&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bars&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;li&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addbar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/mongo&quot;</span><span style="color: #339933;">,</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
        dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> loadbars<span style="color: #339933;">,</span>
        data<span style="color: #339933;">:</span> <span style="color: #3366CC;">'{&quot;name&quot;: &quot;'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bar&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;}'</span><span style="color: #339933;">,</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This JavaScript application starts by adding some elements to the page for displaying and entering &#8220;bars&#8221;.  The <strong>loadbars()</strong> function makes a ajax GET request to the JSON service and then appends the result into the element on the page with the id of <strong>bars</strong>.  The <strong>addbar()</strong> method makes a POST request to the JSON service, passing serialized JSON containing the name of the &#8220;bar&#8221; to the JSON service, then on success it calls <strong>loadbars()</strong>.</p>
<p>If you want to run this locally then you will need a MongoDB server setup and running locally.  Make sure <strong>CONTENT_URL</strong> is set correctly and if your MongoDB settings differ from the default, then set the <strong>MONGOLAB_URI</strong> environment variable.  Start the <strong>AppServer</strong> process and then open:<br />
<a href="http://localhost:8080/mongo">http://localhost:8080/mongo</a></p>
<p>You should be able to add new &#8220;bars&#8221; and see them listed.</p>
<p>To run on Heroku you will need to add the <a href="http://addons.heroku.com/mongolab">MongoLab add-on</a>.  When the MongoLab add-on is added the <strong>MONGOLAB_URI</strong> environment variable on your Heroku application will be automatically set with the connection information for the newly provisioned MongoDB system.  To add the MongoLab add-on just run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku addons:add mongolab</pre></div></div>

<p>Now open your Heroku app&#8217;s &#8220;/mongo&#8221; URL in your browser.  Wahoo!  You have a client/server browser app running on the cloud!  Hopefully that has helped you to get a glimpse of where web application architecture is going.  This is just part of the picture and I have a few other articles planned that will cover some of the other pieces.  So keep watching here and let me know what you think.</p>
<p>Acknowledgments: <a href="http://micronauticsresearch.com/">Mike Slinn</a>, a friend of mine that does Scala and Akka consulting, helped me understand BlueEyes and helped write some of the code for this project.  Mike is also the author of the recently released book <em><a href="http://slinnbooks.com/books/futures/index.jsp%20">Composable Futures with Akka 2.0 with Java and Scala Code Examples</a></em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heroku at Jfokus and Spring I/O 2012</title>
		<link>http://www.jamesward.com/2012/02/01/heroku-at-jfokus-and-spring-io-2012?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-at-jfokus-and-spring-io-2012</link>
		<comments>http://www.jamesward.com/2012/02/01/heroku-at-jfokus-and-spring-io-2012?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-at-jfokus-and-spring-io-2012#comments</comments>
		<pubDate>Wed, 01 Feb 2012 11:11:35 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2988</guid>
		<description><![CDATA[In just a few weeks I&#8217;ll be over in Europe presenting about Heroku at two fantastic Java conferences. First up is Jfokus in Stockholm! On February 14 at 20:00 I will be leading a Cloud Conversations BoF. Then on February 15 at 11:10 I will be speaking about how to &#8220;git push&#8221; Java &#038; Play! [...]]]></description>
			<content:encoded><![CDATA[<p>In just a few weeks I&#8217;ll be over in Europe presenting about Heroku at two fantastic Java conferences.  First up is <a href="http://www.jfokus.se/">Jfokus</a> in Stockholm!  On February 14 at 20:00 I will be leading a <a href="http://www.jfokus.se/jfokus/talks.jsp#Cloud%20Conversations%20BoF">Cloud Conversations BoF</a>.  Then on February 15 at 11:10 I will be speaking about how to <a href="http://www.jfokus.se/jfokus/talks.jsp#%22git%20push%22%20Java%20&%20Play!%20Apps%20to%20the%20Cloud">&#8220;git push&#8221; Java &#038; Play! Apps to the Cloud</a>.  This will be my first time speaking at Jfokus and I&#8217;m really excited because I&#8217;ve heard such great things.</p>
<p>On Thursday Feb 16 I will be at <a href="http://springio.net/">Spring I/O</a> in Madrid speaking about <a href="http://springio.net/agenda">Running Spring Apps on the Cloud with Heroku</a> at 12:40.</p>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/02/01/heroku-at-jfokus-and-spring-io-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Try the New Play Framework Heroku Plugin</title>
		<link>http://www.jamesward.com/2012/01/30/try-the-new-play-framework-heroku-plugin?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=try-the-new-play-framework-heroku-plugin</link>
		<comments>http://www.jamesward.com/2012/01/30/try-the-new-play-framework-heroku-plugin?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=try-the-new-play-framework-heroku-plugin#comments</comments>
		<pubDate>Mon, 30 Jan 2012 15:32:36 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2973</guid>
		<description><![CDATA[I just published a Heroku Plugin for Play Framework. Right now it just deploys a Play app to Heroku. Try it out: Signup for a Heroku account Install the Heroku plugin locally: $ play install heroku Create a Play (1.2.3 or 1.2.4) app: $ play new foo --with heroku Deploy the app: $ play heroku:deploy [...]]]></description>
			<content:encoded><![CDATA[<p>I just published a <a href="http://www.playframework.org/modules/heroku">Heroku Plugin for Play Framework</a>.  Right now it just deploys a Play app to Heroku.  Try it out:</p>
<ol>
<li><a href="http://heroku.com/signup">Signup for a Heroku account</a><br/><br/></li>
<li>Install the Heroku plugin locally:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ play <span style="color: #c20cb9; font-weight: bold;">install</span> heroku</pre></div></div>

</li>
<li>Create a Play (1.2.3 or 1.2.4) app:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ play new foo <span style="color: #660033;">--with</span> heroku</pre></div></div>

</li>
<li>Deploy the app:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ play heroku:deploy foo</pre></div></div>

<p>You should see something like:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.4, http://www.playframework.org
~
~ Deploying app to Heroku
Listening for transport dt_socket at address: 8000
Project directory: /home/jamesw/Desktop/foo
Read Heroku API key from /home/jamesw/.heroku/credentials
Created new ssh key pair (heroku_rsa) in: /home/jamesw/.ssh
Added the heroku_rsa.pub ssh public key to your Heroku account
Created a .git directory for your project
Added and committed all of the local changes to the git repo
Created app: cold-night-1511
http://cold-night-1511.herokuapp.com/
Added git remote: git@heroku.com:cold-night-1511.git
Deploying application via git push
Application deployed
~ App Deployed</pre></div></div>

<p><i>Note: I haven&#8217;t figured out how to pipe the git push output to the screen yet, so be patient when the app is being git pushed.  It&#8217;s working, just takes a minute.</i>
</li>
<li>Check out your Play app running on the cloud!  Use the URL in the &#8220;heroku:deploy&#8221; output.  This should work with new and existing Play apps.</li>
</ol>
<p>All of the <a href="https://github.com/jamesward/play-heroku">code for the Heroku Play module</a> is on GitHub.  There is more I want to do with this (scaling, logs, etc) and your contributions are certainly welcome!  Keep checking back here for updates and let me know how it goes!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/01/30/try-the-new-play-framework-heroku-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java on Heroku at CinJUG, Detroit JUG, and MongoDB Boulder</title>
		<link>http://www.jamesward.com/2012/01/25/java-on-heroku-at-cinjug-detroit-jug-mongodb-boulder?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-on-heroku-at-cinjug-detroit-jug-and-mongodb-boulder</link>
		<comments>http://www.jamesward.com/2012/01/25/java-on-heroku-at-cinjug-detroit-jug-mongodb-boulder?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-on-heroku-at-cinjug-detroit-jug-and-mongodb-boulder#comments</comments>
		<pubDate>Wed, 25 Jan 2012 18:46:17 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2961</guid>
		<description><![CDATA[Over the next few days I&#8217;ll be presenting about Java, Play Framework, and Scala on Heroku at a couple Java User Groups and a MongoDB conference:

Cincinnati JUG on January 26th
Detroit JUG on January 31st
MongoDB Boulder on Febuary 1st

Hope to s...]]></description>
			<content:encoded><![CDATA[<p>Over the next few days I&#8217;ll be presenting about Java, Play Framework, and Scala on Heroku at a couple Java User Groups and a MongoDB conference:</p>
<ul>
<li><a href="http://www.cinjug.org/meetings/index.html">Cincinnati JUG on January 26th</a></li>
<li><a href="http://detroitjugjan2012.eventbrite.com/">Detroit JUG on January 31st</a></li>
<li><a href="http://www.10gen.com/events/mongo-boulder">MongoDB Boulder on Febuary 1st</a></li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/01/25/java-on-heroku-at-cinjug-detroit-jug-mongodb-boulder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial &amp; Screencast: Java on Heroku with Eclipse</title>
		<link>http://www.jamesward.com/2012/01/24/tutorial-screencast-java-on-heroku-with-eclipse/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-screencast-java-on-heroku-with-eclipse</link>
		<comments>http://www.jamesward.com/2012/01/24/tutorial-screencast-java-on-heroku-with-eclipse/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-screencast-java-on-heroku-with-eclipse#comments</comments>
		<pubDate>Tue, 24 Jan 2012 18:16:23 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2933</guid>
		<description><![CDATA[I recorded a screencast and put together some instructions on how to try out Java on Heroku using just a web browser and Eclipse. First, check out the screencast: Here are steps you can follow to get started running Java on Heroku with Eclipse and your browser: Prerequisites) Install the EGit and Maven (m2e) Eclipse [...]]]></description>
			<content:encoded><![CDATA[<p>I recorded a screencast and put together some instructions on how to try out Java on Heroku using just a web browser and Eclipse.  First, check out the screencast:<br />
<iframe width="640" height="480" src="http://www.youtube.com/embed/VRfLHuhWO74" frameborder="0" allowfullscreen></iframe></p>
<p>Here are steps you can follow to get started running Java on Heroku with Eclipse and your browser:</p>
<p><strong>Prerequisites)</strong> Install the EGit and Maven (m2e) Eclipse plugins into your Eclipse.  In Eclipse select the &#8220;Help&#8221; menu, select &#8220;Install new Software&#8221;, from the &#8220;Work With&#8221; drop-down menu select &#8220;All Available Sites&#8221;, and enter &#8220;EGit&#8221; in the filter box.  After the plugin list has loaded (could take a minute) then select the &#8220;Eclipse EGit&#8221; plugin, select &#8220;Next&#8221;, and finish walking through the wizard to the plugin.  Then do the same for the Maven Plugin &#8220;m2e&#8221;.</p>
<p><strong>Step 1)</strong> Go to <a href="http://java.herokuapp.com">java.herokuapp.com</a> and select an application template.  In the screencast I used the &#8220;Simple Java Web App with Maven and Tomcat&#8221; option since it uses the familiar WAR packaging and Tomcat.  Enter your email address and click the &#8220;Go!&#8221; button.  This will create a copy of the template, upload it to Heroku, and assign you as the owner of the app.  When the app is created you will see some instructions and a link to the application running on Heroku.</p>
<p><strong>Step 2)</strong> You should have received an email from Heroku indicating that an application has been shared with you.  If this is your first time using Heroku you will need to click the account setup link in the email in order to set your password on Heroku.</p>
<p><strong>Step 3)</strong> If this is the first time you have used Heroku then you will need to create and associate a ssh key with your Heroku account.  This will be used to authenticate you for git file transfers (to copy the application to/from Heroku).  One way to create a new ssh key and associate it with your Heroku account is via <a href="https://key.herokuapp.com">key.herokuapp.com</a>.  Just enter your Heroku username / password and a new ssh key will be created, associated with your account, and then downloaded.  You will then need to setup Eclipse to use that key.  Go to the &#8220;Window&#8221; menu -> &#8220;Preferences&#8221; -> search for &#8220;SSH&#8221;, select &#8220;Add Private Key&#8230;&#8221;, select the private key that was just downloaded, and then select &#8220;OK&#8221;.</p>
<p><img src="http://www.jamesward.com/wp/uploads/2012/01/1.png" title="ssh key in eclipse" class="alignnone size-full wp-image-2945"/></p>
<p><strong>Step 4)</strong> Now you are ready to import the created project into Eclipse.  Select the &#8220;File&#8221; menu -> &#8220;Import&#8221;, select &#8220;Project from Git&#8221;, select &#8220;Clone&#8230;&#8221;, paste the git URL into the &#8220;URI&#8221; box (you will find the git URL in the java.herokuapp.com instructions or in the email from Heroku), and select &#8220;Next&#8221;.</p>
<p><img src="http://www.jamesward.com/wp/uploads/2012/01/2.png" alt="" title="clone git repo" class="alignnone size-full wp-image-2945" /></p>
<p>Eclipse will fetch the branches of the remote git repository and should display just a master branch.  Select &#8220;Next&#8221; and then &#8220;Finish&#8221;.  A local copy of the project will now be on your computer.  Now select &#8220;Next&#8221;, select &#8220;Import as general project, select &#8220;Next&#8221;, and then select &#8220;Finish&#8221; to complete the import.  From here you can take a few other steps to setup the project for local development.  First, <a href="http://stackoverflow.com/questions/6356421/maven-tomcat-projects-in-eclipse-indigo-3-7">install the m2e-wtp connector</a>, create a new Tomcat server in Eclipse, change the web module context root to &#8220;/&#8221;, and then you can just right-click on the project and select &#8220;Run As&#8221; -> &#8220;Run on Server&#8221;.</p>
<p><strong>Step 5)</strong> Make a change to the app that you will be able to see when the new version is pushed to Heroku.  For instance, add something to the index.jsp file.  If you have setup your Eclipse for local development then you should be able to test this change locally before pushing it to Heroku.</p>
<p><strong>Step 6)</strong> To commit the changes to the local git repository, right-click on the project, select &#8220;Team&#8221; -> &#8220;Commit&#8230;&#8221;, enter a commit message, and select &#8220;Commit&#8221;.</p>
<p><img src="http://www.jamesward.com/wp/uploads/2012/01/3.png" title="commit to git" width="620" height="589" class="alignnone size-full wp-image-2947" /></p>
<p>Now that the changes are in the local git repository they can be pushed to Heroku.  Right-click on the project, select &#8220;Team&#8221; -> &#8220;Push to Upstream&#8221;.  This will send your change to Heroku and then Heroku will run the project&#8217;s Maven build and redeploy the changes.  When the process has completed you will see the details of the push and the Maven build.</p>
<p><img src="http://www.jamesward.com/wp/uploads/2012/01/4.png" title="git push results" width="622" height="428" class="alignnone size-full wp-image-2948" /></p>
<p>Now refresh (or load) the app in your browser and you should see the changes.</p>
<p>That should be enough to get you started.  As you dive in further check out the <a href="http://devcenter.heroku.com/categories/java">Heroku Dev Center</a> for a lot more details on using Java on Heroku.  Let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/01/24/tutorial-screencast-java-on-heroku-with-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just Released the S3Blobs Play Framework Module for Amazon S3</title>
		<link>http://www.jamesward.com/2012/01/23/just-released-the-s3blobs-play-framework-module-for-amazon-s3?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=just-released-the-s3blobs-play-framework-module-for-amazon-s3</link>
		<comments>http://www.jamesward.com/2012/01/23/just-released-the-s3blobs-play-framework-module-for-amazon-s3?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=just-released-the-s3blobs-play-framework-module-for-amazon-s3#comments</comments>
		<pubDate>Mon, 23 Jan 2012 18:30:26 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2911</guid>
		<description><![CDATA[I&#8217;ve just posted the first release of the S3Blobs Play Framework Module. This module makes it easy to upload and download files from Amazon S3 from a JPA entity in a Play Framework Java application. This module is based on a POC that I did a few months ago, the JPA stuff from Tim Kral, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just posted the first release of the <a href="http://www.playframework.org/modules/s3blobs">S3Blobs Play Framework Module</a>.  This module makes it easy to upload and download files from <a href="http://aws.amazon.com/s3/">Amazon S3</a> from a JPA entity in a Play Framework Java application.  This module is based on <a href="http://www.jamesward.com/2011/09/13/sending-play-framework-file-uploads-to-amazon-s3">a POC that I did a few months ago</a>, the JPA stuff from <a href="https://github.com/tkral">Tim Kral</a>, and the modularization done by <a href="http://vanderveer.be/">Roderik van der Veer</a>.  For more details on how to use the module check out <a href="http://www.playframework.org/modules/s3blobs-0.1/home">the documentation</a>, <a href="http://www.jamesward.com/2011/09/13/sending-play-framework-file-uploads-to-amazon-s3">my tutorial</a> (slightly out of date now), and <a href="https://github.com/jamesward/S3-Blobs-module-for-Play">the source code</a>.  This makes it really easy to save file uploads to an external system when <a href="http://www.jamesward.com/2011/08/29/getting-started-with-play-framework-on-heroku">running Play! apps on Heroku</a>.  Let me know if you have any questions.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/01/23/just-released-the-s3blobs-play-framework-module-for-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java, Play! &amp; Scala on Heroku – This Week in San Diego, Mountain View, and Albany</title>
		<link>http://www.jamesward.com/2012/01/16/java-play-scala-on-heroku-in-san-diego-mountain-view-albany?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-play-scala-on-heroku-this-week-in-san-diego-mountain-view-and-albany</link>
		<comments>http://www.jamesward.com/2012/01/16/java-play-scala-on-heroku-in-san-diego-mountain-view-albany?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-play-scala-on-heroku-this-week-in-san-diego-mountain-view-and-albany#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:30:50 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2900</guid>
		<description><![CDATA[This week I&#8217;ll presenting at three Java User Groups about Running Java, Play! and Scala Apps on the Cloud:

San Diego Java User&#8217;s Group on Tuesday, January 17th
Silicon Valley Web JUG on Wednesday, January 18th
The Capital District Java Dev...]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ll presenting at three Java User Groups about <strong>Running Java, Play! and Scala Apps on the Cloud</strong>:</p>
<ul>
<li><a href="http://www.sdjug.org/">San Diego Java User&#8217;s Group on Tuesday, January 17th</a></li>
<li><a href="http://www.meetup.com/sv-web-jug/events/45516292/">Silicon Valley Web JUG on Wednesday, January 18th</a></li>
<li><a href="http://www.cdjdn.com/content/running-java-play-and-scala-apps-cloud">The Capital District Java Developers Network on Thursday January 19th</a></li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/01/16/java-play-scala-on-heroku-in-san-diego-mountain-view-albany/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heroku JUG Tour: Boulder, Phoenix, &amp; Portland</title>
		<link>http://www.jamesward.com/2011/12/12/heroku-jug-tour-boulder-phoenix-portland?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-jug-tour-boulder-phoenix-portland</link>
		<comments>http://www.jamesward.com/2011/12/12/heroku-jug-tour-boulder-phoenix-portland?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-jug-tour-boulder-phoenix-portland#comments</comments>
		<pubDate>Mon, 12 Dec 2011 20:38:44 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2891</guid>
		<description><![CDATA[For the next wave of the Heroku Java User Group Tour I will be speaking about running Java, Play Framework, and Scala apps on the cloud in these three wonderful places:

Boulder, Colorado &#8211; December 13
Phoenix, Arizona &#8211; December 14
Portlan...]]></description>
			<content:encoded><![CDATA[<p>For the next wave of the Heroku Java User Group Tour I will be speaking about running Java, Play Framework, and Scala apps on the cloud in these three wonderful places:</p>
<ul>
<li><a href="http://www.boulderjug.org/">Boulder, Colorado &#8211; December 13</a></li>
<li><a href="http://www.phxjug.org/meetings.html#next">Phoenix, Arizona &#8211; December 14</a></li>
<li><a href="http://www.pjug.org/">Portland, Oregon &#8211; December 20</a></li>
</ul>
<p>I hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2011/12/12/heroku-jug-tour-boulder-phoenix-portland/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Play Framework, JPA, JSON, jQuery, &amp; Heroku</title>
		<link>http://www.jamesward.com/2011/12/11/tutorial-play-framework-jpa-json-jquery-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-play-framework-jpa-json-jquery-heroku</link>
		<comments>http://www.jamesward.com/2011/12/11/tutorial-play-framework-jpa-json-jquery-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-play-framework-jpa-json-jquery-heroku#comments</comments>
		<pubDate>Mon, 12 Dec 2011 02:20:42 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2857</guid>
		<description><![CDATA[If you are a Java developer then you really need to give Play Framework a try. It is really refreshing to take a few minutes, step out of the legacy-feeling world of traditional Java web app development and into something modern and fun. I want to walk you through a very simple tutorial where we [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a Java developer then you really need to give <a href="http://www.playframework.org">Play Framework</a> a try.  It is really refreshing to take a few minutes, step out of the legacy-feeling world of traditional Java web app development and into something modern and fun.  I want to walk you through a very simple tutorial where we will build a web application with Play Framework.  The application will use JPA for persistence and expose access to the data through a JSON over HTTP interface.  The client-side of the application will be built with <a href="http://jquery.com/">jQuery</a>.  Lets get started.</p>
<p><strong>Step 1)</strong> Download and install <a href="http://download.playframework.org/releases/play-1.2.3.zip">Play Framework 1.2.3</a></p>
<p><strong>Step 2)</strong> Create a new Play app from the command line and then move to the new directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">play new playbars
<span style="color: #7a0874; font-weight: bold;">cd</span> playbars</pre></div></div>

<p><strong>Optional Step 3)</strong> If you want to work in an IDE then you can run one of the following commands and then open the generated project in your IDE:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">play idealize</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">play eclipsify</pre></div></div>

<p>I won&#8217;t walk though the IDE specific steps here, but you can refer to the <a href="http://www.playframework.org/documentation/1.2/ide">Play documentation on IDE integration</a> if you want to get that setup.  Note that IntelliJ IDEA has great support for Play Framework with a console right in the IDE.</p>
<p><strong>Step 4)</strong> Start the Play server from the new project&#8217;s directory :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">play run --<span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

<p>This starts Play in test mode which will automatically recompile any changes we make to the application.  No packaging, redeploying, or restarting servers will be needed.</p>
<p><strong>Step 5)</strong> Open the application in your browser:<br />
<a href="http://localhost:9000">http://localhost:9000</a></p>
<p>The default page provides you with great Play documentation on how to get started.  But we will soon be changing that page.  If you want to view the documentation locally after we change the page you can use these links:</p>
<ul>
<li><a href="http://localhost:9000/@documentation/home">Documentation</a></li>
<li><a href="http://localhost:9000/@api/index.html">Play JavaDoc</a></li>
</ul>
<p><strong>Step 6)</strong> Lets start by creating a new JPA entity.  Keeping it very simple, lets create a new &#8220;app/models/Bar.java&#8221; file containing:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">models</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">play.db.jpa.Model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Bar <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This entity uses the standard JPA Entity annotation but also extends the Play Model class which provides some nice conveniences which you can read more about <a href="http://www.playframework.org/documentation/1.2.3/jpa">in the Play JPA docs</a>.  I&#8217;m using just a plain public property on this class but you can also use the Java Bean getter/setter stuff in you like.</p>
<p><strong>Step 7)</strong> Create a simple unit / integration test for this Bar object by creating a &#8220;test/BarTest.java&#8221; file with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">play.test.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">models.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BarTest <span style="color: #000000; font-weight: bold;">extends</span> UnitTest <span style="color: #009900;">&#123;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> integrationTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Bar bar <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        bar.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;a new bar&quot;</span><span style="color: #339933;">;</span>
        bar.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertNotNull<span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertTrue<span style="color: #009900;">&#40;</span>Bar.<span style="color: #006633;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        bar.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertTrue<span style="color: #009900;">&#40;</span>Bar.<span style="color: #006633;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Step 8)</strong> Setup the default database by editing the &#8220;conf/application.conf&#8221; file and uncommenting the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># db=mem</span></pre></div></div>

<p>This sets up the default database to be an in-memory database.</p>
<p><strong>Step 9)</strong> Run the application&#8217;s tests by opening the following URL in your browser:<br />
<a href="http://localhost:9000/@tests">http://localhost:9000/@tests</a></p>
<p>Select &#8220;BarTest&#8221; and then click the &#8220;Start!&#8221; button.  The test should pass.</p>
<p><strong>Step 10)</strong> Add the following two methods to the &#8220;app/controllers/Application.java&#8221; file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    public static void addBar<span style="color: #7a0874; font-weight: bold;">&#40;</span>Bar bar<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        bar.save<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
        index<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    public static void listBars<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        renderJSON<span style="color: #7a0874; font-weight: bold;">&#40;</span>Bar.findAll<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>The <em>addBar</em> method takes a <em>Bar</em>, saves it, and then redirects back to the index page.  Play will automatically parse request parameters and populate the <em>Bar</em> object.  The <em>listBars</em> method queries for all of the Bars in the database and then outputs then as serialized JSON.</p>
<p><strong>Step 11)</strong> Play has a very flexible model for mapping URLs to controllers.  Lets setup two new routes that will map URLs to the new methods we&#8217;ve added to the Application controller.  Add the following lines to the &#8220;conf/routes&#8221; file but make sure you either add them above the &#8220;Catch all&#8221; or simply remove the &#8220;Catch all&#8221; route:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">POST    <span style="color: #000000; font-weight: bold;">/</span>                                       Application.addBar
GET     <span style="color: #000000; font-weight: bold;">/</span>bars.json                              Application.listBars</pre></div></div>

<p>The first route handles HTTP POST requests to the &#8220;/&#8221; URL and handles them with the <em>Application.addBar</em> method.  The second route handles requests to the &#8220;/bars.json&#8221; URL and handles them with the <em>Application.listBars</em> method.</p>
<p><strong>Step 12)</strong> Lets add a <a href="http://www.playframework.org/documentation/1.2.4/test#Functionaltest">FunctionalTest</a> that will actually make requests to the Controller and test that our new routes and controller methods are working.  Add the following method to the &#8220;test/ApplicationTest.java&#8221; file:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> barTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Response addBarResponse <span style="color: #339933;">=</span> POST<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span>, APPLICATION_X_WWW_FORM_URLENCODED, <span style="color: #0000ff;">&quot;bar.name=foo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertStatus<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">302</span>, addBarResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Response listBarsResponse <span style="color: #339933;">=</span> GET<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/bars.json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertIsOk<span style="color: #009900;">&#40;</span>listBarsResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This test adds a new <em>Bar</em> by doing an HTTP POST to &#8220;/&#8221; and passing it some form encoded data.  Then a request is made to &#8220;/bars.json&#8221; and the response is checked to make sure there wasn&#8217;t an error.  Since there isn&#8217;t a DELETE method (which could easily be added) there isn&#8217;t a good way to clean up what this test does.</p>
<p>Run the <em>ApplicationTest</em> Functional Test in the Play Framework Web Test Runner:<br />
<a href="http://localhost:9000/@tests?select=ApplicationTest.class">http://localhost:9000/@tests?select=ApplicationTest.class</a></p>
<p>Because the test didn&#8217;t clean up after itself you can now see the JSON from &#8220;/bars.json&#8221; in your browser by visiting:<br />
<a href="http://localhost:9000/bars.json">http://localhost:9000/bars.json</a></p>
<p><strong>Step 13)</strong> Now it is time to create the actual web UI for this application.  A combination of plain HTML (via Play&#8217;s Groovy templates) and jQuery will be used.  Play Framework uses a convention to render the HTML from the &#8220;app/views/Application/index.html&#8221; template when <em>Application.index</em>&#8216;s render method is called.  In the &#8220;index.html&#8221; file and you will see:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">#{extends 'main.html' /}
#{set title:'Home' /}
&nbsp;
#{welcome /}</pre></div></div>

<p>You can also take a look at the referenced &#8220;app/views/main.html&#8221; file to see what the base template looks like.  It does the standard HTML page stuff and then inserts the body of the &#8220;index.html&#8221; page into the &#8220;#{doLayout /}&#8221; section.  The &#8220;main.html&#8221; template also loads jQuery and provides a way to insert some JavaScript into the <em>head</em> section of the page.  In the &#8220;index.html&#8221; file, replace the &#8220;#{welcome /}&#8221; line with a form that will allow users to create new bars:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">#{form @addBar()}
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bar.name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
#{/form}</pre></div></div>

<p>The &#8220;#{form @addBar()}&#8221; syntax is Groovy that creates a form tag and sets the form action to the URL that corresponds to the <em>Application.addBar</em> method.  You can test this out by loading this page in your browser:<br />
<a href="http://localhost:9000/">http://localhost:9000/</a></p>
<p>The form should be functional now.  Enter the name of a bar and click the submit button.  Because the &#8220;addBar&#8221; method calls the &#8220;index&#8221; method, after the POST, the browser is redirected back to the index page.  You can verify that the data is being saved by loading the <a href="http://localhost:9000/bars.json">bars.json</a> page again.</p>
<p>Now lets add some Ajax / jQuery to the &#8220;index.html&#8221; page that will get the JSON data and display it in the page.  Add an empty <em>ul</em> tag with an <em>id</em> of &#8220;bars&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bars&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now we will insert the JavaScript into the correct place in the page by setting the &#8220;moreScripts&#8221; variable:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">#{set 'moreScripts'}
&lt;script type=&quot;text/javascript&quot;&gt;
    $(function() {
        $.get(&quot;bars.json&quot;, function(data) {
            $.each(data, function(index, item) {
                $(&quot;#bars&quot;).append(&quot;&lt;li&gt;Bar &quot; + item.name + &quot;&lt;/li&gt;&quot;);
            });
        });
    });
&lt;/script&gt;
#{/set}</pre></div></div>

<p>Using jQuery this bit of JavaScript adds a function handler for when the page is loaded, then in that function it makes a get request to &#8220;bars.json&#8221;.  That request has a function handler for when the result comes back from the Ajax request.  Inside that function handler the data is iterated through and each &#8220;bar&#8221; is appended into the page element with the id of &#8220;bars&#8221; &#8211; the <em>ul</em> tag.</p>
<p>Try out the application and make sure that you can still add new bars and see the list of all the bars in the database.</p>
<p>Now that everything works locally, lets deploy the app on the cloud using Heroku.</p>
<p><strong>Step 1)</strong> <a href="http://heroku.com/signup">Create an account on Heroku.com</a>, install the <a href="http://toolbelt.heroku.com">Heroku Toolbelt</a> and <a href="http://git-scm.org">git</a> and then login to Heroku from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

<p>If this is the first time you&#8217;ve done this then new ssh keys for git will be created and associated with your Heroku account.</p>
<p><strong>Step 2)</strong> Each application on Heroku has a Postgres database for testing.  To use that database when running on Heroku we need to configure it.  Play applications on Heroku run in &#8220;prod&#8221; mode.  To set the database to use the Heroku database add the following lines to the &#8220;conf/application.conf&#8221; file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>prod.db=<span style="color: #800000;">${DATABASE_URL}</span>
<span style="color: #000000; font-weight: bold;">%</span>prod.jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
<span style="color: #000000; font-weight: bold;">%</span>prod.jpa.ddl=update</pre></div></div>

<p>The default way to provide database (and other resource) connection strings to an application on Heroku, is through environment variables.  The <em>DATABASE_URL</em> environment variable will contain the database host, name, username, and password.  Play Framework knows how to handle that information and setup the JDBC connections.</p>
<p><strong>Step 3)</strong> Heroku uses <em>git</em> as a means to uploading applications.  Whether or not you use <em>git</em> for your SCM tool you can use <em>git</em> as the tool to upload an app to Heroku.  In the root directory of your project create <em>git</em> repo, add the files to it, and then commit the files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> init
<span style="color: #c20cb9; font-weight: bold;">git</span> add app conf public <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-m</span> init</pre></div></div>

<p>Note: Instead of doing a selective &#8220;git add&#8221; you can create a &#8220;.gitignore&#8221; file containing the files to not add to the git repo.</p>
<p><strong>Step 4)</strong> Now we will provision a new application on Heroku using the Heroku CLI.  Each application you create gets 750 free &#8220;<a href="http://devcenter.heroku.com/articles/dynos">dyno</a>&#8221; hours per month.  So as a developer you can use Heroku for free and only pay when you need to scale beyond one dyno.  On the command line create a new application using the &#8220;cedar&#8221; stack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">-s</span> cedar</pre></div></div>

<p>This creates an HTTP endpoint and a git endpoint for your application.  You can also use a custom name and point your own domain names at the application.</p>
<p><strong>Step 5)</strong> The application is ready to be deployed to the cloud.  From a command line do a &#8220;git push&#8221; to the master branch on Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

<p>Once the files have been received by Heroku, Play Framework&#8217;s precompiler will be run, Heroku will assemble a &#8220;slug file&#8221;, and then the &#8220;slug&#8221; will be deployed onto a dyno.</p>
<p><strong>Step 6)</strong> You can now open the application in your browser by navigating to the domain outputted following the &#8220;heroku create&#8221; or by simply running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku open</pre></div></div>

<p>You&#8217;ve built a Play Framework application with JPA, JSON, &#038; jQuery and then deployed that application on the cloud with Heroku!  Now <a href="https://github.com/jamesward/playbars">get the code </a> and <a href="http://vivid-sunset-6133.heroku.com/">check out a demo</a> on Heroku.  Let me know if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2011/12/11/tutorial-play-framework-jpa-json-jquery-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

