User guide for Tapestry-resteasy module
tapestry-resteasy provides integration with Tapestry 5 and JBoss' RESTEasy, an implementation JAX-RS (Java API for RESTful Web Services). JAX-RS is a very nice little spec and if you know what it is about, the following should be very easy to understand. Otherwise, read up on it at Jersey's overview (the reference implementation) or the actual specification. JBoss' RESTEasy provides a few more features over the reference implementation.
- Add the tapestry-resteasy dependency to your pom.xml
- No need to edit your web.xml.
- Create a package named "rest" for your rest services.
- Code your singleton resource.
- Annotate your entities.
- Add a provider library to your pom.xml
- Contribute singleton resources
- Live class reloading
- version table
Add the tapestry-resteasy dependency to your pom.xml
To use tapestry-resteasy (an independent module of Tynamo), you need to add the following dependency to your pom.xml:
No need to edit your web.xml.
tapestry-resteasy integrates with the Tapestry's HttpServletRequest pipeline.
Create a package named "rest" for your rest services.
tapestry-resteasy will scan the "rest" package and automatically add singleton resources to the configuration.
If you want to add extra packages, besides InternalConstants.TAPESTRY_APP_PACKAGE_PARAM + ".rest", to be scanned for annotated REST resource classes you can contribute your package names to the ResteasyPackageManager.
Code your singleton resource.
- Name the resource class using the entity name followed by the word "Resource".
- The @Path should be the entity name in lowercase.
Annotate your entities.
Don't forget to annotate your entities with JAXB annotations. You need at least @XmlRootElement. See: http://www.caucho.com/resin-3.1/doc/jaxb-annotations.xtp
Add a provider library to your pom.xml
The previous examples use the JSON marshaller/unmarshaller provided by the resteasy-jettison-provider library. This provider allows you to marshall JAXB annotated POJOs to and from JSON, it wraps the Jettison JSON library to accomplish this.
If you don't need JAXB and only you only need JSON support, you can use the JSON marshaller/unmarshaller provided by the resteasy-jackson-provider library. I personally find Jackson's output format more intuitive than the format provided by either BadgerFish or Jettison.
You could use JAXB and Jackson together but be aware of the possible conflicts with the JAXB providers
Contribute singleton resources
If the rest services autodiscovery is not enough for you, you can manually contribute singleton resources in your AppModule:
Live class reloading
Reloading is limited to services that can be proxied, so to enable live class reloading for your REST services you need to create them as regular Tapestry IoC services with an interface and an implementation of that interface. You then have the option to leave them both in the autodiscovery package or explicitly bind them as services and contribute them to javax.ws.rs.core.Application.class. Read more about how service implementation reloading works in: http://tapestry.apache.org/reload.html
Here is an example from the tapestry-resteasy test suite.
If you get this exception:
Add this to your system properties:
|0.0.1||5.1.x||1.1.GA||see tapestry-resteasy-0.0.1 guide|