Now the last step is activating our Web Service. This can be done in two ways: using XML configuration:

1) Define in web.xml that your service is a REST Application

<servlet>
   <servlet-name>Resteasy</servlet-name>
     <servlet-class>
       org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
     </servlet-class>
     <init-param>
       <param-name>javax.ws.rs.Application</param-name> 
       <param-value>com.webservice.RESTService</param-value>
    </init-param>
 
 </servlet>  
 


2) Define a JAX-RS activator by adding a class which extends  javax.ws.rs.core.Application and defines an application path for your web service. [recommended]

package com.webservice;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {
 
}

That's all. Remember to add a persistence.xml file to your META-INF folder of your application

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
 xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="persistenceUnit" transaction-type="JTA">
     <provider>org.hibernate.ejb.HibernatePersistence</provider>
     <jta-data-source>java:/MySqlDS</jta-data-source>  
 
     <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
     </properties>
  </persistence-unit>
</persistence>

If you need a tutorial about installing a datasource on JBoss AS 7 you can find one here .

If you have correctly configured your application, you will end up with a project like this:

jboss 7 restful web services tutorial

The RESTful web service will be accessible using the path: http://localhost:8080/restas7/rest/list

0
0
0
s2smodern