繁体   English   中英

如何禁用 cxf SOAP 客户端使用多部分请求

[英]How to disable cxf SOAP client use multipart request

我必须调用不支持多部分请求的专有服务,我没有发送任何附件,但 cxf 似乎创建了一个多部分请求

POST /endpoint HTTP/1.1
Content-Type: multipart/related; type="text/xml"; boundary="uuid:86ebef4f-fc2a-431b-a21b-37e86b4901f9"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Accept: */*
Authorization: Basic U1dHMTAwNTA6MTIzNDU1
SOAPAction: "XYZ.0050"
User-Agent: Apache-CXF/3.3.6
Cache-Control: no-cache
Pragma: no-cache
Host: localhost:8082
Connection: keep-alive
Content-Length: 2134


--uuid:86ebef4f-fc2a-431b-a21b-37e86b4901f9
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
[etc...]

我注意到非多部分请求工作正常

POST /endpoint HTTP/1.1
Content-Type: text/xml;charset=UTF-8
Accept: */*
Authorization: Basic U1dHMTAwNTA6MTIzNDU1
Cache-Control: no-cache
Connection: keep-alive
Host: localhost:8082
Pragma: no-cache
SOAPAction: "XYZ.0050"
User-Agent: Apache-CXF/3.3.6
Content-Length: 2114

[etc...]

如何强制 cxf 使用非多部分请求?

看起来 cxf 会在有@XmlAttachmentRef / DataHandler属性的任何时候创建一个多部分,在我的情况下它从未使用过,所以我从我的类中删除了它。

更好的解决方案是通过定义拦截器移除器从拦截器链中移除SwAOutInterceptor

class InterceptorRemover : AbstractSoapInterceptor(Phase.PRE_LOGICAL) {
    init {
        addBefore(SwAOutInterceptor::class.java.name)
    }
    override fun handleMessage(message: SoapMessage?) {
        if (message != null) {
            val res = message.interceptorChain.firstOrNull() { it is SwAOutInterceptor }
            if (res != null) {
                message.interceptorChain.remove(res)
            }
        }
    }
}

并将其添加到链中:

val client = ClientProxy.getClient(port)
client.outInterceptors.add(InterceptorRemover())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM