如何在JAX-WS中禁用fastinfoset并始终返回XML结果 [英] How to Disable fastinfoset in JAX-WS and always return XML results

查看:123
本文介绍了如何在JAX-WS中禁用fastinfoset并始终返回XML结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了Java 8本机JAX-WS Web服务,该服务将xml响应作为二进制XML返回.但是,不幸的是,客户端不支持fastinfoset.我可以使用一种配置来关闭fastinfoset,并且无论客户端通过HTTP请求标头传递给webservice的什么,都以纯XML格式使webservice返回响应吗?

I have implemented a Java 8 native JAX-WS webservice that is returning xml responses as binary XML. However, the client unfortunately does not support fastinfoset. Is there a configuration I can use that switches off fastinfoset, and make the webservice return responses in plain XML no matter what the client passes to the webservice in the HTTP request header?

推荐答案

所述JAX-WS RI/Metro用户指南,启用/禁用FastInfoset完全由客户端通过标准的Accept和Content-Type HTTP标头驱动(假设Web服务支持Fast Infoset).在Web服务上支持/启用FastInfoset时,这是标准行为.实际上,默认情况下,在Metro中默认启用了FastInfoset.因此,如果客户端不支持它,则至少它不应在对Web服务的请求的接受"标头中包含application/fastinfoset.

As mentioned on JAX-WS RI/Metro user guide, enabling/disabling FastInfoset is completely driven by the client via standard Accept and Content-Type HTTP headers (assuming the webservice supports Fast Infoset). This is the standard behavior, when FastInfoset is supported/enabled on the web service. Actually, FastInfoset happens to be enabled by default in Metro. So if the client does not support it, at least it should not include application/fastinfoset in the Accept header of the requests to the webservice.

如果您想完全关闭Metro Web服务上的FastInfoset支持,则可以使用.有关更多详细信息,请参见 Netbeans文档.您将在窗口底部看到一个标记为 Disable Fast Infoset 的复选框.应用此功能应导致在WSDL中像下面这样添加一个新的WS-Policy断言:

If you want to turn off FastInfoset support completely on a Metro web service, you can use the Web Service "Quality of Service" configuration GUI of Netbeans IDE. More details on this in Netbeans documentation. You will see at the bottom of the window a checkbox labeled Disable Fast Infoset. Applying this should result in the addition of a new WS-Policy assertion in your WSDL like this one:

<fi:OptimizedFastInfosetSerialization enabled="false"/>

...,其中fi是(特定于都市的)命名空间http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service的前缀.假设您使用了WSDL-first方法.请注意,尽管WS-Policy是一个标准,但不是这个断言,它只能由Metro堆栈使用.

... where fi is a prefix for (Metro-specific) namespace http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service. This assumes that you used a WSDL-first approach. Note that although WS-Policy is a standard, this assertion is not, it is meant to be used by Metro stack only.

通常,每当您想使用高级JAX-WS Web服务功能(例如消息优化(MTOM,快速信息集...)或WS- *标准(WS-Policy,WS-Security ...)时, ),如果您买不起商业工具,我强烈建议您将Netbeans IDE与WSDL-first方法一起使用,至少要生成/修改WSDL(特别是,如果没有这样的适当工具,则编辑WS-Policy断言会非常费力) .实际上,NetBeans GUI允许您发现比Metro用户指南中实际记录的功能更多的功能. 如果您已经使用了Eclipse等其他IDE,则可以始终将生成的WSDL和关联文件复制到Eclipse项目,并照常在用户指南中应用Eclipse的JAX-WS RI/Metro准则.特别是,您可能还需要在类路径上添加Metro JAR,因为本机JDK中未提供大多数这些功能.

On a general note, whenever you want to play with advanced JAX-WS web service features such as message optimization (MTOM, Fast Infoset...) or WS-* standards (WS-Policy, WS-Security...) and if you cannot afford commercial tools, I stronly recommend you use Netbeans IDE with the WSDL-first approach, at least to generate/modify the WSDL (in particular, editing WS-Policy assertions is quite laborious without a proper tool like this). Indeed, the Netbeans GUI allows you to discover more features than what is actually documented in Metro user guide. If you already use another IDE like Eclipse or whatever), you can always copy the generated WSDL and associated files to your Eclipse project and apply the JAX-WS RI/Metro guidelines for Eclipse in the user guide as usual. In particular, you may need to add Metro JAR on your classpath as well, since most of these features are not provided in native JDK.

这篇关于如何在JAX-WS中禁用fastinfoset并始终返回XML结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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