首页 > 解决方案 > 如何在 mule 4 的 Web 服务使用者组件中传递 Bearer Token?

问题描述

我需要以以下格式将承载令牌传递给下游系统(使用 web 服务使用者组件连接)。

Bearer [token value]

我尝试使用键传递它的内联标头:Bearer and Value= token value 但它不起作用。我试图通过下面的 XML:

%dw 2.0
output application/xml
 ---
headers : {
   Authorization: {
    "Bearer " ++ vars.licenseServerTocken
}
}

但得到以下错误:

"Error trying to acquire a new connection:Error fetching the resource [https://abc123.com/xyz/Contract.svc?wsdl]: Server returned HTTP response code: 500 for URL: https://abc123.com/xyz/Contract.svc?wsdl"

当我在正文中按以下方式传递时,它正在从 SOAP UI 工作

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tem.org/">
   <soapenv:Header>
   <Authorization>Bearer sada3123gjkada1231</Authorization>
   </soapenv:Header>
   <soapenv:Body>

请建议

标签: soapmule

解决方案


Authorization 标头不是 SOAP 请求的一部分,也不是 SOAP 标头。它是作为 SOAP 请求传输的 HTTP 请求的一部分。所以你需要在传输头部分定义。

例子:

    <wsc:consume doc:name="Consume" config-ref="Web_Service_Consumer_Config" operation="MyService">
        <wsc:message >
            <wsc:body > ... </wsc:body>
        </wsc:message>
        <wsc:transport-headers >
            <wsc:transport-header key="Authorization" value="#['Bearer ' ++  vars.licenseServerTocken ]" />
        </wsc:transport-headers>
    </wsc:consume>

推荐阅读