【问题标题】:Basic authentication in mule has no effect using the MEL expressionmule 中的基本身份验证使用 MEL 表达式无效
【发布时间】:2018-01-28 03:25:35
【问题描述】:

mule 中的基本身份验证使用 MEL 表达式无效。 如何使用户名和密码动态化?

【问题讨论】:

标签: mule


【解决方案1】:

我可以看到在这种类似的情况下打开了一个错误,其中流变量在 HTTP 配置中被动态使用:- https://www.mulesoft.org/jira/browse/MULE-8895

需要检查您使用的是哪个 Mule 版本...它应该可以从 Mule 版本 3.7+

或者你可以试试下面的例子:-

   <http:listener-config name="HTTP_Listener_Configuration2" host="0.0.0.0" port="8089" doc:name="HTTP Listener Configuration"/>

     <http:request-config name="HTTP_Request_Configuration" host="#[flowVars['urlHost']]" port="#[flowVars['urlHostPort']]" doc:name="HTTP Request Configuration"/>

     <flow name="muleclientFlow">
         <http:listener config-ref="HTTP_Listener_Configuration2" path="/test" doc:name="HTTP"/>
         <set-payload value="gdfgdfgdgsd" doc:name="Set Payload"/>
         <set-variable variableName="urlHost" value="localhost" doc:name="Variable"/>
         <set-variable variableName="urlHostPort" value="8081" doc:name="Variable"/>

         <set-variable variableName="urlHostUser" value="anon" doc:name="Variable"/>
         <set-variable variableName="urlHostPassword" value="anon" doc:name="Variable"/>
        <set-variable variableName="basic_credentials" value="#[flowVars.urlHostUser+':'+flowVars.urlHostPassword]" doc:name="Variable"/>

         <http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP">
            <http:request-builder>
              <http:header headerName="Authorization" value="#['Basic ' + org.apache.commons.codec.binary.Base64.encodeBase64String(flowVars.basic_credentials.getBytes())]"/>
           </http:request-builder>
        </http:request>
         <logger message="Success !!" level="INFO" doc:name="Logger"/>
     </flow>

在这里您可以看到我使用了另一个流变量 basic_credentials,它结合了两个变量 #[flowVars.urlHostUser+':'+flowVars.urlHostPassword] :-

<set-variable variableName="basic_credentials" value="#[flowVars.urlHostUser+':'+flowVars.urlHostPassword]" doc:name="Variable"/>

最后在 HTTP 请求配置中将其传递为:-

 <http:request-builder>
        <http:header headerName="Authorization" value="#['Basic ' + org.apache.commons.codec.binary.Base64.encodeBase64String(flowVars.basic_credentials.getBytes())]"/>
   </http:request-builder>

参考:- https://forums.mulesoft.com/questions/34854/dynamically-set-username-and-password-http-request.html

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 2015-03-06
    • 2014-09-15
    • 2013-01-02
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    相关资源
    最近更新 更多