title: jersey webservice returns a 415 when executing a PUT from Ext.Ajax.request
body: <p>So, I've got a pretty simple RESTful jersey webservice, and I'm wanting to call it from my javascript code.  I have no problem executing a GET request, but for some reason, when I execute a PUT, I get back a "415 Unsupported Media Type" error.  Any idea what I'm doing wrong?</p>
  
  <p>Here's my webservice :</p>
  
  <pre><code>package servlet;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.xml.bind.JAXBElement;
  
  import com.mycompany.www.hudsonsemaphore.HudsonResult;
  import com.mycompany.www.hudsonsemaphore.SemaphoreConstants;
  
  @Path("/HudsonSemaphore")
  public class HudsonSemaphore {
      static private HudsonResult lastResult;
      static private Object RESULT_LOCK = new Object();       
  
      @PUT
      @Consumes({MediaType.APPLICATION_JSON})
      static public void setResult(JAXBElement&lt;HudsonResult&gt; result) {        
          synchronized(RESULT_LOCK) {
              lastResult=result.getValue();
          }       
      }   
  
      @GET
      @Produces({MediaType.APPLICATION_JSON})
      public HudsonResult getLastResult() {
          HudsonResult toReturn;
  
          if(lastResult!=null) {
              synchronized(RESULT_LOCK) {
                  toReturn = lastResult;
                  lastResult=null;
              }
          }
          else {
              toReturn = SemaphoreConstants.NULL_HUDSON_RESULT;
          }
  
          return toReturn;
      }       
  }
  </code></pre>
  
  <p>Here's my annotated JAXBElement :</p>
  
  <pre><code>package com.mycompany.www.hudsonsemaphore;
  
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  import javax.xml.bind.annotation.XmlType;
  
  @XmlRootElement(name="hudsonResult")
  @XmlType(propOrder = { 
      "message", "success"
  })
  public class HudsonResult {
      private boolean success;
      private String message; 
  
      public HudsonResult() {
          success=false;
          message=null;
      }
  
      public HudsonResult(String message, boolean success) {
          this.success = success;
          this.message = message;     
      }
  
      @XmlElement
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message=message;
      }
  
      public void setSuccess(boolean success) {
          this.success=success;
      }
  
      @XmlElement
      public boolean isSuccess() {
          return success;
      }
  
      public boolean equals(HudsonResult result) {
          return(result.success == success &amp;&amp; result.message.equals(message));
      }
  
      public String toString() {
          return "Success : [" + String.valueOf(success) + "] Message : [" + message + "]";
      }
  }
  </code></pre>
  
  <p>And finally, here's my javascript code :</p>
  
  <pre><code>&lt;script type="text/javascript" src="/system/workplace/resources/ext/ext-base.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/system/workplace/resources/ext/ext-all.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
  function pollSemaphore() {
      Ext.Ajax.request({
          url : 'http://localhost:8081/leadcapture/rest/HudsonSemaphore',
          method: 'GET',
          success: 
              function(result, request) {
                  var jsonData = Ext.util.JSON.decode(result.responseText);
  
                  if(jsonData.success=='true') {
                      alert('SUCCESS : ' + jsonData.message);
                  }
                  else {
                      alert('NOT SUCCESS : ' + result.responseText);  
                  }
              },
          failure: 
              function(result, request) {
                  alert('Teh fail : ' + result.responseText);
              }
      });
  }
  
  function pushSemaphore() {
      Ext.Ajax.request({
          url : 'http://localhost:8081/leadcapture/rest/HudsonSemaphore',
          method: 'PUT',
          params: {message : 'Brand new car!', success : 'true'},
          success: 
              function(result, request) {
                  alert('YOU RULE!');
              },
          failure: 
              function(result, request) {
                  alert('Teh fail : ' + result.responseText);
              }
      });
  }
  
  &lt;/script&gt;
  
  &lt;input type="button" onclick="pushSemaphore()" value="Push"/&gt; &lt;br/&gt;
  &lt;input type="button" onclick="pollSemaphore()" value="Poll"/&gt; &lt;br/&gt;
  </code></pre>
  
  <p>Thanks for taking a look!</p>