title: Jersey's POST method usage with embedded jetty
body: <p>I have simple REST service at embedded Jetty:</p>
  
  <pre><code>    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty&lt;/artifactId&gt;
          &lt;version&gt;${jetty.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
           &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
           &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
           &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-servlet&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  package test;
  </code></pre>
  
  <p>Class with REST service:</p>
  
  <pre><code>import javax.ws.rs.*;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  @Path("/test")
  public class TestRESTService {
      @Path("/get")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public Response get() {
          return Response.ok(new SimplePOJO("test get ok")).build();
      }
  
  
      @Path("/post")
      @POST
      @Produces(MediaType.APPLICATION_JSON)
      public Response post(@FormParam("data") String data) {
          return Response.ok("your data is: " + data).build();
      }
  
      public static class SimplePOJO {
          private String message;
  
          public SimplePOJO(String message) {
              this.message = message;
          }
  
          public String getMessage() {
              return message;
          }
  
          public void setMessage(String message) {
              this.message = message;
          }
  
      }
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>package test;
  
  import com.sun.jersey.spi.container.servlet.ServletContainer;
  import org.mortbay.jetty.Server;
  import org.mortbay.jetty.servlet.ServletHolder;
  
  public class JettyStart {
      public static void main(String[] args) {
          final Server server = new Server(8888);
  
          final org.mortbay.jetty.servlet.Context ctxRest = new org.mortbay.jetty.servlet.Context(server, "/rest");
          final ServletHolder jerseyServletHolder = ctxRest.addServlet(ServletContainer.class, "/*");
          jerseyServletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
                  "com.sun.jersey.api.core.PackagesResourceConfig");
          jerseyServletHolder.setInitParameter("com.sun.jersey.config.property.packages",
                  TestRESTService.class.getPackage().getName());
          jerseyServletHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
          ctxRest.addServlet(jerseyServletHolder, "/*");
  
          try {
              server.start();
          } catch (Exception ignore) {
              server.destroy();
          }
      }
  }
  </code></pre>
  
  <p>When I'm trying to access <a href="http://localhost:8888/rest/test/post" rel="nofollow">http://localhost:8888/rest/test/post</a> via ajax call - it's works fine.</p>
  
  <pre><code>$.ajax({
      url : "http://localhost:8888/rest/test/post",
      type : "POST",
      async : false,
      data: {
          data: "test data"
      }
  });
  
  Object {readyState: 4, responseText: "your data is: test data", status: 200, statusText: "OK"}
  </code></pre>
  
  <p>But when I use curl I getting <em>null</em> as data
  parameter.</p>
  
  <pre><code>curl -X POST -H "Content-Type: application/json" -d "{\"data\":\"test data\"}" http://localhost:8888/rest/test/post
  
  your data is: null
  </code></pre>
  
  <p>My question is: what's I'm doing wrong?</p>