I am trying to build a simple Restful api which returns user details.
I have refered this link.
Following are my classes:
API Service class:
package com.demoapp; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.omg.Messaging.SyncScopeHelper; @Path("/AddUserApi") public class AddUserApi { @GET @Path("/users") @Produces(MediaType.APPLICATION_XML) public List<User> getUsers(){ return UserUtil.getUserList(); } } Dao Class:
package com.demoapp; import java.io.Serializable; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "user") public class User implements Serializable { private static final long serialVersionUID = 1L; String name=""; String u_name=""; String password=""; String email=""; String user_type=""; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getU_name() { return u_name; } public void setU_name(String u_name) { this.u_name = u_name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getUser_type() { return user_type; } public void setUser_type(String user_type) { this.user_type = user_type; } } Utils class:
package com.demoapp; import java.util.List; public class UserUtil { public static String mysql_ip="jdbc:mysql://10.119.32.86/"; public static String metadata_database="haas"; public static String mysql_username="root"; public static String mysql_password=""; public static List<User> getUserList(){ List<User> users=new ArrayList<User>(); User user=new User(); user.setName("abc"); user.setU_name("ab_c"); user.setPassword("1234"); user.setUser_type("normal"); user.setEmail("[email protected]"); users.add(user); return users; } } web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>UserAPI</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>Jersey RESTful Application</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.demoapp</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Jersey RESTful Application</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> I have downloaded the jersey jar from the site and extracted 3 folders and added those jars in build path.
I have done everything according to the tutorial. Still its showing this error:
