title: How to deploy REST web service to AWS?
body: <p><strong>What is need to be done?</strong></p>
  
  <p>Deploy web application with web service(REST) on AWS. (Tomcat server)</p>
  
  <p><strong>What I have done?</strong></p>
  
  <p>Build web application with REST web service. Tested locally successfully. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>Now when I deploy it to the AWS using elastic beanstalk giving <strong>404 error.</strong></p>
  
  <p><strong>My Web Service code</strong></p>
  
  <pre><code>@Path("/abc")
  public class registerService {
      @POST
      @Path("/crunchifyService")
      @Consumes(MediaType.APPLICATION_JSON)
      public Response crunchifyREST(InputStream incomingData) {
          StringBuilder crunchifyBuilder = new StringBuilder();
          try {
              BufferedReader in = new BufferedReader(new InputStreamReader(incomingData));
              String line = null;
              while ((line = in.readLine()) != null) {
                  crunchifyBuilder.append(line);
              }
          } catch (Exception e) {
              System.out.println("Error Parsing: - ");
          }
          System.out.println("Data Received: " + crunchifyBuilder.toString());
  
          User userObject = new Gson().fromJson(crunchifyBuilder.toString(), User.class);
          System.out.println("JSon object: " + userObject.getSurname());
          int status = RegisterDao.register(userObject);
          if(status == 1)
          {
  
  
  
          }else{
              System.out.println("Failed again");
  
          }
  
          // return HTTP response 200 in case of success
          return Response.status(200).entity(crunchifyBuilder.toString()).build();
      }
  
      @GET
      @Path("/verify")
      @Produces(MediaType.TEXT_PLAIN)
      public Response verifyRESTService(InputStream incomingData) {
          String result = "CrunchifyRESTService Successfully started..";
  
          // return HTTP response 200 in case of success
          return Response.status(200).entity(result).build();
      }
  
  
       @GET
         @Path("/users")
         @Produces(MediaType.TEXT_PLAIN)
         public Response getUsers(){
            return Response.status(200).entity("Done").build();
         }
  }
  </code></pre>
  
  <p>REST client code</p>
  
  <pre><code>&lt;%
  
   String json = new Gson().toJson(u);
  System.out.println(json);
  
  try {
    URL url = new URL("http://storageserver-env.sa-east-1.elasticbeanstalk.com/MyApplicationName/api/abc/crunchifyService");
      URLConnection connection = url.openConnection();
      connection.setDoOutput(true);
      connection.setRequestProperty("Content-Type", "application/json");
      connection.setConnectTimeout(5000);
      connection.setReadTimeout(5000);
      OutputStreamWriter out1 = new OutputStreamWriter(connection.getOutputStream());
      out1.write(json);
      out1.close();
  
      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  
      while (in.readLine() != null) {
      }
      System.out.println("\nCrunchify REST Service Invoked Successfully..");
      in.close();
  } catch (Exception e) {
      System.out.println("\nError while calling Crunchify REST Service");
      System.out.println(e);
  }
  
  %&gt;
  </code></pre>
  
  <p>My server log says</p>
  
  <blockquote>
    <p>127.0.0.1 - - [09/Apr/2016:13:38:05 +0000] "POST /SecureStorage/api/abc/crunchifyService HTTP/1.1" 404 1070</p>
    
    <p>**</p>
  </blockquote>
  
  <p><strong>Web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
    &lt;display-name&gt;SecureStorage&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;
      createTable.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
     &lt;servlet&gt;
        &lt;servlet-name&gt;Application&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
           &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;registration&lt;/param-value&gt;
           &lt;/init-param&gt;
        &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
     &lt;servlet-name&gt;Application&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>