futureelite7 futureelite7 - 1 month ago 10
Java Question

How to Disable fastinfoset in JAX-WS and always return XML results

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?


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.

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"/>

... 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.

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). Then you can always copy generated files to your Eclipse project or whatever IDE you are using. 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 RI).