如何在http:outbound-endpoint mule中传递用户名和密码等标头值

时间:2015-04-07 11:39:26

标签: mule

<message-properties-transformer scope="outbound"> 
    <add-message-property key="username" value="admin" /> 
    <add-message-property key="password" value="admin"/>
    <add-message-property key="Accept" value="application/json"/>
</message-properties-transformer>
<logger  message=" outbound header username and password... 
    #[message.outboundProperties['username']] and      
    #[message.outboundProperties['password']]"
 level="INFO" doc:name="Logger"/> 

 <http:outbound-endpoint 
       exchange-pattern="request-response"  
       address="http://localhost:8080/callReservation" 
       method="POST" 
       contentType="application/json" 
       doc:name="HTTP"/>

这里我无法将标头值传递给http outbound endpoint.any建议

<http:outbound-endpoint exchange-pattern="request-response"  address="http://localhost:8080/callreservation" method="POST" contentType="application/json" doc:name="HTTP">

对于此出站端点,我尝试将用户名,密码设置为标题

如下

 <message-properties-transformer scope="outbound"> 
<add-message-property key="'http.headers'.username" value="admin"/> 
<add-message-property key="'http.headers'password" value="admin"/> 
</message-properties-transformer> 



<set-property propertyName="username" value="admin"/>
<set-property propertyName="password" value="isgn@123"/>
<set-property propertyName="Accept" value="application/json"/>

但没有接受作为出站端点的标头。我正在使用mule 3.6.0

任何建议

2 个答案:

答案 0 :(得分:2)

由于您使用的是Mule 3.6.0,我建议您使用HTTP Request element,因为您使用的HTTP传输已被弃用。使用此连接器添加显式标头是easy。这是一个例子:

<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8080" doc:name="HTTP Request Configuration"/>
<flow>
...
    <http:request config-ref="HTTP_Request_Configuration" path="callReservation" method="POST" doc:name="HTTP">
        <http:request-builder>
            <http:header headerName="Content-Type" value="application/json"/>
            <http:header headerName="username" value="admin"/>
            <http:header headerName="password" value="admin"/>
        </http:request-builder>
    </http:request>
...
</flow>

如果您想坚持使用HTTP传输,则需要使用Properties Transformer。在这种情况下:

<set-property propertyName="username" value="admin"/>
<http:outbound-endpoint .../>

答案 1 :(得分:0)

您可以按如下方式传递用户名和密码: -

<http:outbound-endpoint exchange-pattern="request-response"  user="admin" password="admin" host="localhost" port="8080" path="callReservation" method="POST" contentType="application/json" doc:name="HTTP"/>