【问题标题】:Unable to post a file to http endpoint inside a choice in mule无法将文件发布到骡子选项内的 http 端点
【发布时间】:2015-05-04 09:34:22
【问题描述】:

这是我的 mule 应用程序 xml 配置

 <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" 
 xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:test="http://www.mulesoft.org/schema/mule/test"   
xmlns:file="http://www.mulesoft.org/schema/mule/file"    
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/3.6/mule-test.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.6/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.6/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.6/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.6/mule-file.xsd">

<object-to-string-transformer name="httptoobj" />
<file:connector name="input"/>
<http:http-response-to-object-transformer
    name="httptostring" />
<configuration>
    <expression-language autoResolveVariables="false">
        <import class="com.xyz.alertcampaign.appworkflow.CampaignStatus" />
    </expression-language>
</configuration>
<flow name="polling" doc:name="polling" processingStrategy="synchronous">
    <quartz:inbound-endpoint repeatInterval="3000"
        startDelay="3000" jobName="couchbasePoller" doc:name="Quartz">
        <quartz:event-generator-job stateful="true" />
    </quartz:inbound-endpoint>
    <component doc:name="Java">
        <singleton-object
            class="com.xyz.alertcampaign.appworkflow.CouchbasePoller" />
    </component>

    <vm:outbound-endpoint exchange-pattern="one-way"
        path="oozieQueue" doc:name="Trigger workflow" />

</flow>
<flow name="oozie-workflow-manager" doc:name="oozie-workflow-manager">
    <vm:inbound-endpoint exchange-pattern="one-way"
        path="oozieQueue" doc:name="VM" />

    <foreach collection="#[payload.items()]" counterVariableName="counter">
        <choice doc:name="Choice">
            <when expression="#[payload.status == CampaignStatus.NOT_STARTED]">
                <file:inbound-endpoint address="file://#[payload.fileName]" connector-ref="input"/>             
                <http:outbound-endpoint exchange-pattern="request-response"
                    address="http://localhost:8080/oozie/v1/jobs"
                    responseTransformer-refs="httptoobj" method="POST" doc:name="HTTP"
                    contentType="application/xml;charset=UTF-8" />
                <choice doc:name="Choice">
                    <when expression="#[message.inboundProperties['http.status'] == 201]">
                        <component doc:name="Java">
                            <singleton-object
                                class="com.xyz.alertcampaign.appworkflow.JobUpdater" />
                        </component>
                    </when>
                    <otherwise>
                        <logger level="ERROR" message="Error occurred on creating Job in OOzie " />
                    </otherwise>
                </choice>
            </when>
            <when
                expression="#[payload.status == CampaignStatus.UPDATED || payload.status == CampaignStatus.EXPIRED]">
                <logger level="ERROR" message="#[payload.status]" />
                <http:outbound-endpoint exchange-pattern="request-response"
                    method="PUT"
                    address="http://localhost:8080/oozie/v1/job/#[payload.jobId]?action=kill"
                    responseTransformer-refs="httptoobj" doc:name="HTTP" />
                <choice doc:name="Choice">
                    <when expression="#[message.inboundProperties['http.status'] == 200]">
                        <component doc:name="Java">
                            <singleton-object
                                class="com.xyz.alertcampaign.appworkflow.JobUpdater" />
                        </component>
                    </when>
                    <otherwise>
                        <logger level="ERROR" message="Error occurred on killing Job in OOzie " />
                    </otherwise>
                </choice>
            </when>
        </choice>
    </foreach>
</flow>

</mule> 

获取以下异常(堆栈):

加载 mule' xml 时出现异常: 原因:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:发现以元素“文件:入站端点”开头的无效内容。 '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' 之一是预期的。

为什么我不允许在选择路由器内将文件发布到 http?

【问题讨论】:

    标签: mule mule-component


    【解决方案1】:

    您只能在流的开头使用file:inbound-endpoint。如果您尝试在流程中检索文件,请考虑使用Mule Requestor 模块。这允许您在流程中的任何点请求资源(即文件)。

    【讨论】:

      【解决方案2】:

      问题在于它是一个入站端点,因此您要在流中间添加一个消息源。您应该做的是定义另一个以该文件入站端点(具有所有逻辑)开始的流,并在对其的选择中使用流引用元素。 更多详情请查看doc

      【讨论】:

      • 我现在试过了。但我收到以下错误。 org.mule.module.launcher.DeploymentInitException: MalformedEndpointException: 端点“file://#[payload.fileName]”格式错误,无法解析。如果这是全局端点的名称,请检查名称是否正确、端点是否存在以及您使用的配置是否正确(例如“ref”属性)。请注意,入站和出站端点上的名称不能用于发送或接收消息;改用命名的全局端点。只有出站端点可以是动态的
      • 是的,这是有道理的。我没有意识到你在哪里使用有效负载来动态获取文件名。
      【解决方案3】:

      另外我认为还有一个问题是入站端点不允许动态输入。我通过 MuleRequester 解决了它

      【讨论】:

      • 如果是这种情况,请您接受答案,以便问题得到解决。谢谢。
      • 为什么mule requester在读取数据后会删除文件。我该如何避免这种情况?
      • 您需要配置一个文件连接器,其中autoDelete 属性设置为“false”。您可以通过将资源配置为resource="file://path/to/file?fileConnector" 来让请求者使用它。如果您仍有问题,请提出新问题并在此处发布答案。
      猜你喜欢
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多