I have used eclipse + glassfish to deploy my first web-service from eclipse.
I have the following class:
package com.restfully.shop.services;
import javax.ws.rs.core.*;
import java.util.*;
public class ShoppingApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
public ShoppingApplication() {
singletons.add(new CustomerResource());
}
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
and the following web.xml:
<?xml version="1.0" ?>
<web-app>
<servlet>
<servlet-name>Rest</servlet-name>
<servlet-class>com.restfully.shop.services.ShoppingApplication</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
As long as I read that jersey is already included with the glassfish – id didnt put anything into the lib folder of the web project.
but hten when I start the app in the browser:
Exception
javax.servlet.ServletException: PWC1403: Class com.restfully.shop.services.ShoppingApplication is not a Servlet
root cause
java.lang.ClassCastException: com.restfully.shop.services.ShoppingApplication cannot be cast to javax.servlet.Servlet
The glassfish version is 3.1.1
I also wrote a simple client which connects to the service throught java.io.URL,
but that one returns:
404
Location:null
What is wrong with the service and how can I fix it?
+ would be very appreciated – how a services tested??? Is it always like that – writing a test class which uses those URL connections or are there any standard ways to test web services?
I have no experience with Glassfish but v3 seems to be JAX-RS aware.
This means a sub-class of javax.ws.rs.core.Application is not needed.
Just deploy your JAX-RS annotated class with a web.xml as follows
Your REST application can subsequently be accessed by adding /resources/ to the context root.