RSSD RSSD - 5 months ago 38
Java Question

JAX-RS POST method 415 Unsupported Media Type

I know there are some threads with the same question, however I don't get it running properly. I'm still very new at this.

I have a JAX-RS server running:


method works. The
method does not.

public Response post(Movie movie){
System.out.println("In the POST method");

String result = movie.toString();

return Response.status(201).entity(result).build();

In my Oracle JET Client I want to make a post:

addMovie = function(){
console.log("post sent");
type: "POST",
url: "http://localhost:8080/MovieRestService/resources/movies",
headers: {

"Content-Type": "application/json"
id: 2,
name: "test",
director: "test",
year: 234
success: "success",
dataType: 'application/json'

It keeps giving me a
415 Unsupported Media Type
Something that seems a little bit odd to me is that in the response header the content type is text/html
Content-Type: text/htlm

Anyone has a solution?


After lots of searching on the web I finally managed to find out what the real problem is... It seems that Glassfish 4.1.1 has a bug in it what was causing the problems while making a post to my server...


This should work

    var url = 'http://localhost:8080/MovieRestService/resources/movies';
    var sucessCallback = function(response) {...}
    var data = JSON.stringify({
                    id: 2,
                    name: "test",
                    director: "test",
                    year: 234
        url: url,
        method: POST,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: data,
        cache: false,
        context: this,