无法 post 文件到 mule 中选择的 http 端点

Unable to post a file to http endpoint inside a choice in mule

这是我的 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: Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: 发现以元素 'file:inbound-endpoint' 开头的无效内容。需要“{"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} 之一。

为什么我不允许 post 一个文件到 http inside choice router?

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

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

此外,我认为还有一个问题是入站端点不允许动态输入。我通过 MuleRequester

解决了它