1

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....
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Miller
  • 744
  • 3
  • 15
  • 39
  • 1
    I can barely see the url in the screenshot. Can you type it outside it? – Claudio Apr 17 '15 at 15:09
  • Without seeing your url, are you sure that tomcat is not using a context to run your application. Try typing `http://localhost:8080/[your_app_context_probably_your_war_name]/rest/...` – Claudio Apr 17 '15 at 15:10
  • http://localhost:9090/Snapshothealthapp1/rest this is my url.Upto "http://localhost:9090/Snapshothealthapp1/ "i am getting the tomcat webpage correctly.But adding rest wont works... – Miller Apr 17 '15 at 15:11
  • @claudio Is there any problem with adding my servlet mapping – Miller Apr 17 '15 at 15:13
  • You got @Path("/customers") at class level, then @Path("/get") at method level. Have you tried the url http://localhost:9090/Snapshothealthapp1/rest/get ? I would have removed the @Path("/get")... – Karl-Bjørnar Øie Apr 18 '15 at 20:23
  • @Karl-BjørnarØie i was tried it earlier, but getting same error.But now that 404 error is resolved.I was commented return Response.status(201).entity(result).build(); this code – Miller Apr 20 '15 at 05:03
  • @Karl-BjørnarØie but now getting 405 error while calling this url http://localhost:9090/Snapshothealthapp1/rest/customers error getting is method not found(405).I am testing it on eclipse itself – Miller Apr 20 '15 at 05:04

1 Answers1

0

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

Community
  • 1
  • 1
Miller
  • 744
  • 3
  • 15
  • 39