Search code examples
javaweb.xmlurl-pattern

Url pattern doesnot works with localhost url(jersey without maven)


This is my web.xml.I haveputted url pattern as rest.iam building a webservice using jersey.but while running in tomcat 6.I am getting 404 error.

Web.xml

<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
    <servlet-name>jersey-serlvet</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.snapshothealthapp1.controller</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

My webpage Inside this image we can see that it just callig rest withlocalhost urland it is getting 404 exception.

enter image description here

Authentication.java

import com.snapshothealthapp1.database.Dbclass;
    import com.snapshothealthapp1.model.AuthenticationModel;
    import com.snapshothealthapp1.model.Jsonparser;
    @Path("/customers")
    public class Authentication {
        @GET
        @Path("/get")
    //  @Produces("json")
        public Response getRequestUrl(@PathParam("get") String msg) {
            //TODO:Create a JSON(recieved from client request)
    //      JSONObject jsonClient = new JSONObject(); 
            System.out.println("inside Authentication");




        String JSON_DATA =
         "{" 
           + "  \"SnapshotRequest\": [" 
           + "    {" 
           + "      \"AuthenticationType\": \"email\"," 
           + "      \"EmailAddress\": \"test@gmail.com\","                  
           + "      \"Password\" : \"12345\"," 
           + "      \"PracticeID\" : \"null\"," 
           + "      \"DeviceID\" : \"null\""
           + "    } +   ]"
       + "}";


        //TODO : ADD JSON PARSER 
        List arr = new ArrayList();
        Jsonparser jp=new Jsonparser();
        arr =jp.jsonParser(JSON_DATA);

    //      
    //      
    //      
    //      
    //      String result=null;
    //  return Response.status(201).entity(result).build();
    return null;
        }


        @POST
        @Produces("text/html")
        public Request getUnamePswd(){
            AuthenticationModel auth=new AuthenticationModel();

            String Uname="Username@gmail.com";
            String Password="Password";
            String AuthTypeID="12345678";
    //      String Uname="username or practice_Id";


                try {
                    auth.validateUser(Uname,Password,AuthTypeID);
                } catch (NullPointerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }




            return null;




        }


 Can anybody helpme?Any help will be highly appreciable....

Solution

  • resloved the issue by adding the following piece of code inside my program

    return Response.status(201).entity(result).build();
    

    and re-check the installed jars as specified here

    Jersey REST Web Service, Tomcat, Eclipse and 404's