<?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>James Ward</title>
	<atom:link href="http://www.jamesward.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamesward.com</link>
	<description>Heroku &#124; Java &#124; Scala &#124; Cloud &#124; Open Source &#124; Linux</description>
	<lastBuildDate>Fri, 03 Feb 2012 19:29:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<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#comments</comments>
		<pubDate>Wed, 01 Feb 2012 11:11:35 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></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%26%20Play%21%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#comments</comments>
		<pubDate>Mon, 30 Jan 2012 15:32:36 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Play Framework]]></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>3</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#comments</comments>
		<pubDate>Wed, 25 Jan 2012 18:46:17 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Scala]]></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 see you there!]]></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/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 18:16:23 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></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>3</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#comments</comments>
		<pubDate>Mon, 23 Jan 2012 18:30:26 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></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>1</slash:comments>
		</item>
		<item>
		<title>Java, Play! &amp; Scala on Heroku &#8211; 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#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:30:50 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Scala]]></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 Developers Network on Thursday January 19th Hope to see you there!]]></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#comments</comments>
		<pubDate>Mon, 12 Dec 2011 20:38:44 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Scala]]></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 Portland, Oregon &#8211; December 20 I hope to see you there!]]></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>3</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#comments</comments>
		<pubDate>Mon, 12 Dec 2011 02:20:42 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Play Framework]]></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>25</slash:comments>
		</item>
		<item>
		<title>Using MongoDB for a Java Web App&#8217;s HttpSession</title>
		<link>http://www.jamesward.com/2011/11/30/using-mongodb-for-a-java-web-apps-httpsession?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-mongodb-for-a-java-web-apps-httpsession</link>
		<comments>http://www.jamesward.com/2011/11/30/using-mongodb-for-a-java-web-apps-httpsession#comments</comments>
		<pubDate>Wed, 30 Nov 2011 22:02:21 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2833</guid>
		<description><![CDATA[Since the web&#8217;s inception we&#8217;ve been using it as a glorified green screen. In this model all web application interactions and the state associated with those interactions, is handled by the server. This model is a real pain to scale. Luckily the model is shifting to more of a Client/Server approach where the UI state [...]]]></description>
			<content:encoded><![CDATA[<p>Since the web&#8217;s inception we&#8217;ve been using it as a glorified green screen.  In this model all web application interactions and the state associated with those interactions, is handled by the server.  This model is a real pain to scale.  Luckily the model is shifting to more of a Client/Server approach where the UI state moves to the client (where it should be).  But for many of today&#8217;s applications we still have to deal with server-side state.  Typically that state is just stored in memory.  It&#8217;s fast but if we need more than one server (for failover or load-balancing) then we usually need to replicate that state across our servers.  To keep web clients talking to the same server (usually for performance and consistency) our load-balancers have implemented sticky sessions.  Session replication and sticky sessions are really just a by-product of putting client state information in memory.  Until we all move to stateless web architectures we need to find more scalable and maintainable ways to handle session state.</p>
<p>Jetty has <a href="http://webtide.intalio.com/2011/08/nosql-sessions-with-jetty7-and-jetty8/">recently added support for a pluggable session state manager</a>.  This allows us to move away from sticky sessions and session replication and instead use external systems to store session state.  Jetty provides a MongoDB implementation out-of-the-box but presumably it wouldn&#8217;t be very hard to add other implementations like Memcached.  Jetty has some <a href="http://wiki.eclipse.org/Jetty/Tutorial/MongoDB_Session_Clustering">good documentation on how to configure this with XML</a>.  Lets walk through a sample application using Jetty and MongoDB for session state and then deploy that application on the cloud with Heroku.</p>
<p>First lets cover some Heroku basics.  Heroku runs applications on &#8220;dynos&#8221;.  You can think of dynos as isolated execution environments for your application.  An application on Heroku can have web dynos and non-web dynos.  Web dynos will be used for handling HTTP requests for your application.  Non-web dynos can be used for background processing, one-off processes, scheduled jobs, etc.  HTTP (or HTTPS) requests to your application are automatically load balanced across your web dynos.  Heroku does not use sticky sessions so it is up to you to insure that if you have more than one web dyno or if a dyno is restarted, that your users&#8217; sessions will not be lost.</p>
<p>Heroku does not have any special/custom APIs and does not dictate which app server you use.  This means you have to bring your app server with you.  There are a variety of ways to do that but the preferred approach is to specify your app server as a dependency in your application build descriptor (Maven, sbt, etc).</p>
<p>You must tell Heroku what process needs to be run when a new dyno is started.  This is defined in a file called &#8220;Procfile&#8221; that must be in the root directory of your project.</p>
<p>Heroku provides a really nifty and simple way to provision new external systems that you can use in your application.  These are called &#8220;add-ons&#8221;.  There are <a href="http://addons.heroku.com">tons of Heroku add-ons</a> but for this example we will be using the <a href="http://addons.heroku.com/mongohq">MongoHQ add-on</a> that provides a MongoDB instance.</p>
<p>With that in mind lets walk through a simple application that uses Jetty&#8217;s MongoDB-backed sessions.  You can <a href="https://github.com/jamesward/jetty-mongo-session-test">get all of this code from github</a> or just clone the github repo:</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>jetty-mongo-session-test.git</pre></div></div>

<p>First lets setup a Maven build that will include the Jetty and MongoDB driver dependencies.  We will use &#8220;appassembler-maven-plugin&#8221; to generate a script that starts the Jetty server.  Here is the pom.xml Maven build descriptor:</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modelVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modelVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.heroku.test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jettySessionTest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jettySessionTest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jetty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jetty-webapp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>8.0.3.v20111011<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jetty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jetty-nosql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>8.0.3.v20111011<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.mongodb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mongo-java-driver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.6.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>appassembler-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.1.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>package<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>assemble<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assembleDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>target<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/assembleDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;programs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;program<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.heroku.test.Main<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webapp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/program<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/programs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The &#8220;appassembler-maven-plugin&#8221; references a class &#8220;com.heroku.test.Main&#8221; that hasn&#8217;t been created yet.  We will get to that in a minute.  First lets create a simple servlet that will store an object in the session.  Here is the servlet from the &#8220;src/main/java/com/heroku/test/servlet/TestServlet.java&#8221; file:</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;">com.heroku.test.servlet</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpSession</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> TestServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> CountHolder <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> count<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> time<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> CountHolder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            time <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> count<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> plusPlus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            count<span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTime<span style="color: #009900;">&#40;</span><span style="color: #003399;">Date</span> time<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">time</span> <span style="color: #339933;">=</span> time<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        HttpSession session <span style="color: #339933;">=</span> req.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        CountHolder count<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>            
            count <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>CountHolder<span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            count <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CountHolder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        count.<span style="color: #006633;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        count.<span style="color: #006633;">plusPlus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Count: &quot;</span> <span style="color: #339933;">+</span> count.<span style="color: #006633;">getCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;count&quot;</span>, count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;count = &quot;</span> <span style="color: #339933;">+</span> count.<span style="color: #006633;">getCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>As you can see there is nothing special here.  We are using the regular HttpSession normally, storing and retrieving a <em>Serializable</em> object named <em>CountHolder</em>.  The application simply displays the number or times the servlet has been accessed by a user (where &#8220;user&#8221; really means a request that passes the same JSESSIONID cookie as a previous request).</p>
<p>Now lets map that servlet to the &#8220;/&#8221; URL pattern in the web app descriptor (src/main/webapp/WEB-INF/web.xml):</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:web</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.5&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;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Test Servlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.heroku.test.servlet.TestServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>default<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.ico<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Test Servlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I put a servlet mapping in for &#8220;.ico&#8221; because some browsers automatically request &#8220;favicon.ico&#8221;, and those requests if not mapped to something will map to our servlet and make the count appear to jump.</p>
<p>Now lets create that &#8220;com.heroku.test.Main&#8221; class that will configure Jetty and start it.  One reason we are using a Java class to start Jetty is because we are trying to avoid putting the MongoDB connection information in a text file.  Heroku add-ons place their connection information for the external systems in environment variables.  We could copy that information into a plain XML Jetty config file but that is an anti-pattern because if the add-on provider needs to change the connection information (perhaps for failover purposes) then our application would stop working until we manually updated the config file.  So our simple Main class will just read the connection information from an environment variable and configure Jetty at runtime.  Here is the source for the &#8220;src/main/java/com/heroku/test/Main.java&#8221; file:</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;">com.heroku.test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Random</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jetty.nosql.mongodb.MongoSessionManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jetty.server.Server</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jetty.server.session.SessionHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jetty.webapp.WebAppContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.mongodb.DB</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.mongodb.MongoURI</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> Main <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> webappDirLocation <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;src/main/webapp/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> webPort <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PORT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>webPort <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> webPort.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            webPort <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;8080&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        Server server <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Server<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>webPort<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        WebAppContext root <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebAppContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        MongoURI mongoURI <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MongoURI<span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MONGOHQ_URL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        DB connectedDB <span style="color: #339933;">=</span> mongoURI.<span style="color: #006633;">connectDB</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mongoURI.<span style="color: #006633;">getUsername</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            connectedDB.<span style="color: #006633;">authenticate</span><span style="color: #009900;">&#40;</span>mongoURI.<span style="color: #006633;">getUsername</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, mongoURI.<span style="color: #006633;">getPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        MongoSessionIdManager idMgr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MongoSessionIdManager<span style="color: #009900;">&#40;</span>server, connectedDB.<span style="color: #006633;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sessions&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">Random</span> rand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> workerNum <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000</span> <span style="color: #339933;">+</span> rand.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        idMgr.<span style="color: #006633;">setWorkerName</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>workerNum<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        server.<span style="color: #006633;">setSessionIdManager</span><span style="color: #009900;">&#40;</span>idMgr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        SessionHandler sessionHandler <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SessionHandler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        MongoSessionManager mongoMgr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MongoSessionManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mongoMgr.<span style="color: #006633;">setSessionIdManager</span><span style="color: #009900;">&#40;</span>server.<span style="color: #006633;">getSessionIdManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        sessionHandler.<span style="color: #006633;">setSessionManager</span><span style="color: #009900;">&#40;</span>mongoMgr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        root.<span style="color: #006633;">setSessionHandler</span><span style="color: #009900;">&#40;</span>sessionHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        root.<span style="color: #006633;">setContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        root.<span style="color: #006633;">setDescriptor</span><span style="color: #009900;">&#40;</span>webappDirLocation<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;/WEB-INF/web.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        root.<span style="color: #006633;">setResourceBase</span><span style="color: #009900;">&#40;</span>webappDirLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        root.<span style="color: #006633;">setParentLoaderPriority</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        server.<span style="color: #006633;">setHandler</span><span style="color: #009900;">&#40;</span>root<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        server.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        server.<span style="color: #006633;">join</span><span style="color: #009900;">&#40;</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>As you can see the <em>MongoSessionManager</em> is being configured based on the <em>MONGOHQ_URL</em> environment variable, the Jetty server is being configured to use the <em>MongoSessionManager</em> and pointed to the web app location, and then Jetty is started.</p>
<p>Now lets give it a try!  If you want to run everything locally then you will need to have <a href="http://maven.apache.org/">Maven 3</a> and <a href="http://www.mongodb.org/">MongoDB</a> installed and started.  Then run the Maven build</p>

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

<p>This will use the <em>appassembler-maven-plugin</em> to generate the start script which sets up the <em>CLASSPATH</em> and then runs the <em>com.heroku.test.Main</em> class.  Before we run we need to set the environment variable to point to our local MongoDB:</p>
<ul>
<li>
On Windows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">MONGOHQ_URL</span>=mongodb:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">27017</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

</li>
<li>
On Linux/Mac:</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;">MONGOHQ_URL</span>=mongodb:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">27017</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>

</li>
</ul>
<p>Now run the generated start script:</p>
<ul>
<li>
On Windows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">target\bin\webapp.bat</pre></div></div>

</li>
<li>
On Linux/Mac:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sh</span> target<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>webapp</pre></div></div>

</li>
</ul>
<p>Test the app in your browser by visiting:<br />
<a href="http://localhost:8080/">http://localhost:8080/</a></p>
<p>Refresh the page a few times to verify that the count is increasing.</p>
<p>This is just testing one instance of the application which isn&#8217;t very exciting since part of the purpose of moving the session out of memory and into an external system is to handle scalability.  So lets start up another instance of the app on a different port and make sure that the session is consistent between both servers.  In another terminal window / command prompt start up a second server on port 9090:</p>
<ul>
<li>
On Windows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">MONGOHQ_URL</span>=mongodb:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">27017</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">PORT</span>=<span style="color: #000000;">9090</span>
target\bin\webapp.bat</pre></div></div>

</li>
<li>
On Linux/Mac:</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;">MONGOHQ_URL</span>=mongodb:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1:<span style="color: #000000;">27017</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PORT</span>=<span style="color: #000000;">9090</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> target<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>webapp</pre></div></div>

</li>
</ul>
<p>Now in your browser make a few requests to:<br />
<a href="http://localhost:9090/">http://localhost:9090/</a></p>
<p>Verify that the session is consistent between the two servers.</p>
<p>Now lets deploy this app on the cloud with Heroku.  As mentioned earlier we need a file named &#8220;Procfile&#8221; in the root directory that will tell Heroku what process to run when a dyno is started.  Here is the Procfile for this application:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">web: <span style="color: #c20cb9; font-weight: bold;">sh</span> target<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>webapp</pre></div></div>

<p>To create and deploy the application you will need to install <a href="http://git-scm.com/">git</a> &amp; the <a href="http://toolbelt.heroku.com">Heroku Toolbelt</a>, create an <a href="http://heroku.com/signup">Heroku</a>, and since we will be using add-ons you will need to <a href="http://heroku.com/verify">verify your Heroku account</a>.  Each application your create on Heroku gets 750 free dyno hours per month.  So as long as you don&#8217;t go above that and you stick with the free tier of the MongoHQ add-on, then you won&#8217;t be billed for anything.</p>
<p>Login to Heroku using the heroku command line interface:</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 you haven&#8217;t already setup an SSH key for Heroku then the login process will walk you through that.</p>
<p>In the root directory of this project create the app on Heroku with the &#8220;cedar&#8221; stack and the free MongoHQ add-on:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">--stack</span> cedar <span style="color: #660033;">--addons</span> mongohq:<span style="color: #c20cb9; font-weight: bold;">free</span></pre></div></div>

<p>Upload your application to Heroku using git:</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>Open the application in your browser:</p>

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

<p>If you want to add more dynos handling web requests then run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku scale <span style="color: #007800;">web</span>=<span style="color: #000000;">2</span></pre></div></div>

<p>To see what is running on Heroku run:</p>

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

<p>If you want to turn off all of the dynos for your application just scale to 0:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku scale <span style="color: #007800;">web</span>=<span style="color: #000000;">0</span></pre></div></div>

<p>To see the logging information for your application run:</p>

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

<p>To see a live version of this demo visit:<br />
<a href="http://young-wind-7462.herokuapp.com/">http://young-wind-7462.herokuapp.com/</a></p>
<p>Well, there you go.  You&#8217;ve learned how to avoid sticky sessions and session replication by moving session state to an external MongoDB system that can be scaled independently of the web tier.  You&#8217;ve also learned how to run this on the cloud with Heroku.  Let me know if you have any questions.</p>
<p>BTW: I&#8217;d like to thank <a href="https://twitter.com/j_simone/">John Simone</a> from Heroku for writing most of the code for this demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2011/11/30/using-mongodb-for-a-java-web-apps-httpsession/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Heroku Java User Group Tour: Columbus and Orange County</title>
		<link>http://www.jamesward.com/2011/11/30/heroku-java-user-group-tour-columbus-and-orange-county?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-java-user-group-tour-columbus-and-orange-county</link>
		<comments>http://www.jamesward.com/2011/11/30/heroku-java-user-group-tour-columbus-and-orange-county#comments</comments>
		<pubDate>Wed, 30 Nov 2011 16:38:37 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2829</guid>
		<description><![CDATA[The Heroku Java User Group Tour continues next week: Tuesday December 6 at the Central Ohio JUG Thursday December 8 at the Orange County JUG The sessions will teach you how to deploy Java, Play! and Scala apps on the cloud with Heroku. Hope to see you there!]]></description>
			<content:encoded><![CDATA[<p>The Heroku Java User Group Tour continues next week:</p>
<ul>
<li><a href="http://www.cojug.org/index.php?option=com_eventlist&#038;Itemid=27&#038;func=details&#038;did=113">Tuesday December 6 at the Central Ohio JUG</a></li>
<li><a href="http://www.ocjug.org/presos/abstract.jsp?id=117">Thursday December 8 at the Orange County JUG</a></li>
</ul>
<p>The sessions will teach you how to deploy Java, Play! and Scala apps on the cloud with Heroku.  Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2011/11/30/heroku-java-user-group-tour-columbus-and-orange-county/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

