Deployed a demo Rest Service on tomcat 7 using jersey JAXRS API . Developed a resource class
@Path("/supportdata")
public class SupportDataService {
public SupportDataService() {
// TODO Auto-generated constructor stub
}
@GET
@Produces(MediaType.APPLICATION_XML)
public String getSupportData(){
String xmlSupport=null;
xmlSupport="<SupportData><Support><key>path1</key><value>value1</value></Support><Support><key>path2</key><value>value2</value></Support></SupportData>";
return xmlSupport;
}
}
Sub class of Application
public class RestApplication extends Application {
public RestApplication() {
// TODO Auto-generated constructor stub
}
@Override
public Set<Class<?>> getClasses() {
// TODO Auto-generated method stub
Set<Class<?>> s=new HashSet<Class<?>>();
s.add(SupportDataService.class);
return s;
}
}
Web.xml contains
<web-app>
<servlet>
<servlet-name>com.jaxrs.RestApplication</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>com.jaxrs.RestApplication</servlet-name>
<url-pattern>/resources</url-pattern>
</servlet-mapping>
</web-app>
Included javax.ws.rs-api-2.0.1.jar from jersey in the project. Deployed it on defaultport of tomcat 7 and calling the url on local host port 8080 and url
/RestService/resources/supportdata
getting a 404 error of resource not available.
Given...
RestApplication
is in thecom.jaxrs
packageYou have the required dependencies [1]
No other unknown issues related to something you're not showing us
All you need to do to get this to work...
is change
to
The resource should be accessible via
http://localhost:8080/yourapp/resources/supportdata
Tested this and it works fine.
/resources
is limiting the url pattern to strictly/resources
. When you add the/*
you are saying anything with the/resources
prefix.[1] :
Using Maven, this is the only dependency I used
Not using Maven (ahhhh, whyyy?):
I suggest you download the RI Bundle from here and include all the jars into your project.
And just for others scratching their head about the OP's configuration, this is from the JAX-RS spec: