RESTEasy tutorial
| Article Index |
|---|
| RESTEasy tutorial |
| Create your first RESTful service |
| Using JSON providers |
| All Pages |
RESTEasy is an portable implementation of JAX-RS specification which provides a Java API for RESTful Web Services over the HTTP protocol. In this tutorial we will show a step-by-step guide how to create some simple RESTful Web services using Resteasy implementation.
Installing RESTEasy
Installing RESTEasy requires different steps depending on the release of JBoss AS you are running:
1) JBoss 6-M4 and Higher
If you are going to run RESTEasy with JBoss 6-M4 and higher you don't have to download/install anything. The RESTEasy libraries are already bundled in the application server. Also the application server detects automatically the resources which are exported as Restful services.
All you have to do is inserting the correct web.xml namespaces:
2) Older JBoss releases
If you have got any other JBoss AS release you have to perform a few basic steps for installing RESTEasy:
Step 1# Download Resteasy from the Repository
The first step is to download the latest Resteasy stable release from:
http://sourceforge.net/projects/resteasy/files/Resteasy%20JAX-RS/
Step 2# Add the following libraries to your Web application:
Step 3# Define listeners and bootstrap classes:
Add the following web.xml configuration:
The org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap class is a ServletContextListener that configures an instance of an ResteasyProviderFactory and Registry.
Then, you need to set the parameter javax.ws.rs.core.Application with the singleton class which is used by your application to enlist all JAX-RS root resources and providers. Using JBoss 6-M4 and Higher this is not necessary as it's performed automatically by the application server when you deploy the .war
Finally you need to specify which url patterns need to be filtered by Resteasy. With the /* url-pattern all resources will be passed to resteasy servlet.
Step 4# Create the Singleton class
Now we need to add a special Singleton class to enlist all JAX-RS resources, as indicated by the javax.ws.rs.Application parameter.
This is your Application class which will enlist your RESTful services in the constructor. In our example, we will add the HelloWorld service.
Autoscanning of resources
If you prefer, you can let RESTeasy scan for your resources instead of adding the SingletonBean which installs your JAX-WS resources. Just add the following configuration in your web.xml:

