Mule ESB从URL字符串下载文件
因此,使用Mule ESB,我正在Bing中搜索某些PDF文件。然后我解析JSON响应以捕获文件位置的URL。现在,我需要检索文件并在本地保存。以下是我到目前为止的情况,但我感觉我在这件事上完全错了。如何完成用例 我有两个问题: 1) 无法理解如何从#[message.payload.Url]中删除“http”(因为http端点将http添加到我传递的Url中) 2) 无法确定如何检索该文件。我甚至不知道HTTP端点是否是正确的选择。HTTP?档案Mule ESB从URL字符串下载文件,esb,mule,Esb,Mule,因此,使用Mule ESB,我正在Bing中搜索某些PDF文件。然后我解析JSON响应以捕获文件位置的URL。现在,我需要检索文件并在本地保存。以下是我到目前为止的情况,但我感觉我在这件事上完全错了。如何完成用例 我有两个问题: 1) 无法理解如何从#[message.payload.Url]中删除“http”(因为http端点将http添加到我传递的Url中) 2) 无法确定如何检索该文件。我甚至不知道HTTP端点是否是正确的选择。HTTP?档案 <?xml version="1.0"
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<flow name="BingFlow1" doc:name="BingFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&WebFileType=%27PDF%27&$top=50&$format=Json" user="********" password="*****" doc:name="Bing"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
<collection-splitter doc:name="Collection Splitter"/>
<http:outbound-endpoint exchange-pattern="request-response" host="#[message.payload.Url]" port="80" method="GET" doc:name="HTTP"/>
<file:outbound-endpoint path="/home/user/Documents/output" outputPattern="#[message.payload.ID].pdf" responseTimeout="10000" doc:name="File"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
我无法测试流,因为需要一些凭据,但以下内容应该可以帮助您:
- 使用
剥离HTTP表达式转换器
- 您使用
和http:outbound端点
的方法可以很好地工作file:outbound端点
- 将
更改为http:inbound端点
:由于执行流被拆分,因此无法返回任何合理的内容单向
message.payload.Url
解析为java.lang.String
,则可以使用:
<expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/>
太棒了。我刚刚将入站端点更改为单向。我回到了rest客户端,但你是对的……我让它回显到控制台,因此没有真正的需要。你将如何编写表达式,我在集合拆分器之后添加了
,但我不确定如何从URL中删除http://。你能提供一个例子或者文档来说明如何做到这一点吗?我没有在Mule文档中看到它。没有专门的文档:这是MEL(内置),它允许您访问任何Java对象,包括在本例中的org.Mule.util.StringUtils
用于处理字符串。我相应地复习了我的答案。使用脚本组件来处理字符串怎么样?我只是不知道如何在不编写java类的情况下使用表达式转换器。根本不需要脚本组件来完成这项工作。通过使用java.lang.String
的substring
和indexOf
方法,可以使用表达式转换器而不使用helper类(但为什么?)。