Apache CXF: Consume XML POST payload with “application/x-www-form-urlencoded” content type set

≯℡__Kan透↙ 提交于 2019-12-24 03:26:29

问题


We got a REST service implemtented in Apache CXF available for our client exposed like this:

@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.TEXT_PLAIN)
@Path("/process")
public Response processBean(Bean bean);

The Bean object is annotated with @XmlRootElement and all this works great. The problem is that the client is not setting the right content-type (should be "application/xml" but client sets "application/x-form-urlencoded").

Apache CXF is not regonizing the method as a valid method for the (incorrect) call since the content-type is wrong. If I change @Consumes to "/ or application/x-www-form-urlencode" Apache CXF does not know how to parse the POST payload (no MessageBodyReader). The client will eventually change the header but we need a quick fix for now.

Any ideas? Do I need to use some XmlMessageBodyReader?


回答1:


I'd recommend taking at look a using a filter to modify the content type to the value that your code is expecting.



来源:https://stackoverflow.com/questions/8010595/apache-cxf-consume-xml-post-payload-with-application-x-www-form-urlencoded-co

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!