Dropwizard-Guice-JPA RESTful application example

1,184 views
Skip to first unread message

Sebastian Eichholz

unread,
Jun 11, 2014, 4:54:58 PM6/11/14
to dropwiz...@googlegroups.com
I created a generic RESTful server application at Github, perhaps some of you can use it as a starting point for his/her own project.

Some details about it:
  • RESTful app based on Dropwizard version 0.7.0
  • Dependency Injection with Google Guice
  • Hibernate / JPA 2.1 as persistence framework
  • HSQLDB as (in memory) database
  • "Transaction-per-HTTP-request" with Guice PersistentFilter
  • Support for cross-origin resource sharing
  • JPA entities with UUIDs as key
During the next months I would like to add more functionality to it (authentication, hypermedia with HATEOAS, ...).

I would appreciate if you have improvements for this app or would support the further development, so that everyone else can also benefit even more.

For more information about it read this blog entry or go directly to the Github project page.

Sebastian Eichholz

unread,
Jun 19, 2014, 4:28:03 PM6/19/14
to dropwiz...@googlegroups.com
I added two new features to the application:
  • basic authentication for DELETE calls to /task ("user" + "password")
  • integration tests with rest-assured, which is a great library to make for integration tests without a browser!

Sebastian Eichholz

unread,
Jul 12, 2014, 8:00:27 AM7/12/14
to dropwiz...@googlegroups.com
I added the support for basic version control with Hibernate Envers.
So if you change an existing entity, Envers automatically saves the old state of that entity. Then you can e.g. ask the database for the revisions of a single entity or you can load the concrete older revisions.
Some general information about Hibernate Envers can be found here, the full developer documentation is here.

The most annoying thing I encountered was that I got some weird ClassCastExceptions when I asked Envers for the revisions of an entity. It turned out that dropwizard included an older version of Javassist than the version that Hibernate Envers needs.
So I had to do this in the pom.xml:
        <dependency>
           
<groupId>com.hubspot.dropwizard</groupId>
           
<artifactId>dropwizard-guice</artifactId>
           
<version>${dropwizard.version}</version>
           
<exclusions>
               
<!-- javassist used here is too old and must be excluded!
                See http://stackoverflow.com/questions/23215917/javassist-classcastexception-in-hibernate-and-netbeans
                -->

               
<exclusion>
                   
<artifactId>javassist</artifactId>
                   
<groupId>javassist</groupId>
               
</exclusion>
           
</exclusions>
       
</dependency>
Ugly! :-(


Another more interesting question was how to expose older revisions of an entity via the REST API.
I decided to do it this way:

What do you think about this?


Sebastian Eichholz

unread,
Sep 20, 2014, 10:37:26 AM9/20/14
to dropwiz...@googlegroups.com
I created a corresponding AngularJS web application s a client for the REST server!
Take a look at:
https://github.com/oregami/angularjs-rest-client/

Currently it has the following features:

  • created with the Yeoman generator for AngularJS
  • integrated dependency managament with npm/Bower
  • build management with Grunt
  • JavaScript unit tests with Karma (TODO: end2end tests)
  • live reload of the website during development
  • REST calls with Restangular
  • edit task objects, including subtasks (1-n relation)
  • list revisions of task objects and language objects (stored on the server via Hibernate Envers)
Comments, suggestions or help is always welcome :-)

Reply all
Reply to author
Forward
0 new messages