一個簡單的方法是將url拆分成多個部分並設置它變成流量變量。然後你可以在任何你想要的地方使用這個流變量。
一個簡單的例子來做到這一點是如下: -
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="csv-to-smtpFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/aa" doc:name="HTTP"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="http://example.com:80/a/specific/path" doc:name="Set Payload"/>
<set-variable variableName="url" value="#[new URL(payload);]" doc:name="Variable"/>
<set-variable variableName="protocol" value="#[url.getProtocol();]" doc:name="Variable"/>
<set-variable variableName="host" value="#[url.getHost();]" doc:name="Variable"/>
<set-variable variableName="port" value="#[url.getPort();]" doc:name="Variable"/>
<set-variable variableName="path" value="#[url.getPath();]" doc:name="Variable"/>
<logger message="Done" level="INFO"/>
</flow>
在這裏你可以看到我設置的URL http://example.com:80/a/specific/path的有效載荷,然後將其拆分成主機,端口,路徑等並將其存儲在變量。
請注意如果您的網址形式http://example.com:80/a/specific/path,你會使用表達式#[url.getProtocol();]
得到端口,但如果你的網址形式http://example.com/a/specific/path,你不會得到的端口號。
參考: - https://docs.oracle.com/javase/tutorial/networking/urls/urlInfo.html
我在騾子JIRA創建的票這樣的:https://www.mulesoft.org/jira/browse/MULE-10741 –