Prudence
The Scalable REST/JVM
Web Development Platform

Creative Commons License

Prudence As a Restlet Container

Why use Prudence for a Restlet application that already works?
Though applications can be written in Prudence without a single line of Java code, Prudence also acts as a useful container for existing Restlet applications, Restlet resources or restlets written in Java.
Prudence makes it easy to handle the bootstrapping and routing of your applications, and the Administration Application, debugging and logging features make it easier to deploy and manage multiple applications together. These issues have more to do with your application's configuration, rather than its functionality, and it can be useful to handle them outside of the Java build process, using live, dynamic languages in simple text source that you can modify on the fly. Deploying your Restlet application to a Prudence instance can be as simple as copying a zip file to a Prudence container.
This need is also fulfilled by servlet and Java Enterprise Edition (JEE) containers, such as Tomcat, Resin and JBoss. Indeed, Restlet has a JEE edition, and good support for servlets. However, if all you need is a deployment container, Prudence can serve as a straightforward, pure REST alternative to JEE.
Some people also look to JEE containers for their support of Java Server Pages (JSP). We urge you to take a good look at Prudence's dynamic web support. It may surpass JSP for your purposes. In particular, it is based on Restlet, which you already know and love, giving you the entire Restlet API at your fingertips. It also lets you use many wonderful languages other than Java for scriptlets. For simpler templating, Velocity and Succinct are also built in and immediately ready to use.

Summary

A 100% Restlet-based alternative to servlet/JEE containers. (Requires only Restlet JSE.)
  1. Easy deployment
    1. Configuration scripts: avoid weird (XML) configuration formats and start your Restlet component exactly as you want (your choice from six languages)
    2. The default scripts already handle virtual hosting, multiple servers and internal routing
    3. Designed from the ground-up to handle multiple applications on the same component
    4. Cloud-ready with instant clusters
    5. Admin application for live management of components
    6. Logging is pre-configured and "just works," including an Apache-compatible web log
    7. Single zip-file application deployment (like WAR files in JEE)
  2. Easy prototyping of REST resources
    1. Your choice among 6 languages
    2. Code is compiled, cached and loaded on the fly
    3. Rich debug page shows errors and source code
    4. When you're happy with it, you can rewrite it as a ServerResource in Java
  3. Powerful HTML generation platform, like JSP/ASP/PHP (again, 100% Restlet-based)
    1. Your choice from six languages, including mixing languages and templating engines (Velocity, Succinct) on one page
    2. Code is compiled, cached and loaded on the fly
    3. RAM/database/Hazelcast/memcached server-side caching, using Restlet's URI templating language for cache key generation
    4. Straightforward support for client-side caching
    5. Asynchronous processing
    6. Easily accept uploaded files
    7. Rich debug page shows errors and source code
  4. Restlet sugar (also available as a standalone JAR)
    1. Fallback router (attach multiple MODE_STARTS_WITH restlets to the same base URI)
    2. URI "capturing"
    3. JavaScript and CSS unify-and-minify filters
    4. Delegated status service for diverting to custom pages (404, 500 errors, etc.)
    5. Rich DebugRepresentation
    6. Cache backend abstraction, designed for storing StringRepresentations
    7. Easier file uploads (slightly higher-level than the Restlet FileUpload extension)
    8. ConversationCookie (combines Cookie and CookieSetting)
    9. Filter to selectively add CacheControl (to Directory, for example)

Custom Resources and Restlets

Use your application's "routing.*" to attach your resources, or otherwise manage routing. Example (JavaScript flavor):
// Prudence defaults 
document.execute('/defaults/application/routing/')
​
// MyOrg resources
router.attach('/data/item/{id}', classLoader.loadClass('org.myorg.ItemResource'))
router.attach('/data/items', classLoader.loadClass('org.myorg.ItemsResource'))
You can also change Prudence's default routing by detaching and re-attaching routes:
importClass(com.threecrickets.prudence.util.JavaScriptUnifyMinifyFilter)
​
router.detach(staticWeb)
router.attachBase(
	staticWebBaseURL,
	new JavaScriptUnifyMinifyFilter(application.context, staticWeb, new File(applicationBasePath + staticWebBasePath),
		10000))

Custom Application

By default, Prudence creates an instance of the standard Restlet Application class. Use your application's "application.*" to override this, and create and configure your own application. Example:
// MyOrgApplication
importClass(org.myorg.MyOrgApplication)
var application = new MyOrgApplication()
​
// Install our custom tunnel service
importClass(org.myorg.MyOrgTunnelService)
application.tunnelService = new MyOrgTunnelService(MyOrgTunnelService.MODE_QUERY)
​
// These attributes are specific to the MyOrgApplication class
application.databaseURI = 'mysql://localhost/myorg'
application.useTransactions = true