Apache CXF:使用带有"application/x-www-form-urlencoded"的XML POST负载来消费XML POST负载内容类型集 [英] Apache CXF: Consume XML POST payload with "application/x-www-form-urlencoded" content type set

查看:64
本文介绍了Apache CXF:使用带有"application/x-www-form-urlencoded"的XML POST负载来消费XML POST负载内容类型集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们为客户端公开了Apache CXF内置的REST服务,如下所示:

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);

Bean 对象用@XmlRootElement注释,并且所有这些都很好用.问题在于客户端未设置正确的内容类型(应为"application/xml",但客户端设置为"application/x-form-urlencoded").

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不会将该方法重新格式化为(错误的)调用的有效方法.如果将@Consumes更改为"/或application/x-www-form-urlencode",则Apache CXF不知道如何解析POST负载(没有MessageBodyReader).客户最终将更改标头,但现在我们需要快速修复.

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.

有什么想法吗?我需要使用一些XmlMessageBodyReader吗?

Any ideas? Do I need to use some XmlMessageBodyReader?

推荐答案

我建议您使用

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

这篇关于Apache CXF:使用带有"application/x-www-form-urlencoded"的XML POST负载来消费XML POST负载内容类型集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆