I am using Apache-CXF for creating REST web services and trying to submit a form.
我正在使用Apache-CXF创建REST Web服务并尝试提交表单。
Server:
This is my method, which is expected to get json data.
服务器:这是我的方法,期望获取json数据。
@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:
客户端:我使用firefox REST插件提交请求:使用REST客户端,我发布了以下json作为请求体:
{"Customer":{"name":"Arnav Awasthi","id":6}}
But I am getting "415: Unsupported Media Type"
.
但我得到“415:不支持的媒体类型”。
7 个解决方案
#1
3
use restclient , a plugin for fire fox and add the http headers as Accept:application/json ,content-type: application/json.
使用restclient,一个fire Fox的插件,并将http标头添加为Accept:application / json,content-type:application / json。
#2
2
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.
你必须找到一种方法告诉firefox将content-type设置为application / json。该错误表明它正在发送其他内容。
#3
2
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.
您应该使用JAXB的@XmlRootElement对Customer类进行双重检查,因为jackson需要它来反序列化JSON消息。
#4
1
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.
根据http://www.javatips.net/blog/2012/02/cxf-restful-tutorial,我添加了jettison库来解决这个问题。
#5
1
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 .
我使用CXF 2.7.4与Jasckon 2.X.X面临同样的问题。但是当我升级到CXF 2.7.7时,它已得到修复。或者使用Jackson 1.9.X和CXF 2.7.4。
#6
0
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
您必须添加自定义标头以通知客户端您要发送的数据类型,例如:标题名称:内容类型标题值:application / json
#7
0
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,
我有同样的问题。解决方案是从json字符串中删除bean类名。在你的情况下,应该作为正文发送的Json,
{"name":"Arnav Awasthi","id":6}
#1
3
use restclient , a plugin for fire fox and add the http headers as Accept:application/json ,content-type: application/json.
使用restclient,一个fire Fox的插件,并将http标头添加为Accept:application / json,content-type:application / json。
#2
2
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.
你必须找到一种方法告诉firefox将content-type设置为application / json。该错误表明它正在发送其他内容。
#3
2
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.
您应该使用JAXB的@XmlRootElement对Customer类进行双重检查,因为jackson需要它来反序列化JSON消息。
#4
1
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.
根据http://www.javatips.net/blog/2012/02/cxf-restful-tutorial,我添加了jettison库来解决这个问题。
#5
1
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 .
我使用CXF 2.7.4与Jasckon 2.X.X面临同样的问题。但是当我升级到CXF 2.7.7时,它已得到修复。或者使用Jackson 1.9.X和CXF 2.7.4。
#6
0
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
您必须添加自定义标头以通知客户端您要发送的数据类型,例如:标题名称:内容类型标题值:application / json
#7
0
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,
我有同样的问题。解决方案是从json字符串中删除bean类名。在你的情况下,应该作为正文发送的Json,
{"name":"Arnav Awasthi","id":6}