title: Web Application Exception: javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
body: <p>I'm using jersey and spring in my application. I don't have any issue when working with any AJAX requests but i get media not supported error when uploading files. I tried several ways, but haven't find any fix for it. Wondering if anyone can help me find the root cause of the issue. Appreciate your help. </p>
  
  <h1>Server side implemention</h1>
  
  <h2>web.xml</h2>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;jersey-servlet&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;javax.ws.rs.Application&lt;/param-name&gt;
          &lt;param-value&gt;org.blanc.whiteboard.RestResourceApplication&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;org.glassfish.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.server.provider.classnames&lt;/param-name&gt;
          &lt;param-value&gt;org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <h2>resource class</h2>
  
  <pre><code>@Path("/upload")
  @POST
  //@Consumes({ MediaType.MULTIPART_FORM_DATA })
  public Response uploadAsset(@Context SecurityContext sc,
          MultipartHttpServletRequest request) {
      User user = loadUserFromSecurityContext(sc);
      MultipartFile file = null;
      // 1. build an iterator
      Iterator&lt;String&gt; itr = request.getFileNames();
      // 2. get each file
      while (itr.hasNext()) {
          // 2.1 get next MultipartFile
          file = request.getFile(itr.next());
          if (file == null) {
              throw new FileUploadException("File is null.");
          }
          LOG.info(file.getOriginalFilename() + " uploaded! " + files.size());
          // 2.2 if files &gt; 10 remove the first from list
          if (files.size() &gt; 10)
              files.pop();
  
      }
      return Response.ok().build();
  }
  </code></pre>
  
  <h2>pom.xml</h2>
  
  <pre><code>    &lt;jersey.version&gt;2.20&lt;/jersey.version&gt;
     .....
          &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.ext&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-spring3&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
                  &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-common&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
          &lt;version&gt;${jersey.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- File upload --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
          &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
          &lt;version&gt;${commons-fileupload.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-io&lt;/groupId&gt;
          &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
          &lt;version&gt;${commons-io.version}&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <h1>Error :</h1>
  
  <pre><code>Aug 12, 2015 7:21:58 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 4 * Server responded with a response on thread http-bio-8080-exec-5
  4 &lt; 200
  4 &lt; Access-Control-Allow-Headers: X-HTTP-Method-Override, Content-Type, x-requested-with, Authorization, Cache-Control
  4 &lt; Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
  4 &lt; Access-Control-Allow-Origin: http://localhost:9000
  4 &lt; Access-Control-Max-Age: 3600
  4 &lt; Content-Type: application/json
  
  Aug 12, 2015 7:22:15 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 5 * Server has received a request on thread http-bio-8080-exec-1
  5 &gt; OPTIONS http://localhost:8080/v1.0/assets/upload
  5 &gt; accept: */*
  5 &gt; accept-encoding: gzip, deflate, sdch
  5 &gt; accept-language: en-US,en;q=0.8
  5 &gt; access-control-request-headers: accept, cache-control, content-type, x-requested-with
  5 &gt; access-control-request-method: POST
  5 &gt; cache-control: no-cache
  5 &gt; connection: keep-alive
  5 &gt; host: localhost:8080
  5 &gt; origin: http://localhost:9000
  5 &gt; pragma: no-cache
  5 &gt; referer: http://localhost:9000/debug.html
  5 &gt; user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
  
  Aug 12, 2015 7:22:15 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 5 * Server responded with a response on thread http-bio-8080-exec-1
  5 &lt; 200
  5 &lt; Access-Control-Allow-Headers: X-HTTP-Method-Override, Content-Type, x-requested-with, Authorization, Cache-Control
  5 &lt; Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
  5 &lt; Access-Control-Allow-Origin: http://localhost:9000
  5 &lt; Access-Control-Max-Age: 3600
  5 &lt; Allow: POST,OPTIONS
  5 &lt; Content-Type: application/vnd.sun.wadl+xml
  5 &lt; Last-modified: Wed, 12 Aug 2015 19:22:15 EDT
  
  Aug 12, 2015 7:22:15 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 6 * Server has received a request on thread http-bio-8080-exec-10
  6 &gt; POST http://localhost:8080/v1.0/assets/upload
  6 &gt; accept: application/json
  6 &gt; accept-encoding: gzip, deflate
  6 &gt; accept-language: en-US,en;q=0.8
  6 &gt; cache-control: no-cache
  6 &gt; connection: keep-alive
  6 &gt; content-length: 108054
  6 &gt; content-type: multipart/form-data; boundary=----WebKitFormBoundarywS3v9iwIqD3NwnYt
  6 &gt; host: localhost:8080
  6 &gt; origin: http://localhost:9000
  6 &gt; pragma: no-cache
  6 &gt; referer: http://localhost:9000/debug.html
  6 &gt; user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
  6 &gt; x-requested-with: XMLHttpRequest
  
  19:22:15.340 [http-bio-8080-exec-10] INFO  o.b.w.r.GenericExceptionMapper - Web Application Exception: **javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type**
  Aug 12, 2015 7:22:15 PM org.glassfish.jersey.filter.LoggingFilter log
  INFO: 6 * Server responded with a response on thread http-bio-8080-exec-10
  6 &lt; 415
  6 &lt; Access-Control-Allow-Headers: X-HTTP-Method-Override, Content-Type, x-requested-with, Authorization, Cache-Control
  6 &lt; Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
  6 &lt; Access-Control-Allow-Origin: http://localhost:9000
  6 &lt; Access-Control-Max-Age: 3600
  </code></pre>
  
  <p>On front end i'm using <code>[dropzone][1]</code></p>