Thanks in advance. I am new in web services , when i try to deploy the restful web service using java , it will generate an exception. I am follow the RESTful Java with JAX-RS to learn web services, according to this book chapter 3 ,i try to build the example , after deploying the example it will generate the exception , i know , i miss something , but i don't know what i missing. following is my code of example .
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" 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>RestfulTest</display-name>
<servlet>
<servlet-name>Rest</servlet-name>
<servlet-class>com.restfultest.controller.ShoppingApplication</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Following is the class
public class ShoppingApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
public ShoppingApplication() {
singletons.add(new CustomerResources());
}
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
when try to deploy the application following the exception occur.
java.lang.ClassCastException: com.restfultest.controller.ShoppingApplication cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
this is silly question i know , ShoppingApplication
is not the servlet class but accordin to this book ,it is servlet class. to call this services , i use chrome
restful client. Please suggest me how to use chrome restful client and how to send XML
or JSON
request using this client.
java.util.HashSet; import java.util.Set; import javax.ws.rs.core.Application; import com.resfultest.service.CustomerResources;
. But i think, this is the problem of servlet , because when i call , the application not found any servlet. – Harmeet Singh May 18 '13 at 12:31