title: RESTful Web Service eclipse
body: <p>I followed a very nice tutorial and it works smoothly for the <code>GET</code> http method, but for some reason when I try to access the <code>POST</code> or <code>PUT</code> methods the server returns:</p>
  
  <blockquote>
    <p>HTTP Status 405 - Method Not Allowed</p>
  </blockquote>
  
  <p>So this is what I did in the tutorial, </p>
  
  <ul>
  <li>I created a new dynamic web project</li>
  <li>I imported the jersey RESTful implementation</li>
  <li>I created a new java class and set some jersey annotations</li>
  <li>I edited the web.xml file for it to create a servlet on start up with some Jersey set up and point it to my Java class mapping it.</li>
  </ul>
  
  <p>That's it, I ran the app on a tomcat 6 app server.</p>
  
  <p>So when I follow the path of my class and I hence a <code>@GET</code> method it works smoothly but when i try to replace the <code>@GET</code> annotation with <code>@POST</code> it return the error above.</p>
  
  <p>The web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><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" 
           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"&gt;
  
    &lt;display-name&gt;RESTfulTest&lt;/display-name&gt;
  
    &lt;servlet&gt;
        &lt;servlet-name&gt;NAME&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
            &lt;param-value&gt;com.RESTful.Test&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;NAME&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
   &lt;/web-app&gt;
  </code></pre>
  
  <p>My Java class with the jersey annotations:</p>
  
  <pre><code>package com.RESTful.Test;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  @Path("/resttest")
  public class Test {
  
      //this WORKS!
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String getTestString()
      {
          return "Hello this is a test post";
      }
      //this returns the error
      @POST
      @Produces(MediaType.TEXT_PLAIN)
      public String getTestString2()
      {
          return "Hello this is a test post";
      }
      //this returns the error
      @PUT
      @Path("{param1}")
      @Produces(MediaType.TEXT_PLAIN)
      public String getTstWithInput(@PathParam("/param1") 
              String param)
      {
          return "hello "+param;
      }
      //this returns the error
      @PUT
      @Path(value="/putTest")
      @Produces(MediaType.TEXT_PLAIN)
      public String getTstWithInput2(@PathParam("/param1") 
              String param)
      {
          return "hello "+param;
      }
  }
  </code></pre>
  
  <p>Please note that I have tried documenting all but the method I'm testing with the same results. I know I can't run some of them at the same time, they are all just tests.</p>
  
  <p>I'm calling the REST resources from URL:</p>
  
  <ul>
  <li><p>"http://localhost/RESTfulTest/rest/resttest/" </p></li>
  <li><p>"http://localhost/RESTfulTest/rest/resttest/myname" </p></li>
  <li><p>"http://localhost/RESTfulTest/rest/resttest/putTest" </p></li>
  </ul>