users@jersey.java.net

REST web service with Jersey giving 404 error

From: <jadhavjyoti23_at_gmail.com>
Date: Thu, 11 Nov 2010 16:52:14 -0800 (PST)

Hi all,

i am new to Jersey. and I am developing a rest web service using Jersey
and Weblogic 8.1 as application server.

i followed the steps in the documnet and created a dynamic java project
for rest web service and while testing it gives me 404 error

i followed following steps :

1. new dynamic web project in eclipse
2. copied all Jersey .jars to WEB-IF/lib
3. created new java class with annotations like

package com.foo.rest1;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
        // This method is called if TEXT_PLAIN is request
        @GET
        @Produces(MediaType.TEXT_PLAIN)
        public String sayPlainTextHello() {
                return "Hello Jersey";
        }

        // This method is called if XMLis request
        @GET
        @Produces(MediaType.TEXT_XML)
        public String sayXMLHello() {
                return "<?xml version=\"1.0\"?>" + "<hello> Hello
Jersey" + "</hello>";
        }

        // This method is called if HTML is request
        @GET
        @Produces(MediaType.TEXT_HTML)
        public String sayHtmlHello() {
                return "<html> " + "<title>" + "Hello Jersey" +
"</title>"
                                + "<body><h1>" + "Hello Jersey" +
"</body></h1>" + "</html> ";
        }
}



4. added following in web.xml

<servlet>
       <servlet-name>Jersey REST Service</servlet-name>
      
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</s
ervlet-class>
       <init-param>
       
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-n
ame>
       
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-valu
e>
       </init-param>
       <init-param>
        
<param-name>com.sun.jersey.config.property.packages</param-name>
         <param-value>com.foo.rest1</param-value>
       </init-param>
     </servlet>
     <servlet-mapping>
       <servlet-name>Jersey REST Service</servlet-name>
       <url-pattern>/rest/*</url-pattern>
     </servlet-mapping>
   
5. i deployed the project and restarted the weblogic server

6. i am testing web service with this URL
http://localhost:7001/rest1/rest/hello

and it is giving me error 404

am i missing any steps ?

can anyone please help me to resolve this issue ?

thanks in advance,

Jyoti.