Reputation: 1018
I am using Apache-CXF for creating REST web services and trying to submit a form.
Server:
This is my method, which is expected to get json data.
@POST
@Path("/addCustomer/")
@Consumes(MediaType.APPLICATION_JSON)
//{"Customer":{"name":"Some Name","id":6}}
public Customer addCustomer(Customer customer){
logger.debug(customer);
return customer;
}
Client: I am using firefox REST plugin for submitting request: Using REST client, I have posted following json as request body:
{"Customer":{"name":"Arnav Awasthi","id":6}}
But I am getting "415: Unsupported Media Type"
.
Upvotes: 8
Views: 19089
Reputation: 2874
I had the same problem. The solution was to remove the bean class name from the json string. In your case, the Json which should be sent as the body would be,
{"name":"Arnav Awasthi","id":6}
Upvotes: 0
Reputation: 113
I faced the same issue using CXF 2.7.4 with Jasckon 2.X.X . But it was fixed when i upgraded to CXF 2.7.7 . Or use Jackson 1.9.X with CXF 2.7.4 .
Upvotes: 1
Reputation: 3
You have to add custom headers to inform the client what kind of data you are sending back e.g: Header Name: Content-type Header-Value : application/json
Upvotes: 0
Reputation: 2108
I had the same error some time ago. It seems the root reason was exception "No message body reader has been found for request class ".
According to http://www.javatips.net/blog/2012/02/cxf-restful-tutorial I added jettison library to resolve this issue.
Upvotes: 2
Reputation: 96
Sorry for the late answer, but it may serve to others.
You should doublecheck than your Customer class is annotated with JAXB's @XmlRootElement, since jackson needs it to deserialize JSON message.
Upvotes: 2
Reputation: 307
use restclient , a plugin for fire fox and add the http headers as Accept:application/json ,content-type: application/json.
Upvotes: 4
Reputation: 100151
You have to find a way to tell firefox to set the content-type to application/json. The error indicates that it's sending something else.
Upvotes: 2