RESTful Web services on JBoss AS 7
| Article Index |
|---|
| RESTful Web services on JBoss AS 7 |
| Activating JAX-RS |
| All Pages |
In this sample tutorial we will show how to run RESTful Web services on JBoss AS 7 (release 7.0.2) using CDI and JPA to load persistent data.
In order to use Web services in the new application server release you need the following extension in your configuration file:
<extension module="org.jboss.as.webservices"/>
At the moment this extension (and the webservice subsystem) is included only in the -preview.xml configuration files so for example if you want to start the standalone server and user webservices you need to use the --server-config option. For example:
standalone.bat --server-config=standalone-preview.xml
In this example we will build a sample application which uses a RESTful Web services to gather some data which is returned in XML format.
The first piece of our application will be the RESTful Web service which produces a list of Entities (of type Book):
In this example, we are binding the Path to the specific context named "/list".
You can apply the @Path annotation also at method level so that you can specify different virtual paths for your web services.
Now Let's add the Entity class named Book to our project, which simply maps the table named "Book" on the database:
Next thing, as we have seen, this project uses Context Dependency Injection to inject the EntityManager into our project.
In order to do that, we need a simple qualifier which exposes an entity manager using the resource producer pattern :
After that, in order to swith on CDI, you need to place the beans.xml file into the WEB-INF folder of your application, so that the deployer triggers CDI deployment. As we are not defining any beans into this file, just place add an empty file named beans.xml under WEB-INF.

