使用 HTTP 端点下载 Mule 文件

2023-11-29

我负责在流程结束时下载文件的 HTTP 端点出现错误。它不断尝试与http://:80/而不是传入的 URL。我在这里做错了什么?

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd ">
    <flow name="BingFlow1" doc:name="BingFlow1">
        <http:inbound-endpoint exchange-pattern="one-way" 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"/>
        <expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/>
        <logger message="Payload is: #[message.payload]" level="INFO" doc:name="Logger"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="#[org.mule.util.StringUtils.substringBefore(message.payload, '/')]" port="80" method="GET" doc:name="HTTP" contentType="application/pdf" mimeType="application/pdf" path="#[org.mule.util.StringUtils.substringAfter(message.payload, '/')]"/>
        <file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[org.mule.util.StringUtils.replace(message.payload, '/','.')]" path="/home/user/Documents/output" mimeType="application/pdf"/>
    </flow>
</mule>

当更改为匹配第一个答案时,我收到此异常:

********************************************************************************
Message               : Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHas
hMap
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHashMap (org.mule.transp
ort.http.components.RestServiceException)
  org.mule.transport.http.components.RestServiceWrapper:219 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/http/components/RestServiceException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.http.components.RestServiceException: Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Mess
age payload is of type: LinkedHashMap
    at org.mule.transport.http.components.RestServiceWrapper.doInvoke(RestServiceWrapper.java:219)
    at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:126)
    at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:61)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

- - 解决了 - -

非常感谢大卫。这是我的最终解决方案:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.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 ">

    <configuration doc:name="Configuration">
        <expression-language>
            <import class="org.mule.util.StringUtils" />
        </expression-language>
    </configuration>
    <flow name="BingQuery" doc:name="BingQuery">
        <http:inbound-endpoint exchange-pattern="one-way"
            host="localhost" port="8082" 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=%27california%20school%20district%20contract%27&amp;WebFileType=%27PDF%27&amp;$top=10&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" />
        <vm:outbound-endpoint exchange-pattern="one-way"
            doc:name="VM" path="fileWriter" />
    </flow>
    <flow name="RestProcessor" doc:name="RestProcessor">
        <vm:inbound-endpoint exchange-pattern="one-way"
            doc:name="VM" path="fileWriter" />
        <set-variable variableName="fileName" value="#[message.payload.ID].pdf"
            doc:name="Variable" />
        <http:rest-service-component
            serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&amp;':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]"
            httpMethod="GET">
            <http:error-filter>
                <expression-filter
                    expression="#[Integer.valueOf(message.inboundProperties['http.status']) &gt;= 400]"></expression-filter>
            </http:error-filter>
        </http:rest-service-component>
        <file:outbound-endpoint responseTimeout="10000"
            doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/ken/Documents/output"
            mimeType="application/pdf" />
    </flow>
</mule>

我无法发现错误:您的流程看起来不错(除了我将在下面详细说明的问题),因此,可以选择使用http:outbound-endpoint,有时可能很挑剔,您可以使用http:rest-service-component.

您的下一个问题将是outputPattern文件端点的:记住这一点message.payload将是来自 HTTP 端点的响应,不再是(部分)URL。您需要预先计算文件名并将其存储在流变量中,然后使用它。

这将给出:

<configuration>
  <expression-language>
    <import class="org.mule.util.StringUtils" />
  </expression-language>
</configuration>

<flow name="BingFlow1" doc:name="BingFlow1">
    <http:inbound-endpoint exchange-pattern="one-way" 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"/>
    <set-variable variableName="fileName" value="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://').replace('/','.')]" />
    <http:rest-service-component serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&amp;':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]" httpMethod="GET">
        <http:error-filter>
            <expression-filter expression="#[Integer.valueOf(message.inboundProperties['http.status']) &gt;= 400]" />
        </http:error-filter>
    </http:rest-service-component>
    <file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/user/Documents/output" mimeType="application/pdf"/>
</flow>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 HTTP 端点下载 Mule 文件 的相关文章

  • 使用 Redis 的 Mule 缓存策略

    我正在寻找一种在两台服务器之间共享缓存的方法 并且正在研究使用 Redis 作为对象存储缓存策略 但在读取存储值时遇到问题 当缓存命中为未命中值时 它会成功存储值 但在检索该值时会抛出错误 所需的对象 属性 muleContext 为 nu
  • 使用 Mule 发送格式化邮件

    我正在使用 Mule 发送电子邮件 我需要为发送的文本添加格式 邮件的内容是有效负载 其中包含我在 Java 方法中形成的字符串 并使用表达式转换器发送到流程 我需要向该字符串添加格式 粗体 下划线 颜色 我该怎么做 这是我的流程的摘录
  • Mule 中是否有break语句

    我有一个array list我循环使用的值
  • 无法在 mule 中创建动态文件入站端点

    我得到一个文件路径作为 xml 内 mule 的输入 使用 XPATH 表达式 我能够提取路径 我想从该路径读取特定文件 我尝试如下定义文件入站端点 但它似乎不起作用
  • 如何在Mule中读取巨大的CSV文件

    我正在使用 Mule Studio 3 4 0 社区版 我有一个关于如何解析通过文件端点传入的大型 CSV 文件的大问题 场景是我有 3 个 CSV 文件 我会将文件的内容放入数据库中 但是当我尝试加载一个大文件 大约 144MB 时 我收
  • 如何使用 MUnit 在 Mule Flow 中模拟 Java 组件

    我正在尝试使用 MUnit 对我的一个子流程进行单元测试 我需要模拟一个自定义 Java 组件 但我无法这样做 我的子流程如下
  • ESB 中有效负载的验证

    我有一个 HTTP POST REQUEST 它发送如下有效负载 键1 值1 键2 值2 键3 值3 我能够验证所有值 但每次都必须使用一个组件 在本例中 我使用了验证器 非空字符串 3 次 1 Is there any way that
  • 如何在 Mule 中添加一次全局异常处理程序/记录器

    我们想要向 mule 添加几行 XML 配置 并使用一个异常处理程序来记录到 SLF4J 而不是现在记录的位置 stdout 我们如何添加这个 我们不想将此处理程序添加到每个流 50 多个流 加上人们添加流时 他们可能会忘记添加我们的异常处
  • Mule CXF 马歇尔响应

    我在 Mule 3 中使用 cxf jaxws client 并且从 Web 服务调用中获得的响应属于 ReleasingInputStream 类型 我尝试添加 http response to message transformer 但
  • 为什么 Mule 例外策略这么啰嗦?

    在我的 Mule 应用程序中 我已将一些流程配置为使用捕获异常策略来执行一些特殊处理 对于这些情况 我想将错误和原始有效负载弹出到对象存储中 在其他地方 默认的异常策略就很好
  • 如何在骡子中手动抛出肥皂故障

    我面临着一种情况 我们无法使用模式来验证传入的请求 基本上模式就在那里 但它接受请求中的任何字符串 wsdl 设计者有自己的理由这样做 以接受来自不同来源和灵活性的请求 但是 当收到请求时 我会验证请求包装器的子元素是否是我们所期望的 为此
  • Anypoint studio/Mule 在启动期间挂起

    我是 Mule 和 Anypoint 工作室的新手 我以前和Mule一起工作过 过了一会儿 我又回来处理它了 我升级到 Anypoint Studio March 2015 Release Version 5 1 0 Build Id 20
  • 如何在Mule中通过HTTP请求发送文件并通过FTP上传到文件服务器

    我想在 HTTP POST 请求中发送一个文件 然后让 Mule 使用 FTP 将文件上传到服务器上的文件目录 看起来 FTP 连接器将有效负载保存到文件目录 但这实际上是空的 并且 FTP 将一个空文件写入该目录 我已经使用 Postma
  • 读取通配符文件名的 Quartz 作业仅获取一个文件

    使用骡子 3 7 如果我的目录中有 5 个扩展名为 csv 的文件 则以下代码仅选取这五个文件之一 如果我删除石英触发器并将其设为普通文件 inbound endpoint 它将拾取所有五个文件 看起来很简单 但并没有按预期工作 Thank
  • NoClassDefFoundError: javax/validation/Validation 即使在 POM 中的validation-api 1.1.0.Final 也会发生

    看起来很奇怪 我有异常跟踪 org apache cxf interceptor Fault at org mule module cxf MuleInvoker invoke MuleInvoker java 117 at org mul
  • 在 Mule 中测试子流程

    我已经开始为我的 Mule 项目编写测试用例 我为我的主流程编写了功能测试用例 如下所示 public void testMainFlow 1 throws Exception MuleClient client muleContext g
  • 如何拆分 XML

    我的第一篇文章在这里 我已经搜索过 但没有找到我要找的东西 我不太确定需要什么技术来完成以下操作 我使用 Mule 3 3 CE 我需要拆分 XML 文件 我需要在每个分割的 XML 中保留 rootElement 及其属性 所有 XML
  • Mule 处理策略 - 从同步流调用异步私有流

    我试图从主同步流中调用异步私有流 如下所示
  • 如何在 Mulesoft 中将睡眠设置为流程而不丢失消息负载

    我想插入脚本来延迟 Mulesoft 中的处理流程 我尝试在 groovy 中插入脚本 但丢失了消息有效负载 因此当我必须获取消息有效负载时 收到了空指针 我怎样才能不丢失消息有效负载 Thanks 如果您正在使用Groovy流程中的组件
  • 如何让 Mule 从 JDBC 查询中作为单个事务返回多行?

    如果 Oracle 表中有 100 行 我希望收到一封正文有 100 行的电子邮件 但我收到了 100 封电子邮件 每行一封 我认为 transactionPerMessage 会做到这一点 工具提示说 如果false 整个结果集将有一个事

随机推荐

  • 无法从另一个类python访问变量

    这是我的代码 应该从 设置 类中打印 self cake 和 self age from startup import Settings class Profile Settings def init self super Profile
  • 警告:赋值使指针来自整数而不进行强制转换

    这是一个很常见的问题 但我还没有得到答案 所以再次询问 我将结构体定义为 struct f lock int x struct f lock next 然后说我有一个功能 struct f lock new node struct f lo
  • docker-compose 中“无法连接到本地 MySQL 服务器”

    我有带有 MySQL 的 Laravel 应用程序 我正在尝试使用 docker compose 在 Docker 中运行它 但是当应用程序尝试连接数据库时 它会抛出 Connector php 第 55 行中的 PDOException
  • 使用 mod_rewrite 重定向和重写

    问完这个问题后 用于搜索查询的干净 URL 我尝试使用 mod rewrite 进行一些操作 RewriteCond QUERY STRING s a z NC RewriteRule s 1 NC R 301 L RewriteRule
  • 使用滑块更新散景图

    我正在尝试使用滑块来更新我的散景图 我发现使用 pandas dataframe 很难实现它 到目前为止没有找到任何例子 另一种方法是使用 columndatasource 在论坛上找到了一些示例 但仍然无法实现该功能 所以我有两列 X 轴
  • 如何正确等待 execve 完成?

    C 源代码 在 Linux Centos 6 3 上编译并运行 包含以下行 execve cmd argv envp execve不返回 但我想修改代码以知道它何时完成 所以我这样做 if child fork waitpid child
  • 使用 pybind11 嵌入 python。虚拟环境不起作用

    我正在尝试制作一个简单的 C 应用程序 它使用以下命令翻译短语googletranspython 库 所以我选择了pybind11为此目的嵌入Python 我还使用 cmake 进行代码配置 当我使用全局 python 安装时 一切正常 但
  • 使用 eigen3/sparse 的稀疏特征值

    是否有一种独特且有效的方法来查找实数 对称 非常大 比如说 10000x10000 的稀疏矩阵的特征值和特征向量Eigen3 有一个用于稠密矩阵的特征值求解器 但它没有利用矩阵的属性 例如这是对称性 此外 我不想将矩阵存储为密集的 或者 替
  • 用 C++ 制作简单的跨平台 GUI 的最佳方法是什么? [关闭]

    Closed 这个问题需要多问focused 目前不接受答案 我想制作一个带有非常简单的 GUI 背景图形 取消按钮和进度条 的桌面应用程序 我的主要目标是 Mac 和 Windows 使用 Visual C 2008 可以吗 任何人都可以
  • 使用 CasperJS 实现页面对象模式

    有没有人已经用 casperjs 实现了著名的 页面对象模式 从长远来看 它对于测试可维护性非常有用 当您必须将测试的机制和目的分开时 使用它非常非常酷 以这种方式编写测试会变得更加愉快 有一些 ruby 和 selenium 的例子 ht
  • 列表理解/生成器中的海象赋值表达式

    我试图传递每个元素foo list变成一个函数expensive call 并获取其输出为的所有项目的列表expensive call是诚实的 我正在尝试用列表理解来做到这一点 这可能吗 就像是 像这样的事情 result list y e
  • 无法在套接字上使用 BufferedReader/Writer 发送和接收数据

    我正在制作一个客户端 服务器应用程序 并使用以下代码在服务器和客户端之间交换数据 服务器的发送和接收代码 public void run try BufferedReader input new BufferedReader new Inp
  • 具有特定值的行名和列名

    我有这个矩阵 我想得到一个 2 列矩阵 其中一列有行名 另一列有值为 1 的单元格的列名 x X1 X2 X3 X1 1 0 1 X2 0 1 0 X3 0 1 1 X4 1 0 0 str x num 1 886 1 886 1 0 1
  • 从“package::function”形式的字符串中获取函数

    有过讨论关于如何从字符串中获取变量 的确 get例如 适用于data table功能 get data table 回报data table 然而 gt get data table data table Error in get data
  • 带有 mongodb 的 yii2 无法登录或注册

    我们按照此 youtube 链接创建 yii2 mongodb 连接 但不起作用 检查此链接 https www youtube com watch v 1msu95ZkRe8 给出一个错误对象配置必须是包含 class 元素的数组 在视频
  • 将 varchar() 中的重音字符转换为 XML 导致“非法 XML 字符”

    我有一个应用程序写入的表 该字段为 varchar max 数据看起来像 xml DECLARE poit VARCHAR 100 SET poit
  • 如何在 Gtk 2 窗口上创建 cairo_t

    我有一个旧的应用程序 现在在 Gtk 2 上编译 但我需要介绍一下 Cairo 的使用 我不知道如何从我的小部件创建必要的 cairo 上下文 cairo t 这是我到目前为止正在尝试学习的代码 是从 Gtk 3 教程中修改的 咳咳 抄袭
  • 滚动到视图与移动到元素

    在 Selenium WebDriver 中 有两种主要方法将一个元素放入可见区域 滚动到视图中 JavascriptExecutor driver executeScript arguments 0 scrollIntoView true
  • Java中前后缀“++”运算符的语义[重复]

    这个问题在这里已经有答案了 我想知道为什么这段代码给出输出112最后一个数字如何2正在创造 public static void main String args int i 0 System out print i System out
  • 使用 HTTP 端点下载 Mule 文件

    我负责在流程结束时下载文件的 HTTP 端点出现错误 它不断尝试与http 80 而不是传入的 URL 我在这里做错了什么