需要帮助将 Mule 连接器从 3.9 转换为 4.5

问题描述 投票:0回答:1

我们正在努力将现有的 Mule 连接器从版本 3.9 转换为 4.5.0(社区版),我发现了一个我不知道如何转换的连接器。它调用 Microsoft Outlook 的 OAuth URL 并返回令牌。旧版本看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd">
    <context:property-placeholder location="connect.properties" />
    <http:listener-config name="HTTP_Listener_Configuration"
        host="0.0.0.0" port="8081" basePath="/base" doc:name="HTTP Listener Configuration" />
    <http:request-config name="HTTP_Request_Configuration"
        protocol="HTTPS" host="login.microsoftonline.com" port="443"
        basePath="${outlook.base}" doc:name="HTTP Request Configuration" />
    <flow name="TokenProviderFlow">
        <http:listener config-ref="HTTP_Listener_Configuration"
            path="/path" doc:name="HTTP" />
        <set-payload doc:name="Set Payload"
            value="#[{'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]" />
        <http:request config-ref="HTTP_Request_Configuration"
            path="/oauth2/v2.0/token" method="POST" doc:name="HTTP" />
    </flow>
</mule>

我的新版本(不起作用)如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <configuration-properties file="connect.properties" />
    <http:listener-config name="HTTP_Listener_config" basePath="/base">
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <http:request-config name="HTTP_Request_configuration" basePath="${outlook.base}">
        <http:request-connection protocol="HTTPS" host="login.microsoftonline.com" port="443" />
    </http:request-config>
    <flow name="tokenproviderFlow">
        <http:listener config-ref="HTTP_Listener_config" path="/path" />
        <set-payload value="#[{'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]" />
        <http:request config-ref="HTTP_Request_configuration" method="POST" path="/oauth2/v2.0/token" />
    </flow>
</mule>

我的新版本返回的 http 状态为 400(错误请求)。关于如何进行这项工作有什么建议吗?

mule mulesoft
1个回答
0
投票

找到答案了!我删除了 set-payload 组件并向 http:request 组件添加了一个主体:

<http:request config-ref="HTTP_Request_configuration" method="POST" path="/oauth2/v2.0/token">
    <http:body><![CDATA[#[output application/x-www-form-urlencoded --- {'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]]]></http:body>
</http:request>
© www.soinside.com 2019 - 2024. All rights reserved.