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

WSO2 Integration Studio调用SOAP服务报UTF-8编码错误求助

问题描述

我们有一个调用REST服务的序列,在接收序列中会调用一个SOAP服务。传递给该SOAP调用的XML负载如下:

<payloadFactory media-type="xml">
        <format>
            <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
                <env:Header/>
                <S:Body>
                    <ns0:searchCust xmlns:ns0="">
                        <customerData xmlns="">
                            <Instrument/>
                            <EntityInformation>
                                <Individual>
                                    <Name>
                                        <Name Location="First">$1</Name>
                                      
                                    </Name>
                                    <ContactInformation>
                                        <Address/>
                                        <EMail>
                                            <EMailAddress>$3</EMailAddress>
                                        </EMail>
                                    </ContactInformation>
                                </Individual>
                            </EntityInformation>
                        </customerData>
                    </ns0:searchCust>
                </S:Body>
            </S:Envelope>
        </format>
        <args>
           
        </args>
    </payloadFactory>

调用后收到错误响应:

<?xml version='1.0' encoding='utf-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
            <faultcode>S:Client</faultcode>
            <faultstring>Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x8b (at char #2, byte #-1)</faultstring>
        </S:Fault>
    </S:Body>
</S:Envelope>

该SOAP服务通过ESB或soapUI单独调用时可正常运行,但通过WSO2 Integration Studio调用则出现上述错误。相关wirelog如下:

[2023-01-04 17:15:21,061] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "HTTP/1.1 500 Internal Server Error[
][
]"
[2023-01-04 17:15:21,061] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "Date: Wed, 04 Jan 2023 11:45:21 GMT[
][
]"
[2023-01-04 17:15:21,062] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "Transfer-Encoding: chunked[
][
]"
[2023-01-04 17:15:21,063] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "Content-Type: text/xml; charset=utf-8[
][
]"
[2023-01-04 17:15:21,063] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "Strict-Transport-Security: max-age=31536000[
][
]"
[2023-01-04 17:15:21,064] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "X-ORACLE-DMS-RID: 0[
][
]"
[2023-01-04 17:15:21,064] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "X-Content-Type-Options: nosniff[
][
]"
[2023-01-04 17:15:21,065] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "X-ORACLE-DMS-ECID: d53a62da-093e-46c4-8f0b-4aabb22b9e40-00000052[
][
]"
[2023-01-04 17:15:21,065] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "X-Frame-Options: SAMEORIGIN[
][
]"
[2023-01-04 17:15:21,066] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "[
][
]"
[2023-01-04 17:15:21,066] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "006e[
][
]"
[2023-01-04 17:15:21,067] DEBUG {wire} - HTTPS-Sender I/O dispatcher-2 >> "<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>[
][
]"
解决方法

错误提示的Invalid UTF-8 start byte 0x8b通常表示响应内容是GZIP压缩的,但WSO2 Integration Studio未正确处理解压,可通过以下步骤解决:

  • 启用自动解压GZIP响应
    在调用SOAP服务的序列或endpoint中添加配置,开启自动解压:

    <!-- 在序列中添加 -->
    <property name="Accept-Encoding" value="gzip, deflate" scope="transport"/>
    <property name="DISABLE_GZIP_ENCODING" value="false" scope="axis2"/>
    
    <!-- 或直接在endpoint中配置 -->
    <endpoint>
        <address uri="http://your-soap-service-url">
            <property name="Accept-Encoding" value="gzip, deflate" scope="transport"/>
            <property name="DISABLE_GZIP_ENCODING" value="false" scope="axis2"/>
        </address>
    </endpoint>
    
  • 统一请求编码
    在payloadFactory前添加属性,确保请求的Content-Type明确指定UTF-8:

    <property name="Content-Type" value="text/xml; charset=UTF-8" scope="transport"/>
    
  • 修正XML命名空间
    原payload中ns0:searchCust和customerData的命名空间为空,可能导致服务端解析异常,需替换为空的xmlns:ns0=""和xmlns=""为目标服务要求的正确命名空间。

  • 手动验证压缩响应
    若上述操作无效,可通过抓包工具捕获响应,尝试用GZIP解压验证内容是否正常。确认是压缩问题后,也可通过script mediator添加手动解压逻辑。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 17:55:12