Skip to content

Skeleton for a REST service running over Google App-Engine, using Jersey, Jackson and Guice

License

Notifications You must be signed in to change notification settings

zach-m/gae-jersey-guice-jsf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template for a Google AppEngine REST Application

(Online demo available online at: http://gae-jersey-guice-jsf.appspot.com)

Uses GAE-friendly versions of the following products:

As a bonus, there's also a demonstration of how to use:

Even though there are newer generations for these products (Jersey 2.x and Jackson 2.x), Google AppEngine still works with Servlet specifications version 2.5 (part of JavaEE 5), and doesn't play nicely with those advanced generations (that were built to cater for Servlet 3.0 specifications).

This template project provides all the required configuration (web.xml, Jersey, Jackson, Guice, Mojarra) so that all features from all products work smoothly together. It also provides the code for 3 typical requirements (easily removable if unneeded):

  • CORS filter - to add CORS headers that are mandatory in public REST APIs
  • @PostConstruct annotation for injectable beans. This allows you the initialize your classes outside the constructor (which is invoked before the dependencies are injected)
  • GAE Blobstore support

The code demonstrates several types of APIs (implemented as JAX-RS annotated classes):

  • TestAPI - Demonstrates how to return a Java bean (MyBean) as either JSON or XML (this is a @Singleton resource)
  • InfoAPI - Returns an HTML page with the environmental settings, including those of the HttpRequest (hence it is @RequestScoped)
  • UploadAPI - Assists in using GAE Blobstore

The code also demonstrates how to bind and inject an implementation class (MyImpl) into an interface placeholder (MyIntf).

All Jersey and Guice configuration parameters are set in the class RestConfig. Jackson's JSON configuration parameters are set in JsonProvider.

To create a new project of you own, using this project as a template:

mvn archetype:generate -Dfilter=com.tectonica:

And then pick the number corresponding to gae-jersey-guice-jsf-archetype

To build:

mvn clean package

To execute locally (on http://localhost:8080):

mvn appengine:devserver

To deploy to GAE:

mvn appengine:update

About

Skeleton for a REST service running over Google App-Engine, using Jersey, Jackson and Guice

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages