Mule ESB从URL字符串下载文件 [英] Mule ESB download file from URL string

查看:61
本文介绍了Mule ESB从URL字符串下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用Mule ESB在Bing中搜索某些PDF文件.然后,我解析JSON响应以捕获文件位置的URL.现在,我需要检索文件并将其保存在本地.以下是到目前为止的内容,但是我有种种感觉,那就是我全都错了.如何完成用例?

So, using Mule ESB, I'm searching Bing for certain PDF files. Then I'm parsing the JSON response to capture the URL of the file location. Now I need to retrieve the file and save locally. Below is what I have so far, but I have a feeling I'm going about this all wrong. How can I complete the use case?

我遇到两个问题:

1)无法弄清楚如何从#[message.payload.Url]中剥离"http"(因为HTTP端点将http添加到了我要传递的url中.

1) Can't figure out how to strip "http" from #[message.payload.Url] (since the HTTP Endpoint adds http to the url I'm passing in.

2)无法弄清楚如何检索文件.我什至不知道HTTP Endpoint是否是正确的选择. HTTP?文件?

2) Can't figure out how to retrieve the file. I don't even know if HTTP Endpoint is the right option. HTTP? File?

<?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&amp;WebFileType=%27PDF%27&amp;$top=50&amp;$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>

推荐答案

我无法测试流程,因为需要一些凭据,但以下内容可以为您提供帮助:

I couldn't test the flow because some credentials are needed but the following should help you:

  • 使用expression-transformer剥离HTTP,
  • 您使用http:outbound-endpoint后跟file:outbound-endpoint的方法会很好地工作,
  • http:inbound-endpoint更改为one-way:由于执行流被分割,因此无法返回任何有意义的内容.
  • Use an expression-transformer to strip the HTTP out,
  • Your approach with an http:outbound-endpoint followed by a file:outbound-endpoint will work fine,
  • Change the http:inbound-endpoint to one-way: there is no way to return anything sensible since the execution flow gets split.

例如,假设message.payload.Url解析为java.lang.String,则可以使用:

For example, assuming message.payload.Url resolves to a java.lang.String, you can use:

<expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/>

这篇关于Mule ESB从URL字符串下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆