You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Integration添加API密钥后SOAPAction为空问题求助

问题原因分析

你遇到的这个问题核心在于自定义soapHeaderMapper覆盖了默认的头映射规则:

原来的代码中,<int-ws:soap-action>会把SOAPAction值写入Spring Integration消息的WsHeaders.SOAP_ACTION(对应常量值http://spring.io/spring-ws/soap-action)头中,默认的SOAP头映射器会自动识别这个特殊头,并将其转换为SOAP请求的SOAPAction HTTP头。

但当你添加mapped-request-headers="soapHeaderMapper"后,你指定的DefaultSoapHeaderMapper只配置了映射api-key头,并没有包含WsHeaders.SOAP_ACTION这个特殊头。因此,原来设置的SOAPAction消息头没有被映射到实际的SOAP请求中,导致第三方API收到空的SOAPAction头,进而抛出SoapFaultClientException。

解决方案

你只需要修改soapHeaderMapper的配置,把WsHeaders.SOAP_ACTION对应的头名加入到requestHeaderNames列表中即可,这样既能传递api-keySOAP头,也能保留SOAPAction的正确传递:

<bean id="soapHeaderMapper" class="org.springframework.integration.ws.DefaultSoapHeaderMapper">
    <property name="requestHeaderNames">
        <list>
            <value>api-key</value>
            <!-- 添加SOAPAction对应的消息头 -->
            <value>http://spring.io/spring-ws/soap-action</value>
        </list>
    </property>
</bean>

或者,如果你更倾向于使用常量(避免硬编码字符串),可以直接引用WsHeaders.SOAP_ACTION:

<bean id="soapHeaderMapper" class="org.springframework.integration.ws.DefaultSoapHeaderMapper">
    <property name="requestHeaderNames">
        <list>
            <value>api-key</value>
            <value>#T(org.springframework.ws.messaging.core.WsHeaders).SOAP_ACTION</value>
        </list>
    </property>
</bean>
额外说明
  • 如果你担心遗漏其他必要的头,也可以设置setMapAllRequestHeaders(true),但这会映射所有消息头到SOAP请求中,可能带来不必要的开销或安全风险,因此不推荐这种方式。
  • 修改后,你的<int-ws:soap-action>配置依然生效,它会继续将${service.soapaction}的值写入WsHeaders.SOAP_ACTION头,然后通过soapHeaderMapper映射到SOAP请求的SOAPAction HTTP头中。

内容的提问来源于stack exchange,提问作者Lakshman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:13:53