一个简单的方法是将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 –