MTOM not working when using SOAPHandler

自作多情 提交于 2019-12-06 16:34:26

The Java JRE comes with a JAX-WS Provider. This provider has what I would consider a bug. If a SoapHandler is added, either by directly getting the HandlerChain or by using a HandlerResolver, the message, which was correctly created using MTOM, is deconstructed and the attachment(s) are placed inline within the SOAP message. If the attachments are large, this can lead to very poor performance or out of memory errors.

The only solution I have found is to use another JAX-WS provider. From testing, Axis2 seems to work perfectly (although it has a huge number of dependencies). Simply placing another provider on the classpath will cause it to be used. Java looks for a file in META-INF/services named javax.xml.ws.spi.Provider. If this file is found, it will use the Provider specified. The main Axis2 jar will include this file to ensure the Axis2 provider is used. Other Providers may also solve this problem.

Because of this automatic Provider detection, you may find your application does or does not have this problem depending on where it is running. For example, if you deploy an application to IBM WebSphere it already has overridden the default Provider and you will not have this issue. Likely other Application Servers also have overridden the default Provider. If you can get ahold of a copy, IBM also provides a very nice jar, com.ibm.jaxws.thinclient_7.0.0.jar, that has Axis2 packaged in it. This can only be used for standalone applications (those not running in WebSphere), but it is very convenient and resolves this issue.

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