Reputation: 547
Hi I followed vogella tutorial and made some changes according to my requirements. when I tried to call the service after deploying the application to the server I am getting 404 (Not found) error in rest client/browser. Please help and tell me whats wrong in the code.
Here are my fiels
Web.XML
<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>UploadDemo</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.services.demo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<description>Location to store uploaded file</description>
<param-name>file-upload</param-name>
<param-value>
c:\data\
</param-value>
</context-param>
</web-app>
Java Class
package com.services.demo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/demo")
public class ServiceDemo {
@GET
@Path("/hello")
public String getMessage() {
return "Hello world";
}
}
Application structure:
And the URL I am calling is
http://localhost:8080/uploadDemo/demo/hello
Upvotes: 0
Views: 1565
Reputation: 1019
If you are not getting any other exceptions on the server side but still getting a 404 error, then the problem is with the url.
http://localhost:8080/uploadDemo/demo/hello
Your url looks wrong and it should be:
http://localhost:8080/UploadDemo/demo/hello
I guess your war name deployed in your container will be "UploadDemo" (by looking at your folder structure) instead of "uploadDemo".
Upvotes: 2