Java

Just Released the S3Blobs Play Framework Module for Amazon S3

I’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, and the modularization done by Roderik van der Veer. For more details on how to use the module check out the documentation, my tutorial (slightly out of date now), and the source code. This makes it really easy to save file uploads to an external system when running Play! apps on Heroku. Let me know if you have any questions. Thanks!

Tutorial: Play Framework, JPA, JSON, jQuery, & Heroku

UPDATE: This tutorial is for Play 1.x (an old version). Check out my Play 2 Tutorial if you want to get started with the latest stuff. (Thanks to John Borys for pointing this out.)

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 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 jQuery. Lets get started.

Using MongoDB for a Java Web App’s HttpSession

Since the web’s inception we’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’s applications we still have to deal with server-side state. Typically that state is just stored in memory. It’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.

Heroku Preso from Devoxx 2011

As expected… Devoxx 2011 rocked! Such a fun conference with top notch sessions and people. I presented a session on how to deploy Java, Play Framework, and Scala apps on Heroku. Matt Raible did a great (and very thorough) write-up on my session. Thanks Matt! Here are my slides:

There was also some hot news at Devoxx… Play Framework 2 is the official web framework in the Typesafe Stack! And Heroku already supports Play 2! Awesome stuff.

Using Apache Tomcat on Heroku

One great thing about Heroku is the freedom to use any APIs and any application server. On Heroku you bring your application server with you. The easiest way to do this is by specifying your app server as a dependency of your application. This allows for maximum control and avoids the pain associated with developer and production environments using different versions of the container.

Most of the articles that have been written about running Java on Heroku use embedded Jetty since it’s lightweight and easy to specify as a dependency. But you can also use Apache Tomcat in the same way. There is now a great article on the Heroku Dev Center that walks you through how to do it. Check it out: