4

我正在尝试使用以下流程将多个文件从源移动/上传到目标(可以是任何东西,例如 FTP 或文件出站等)

<flow name="flow1" doc:name="f1">
            <file:inbound-endpoint path="C:\input" responseTimeout="10000" doc:name="File"/>
    </flow>

<flow name="flow2" doc:name="f2">
  <http:inbound-endpoint address="http://localhost:8080" doc:name="HTTP" exchange-pattern="request-response"/>

  <flow-ref name="flow1" doc:name="Flow Reference"/>
        <file:outbound-endpoint path="C:\outputfile" responseTimeout="10000" doc:name="File"/>

</flow>

这样做的原因是我想使用 CURL 从 CLI(命令行界面)调用作业。

但我收到以下错误

错误:

线程“主”org.mule.module.launcher.DeploymentInitException 中的异常:SAXParseException:cvc-complex-type.2.4.b:元素“流”的内容不完整。'{"之一http://www.mulesoft.org/schema/mule/core ":abstract-message-processor, " http://www.mulesoft.org/schema/mule/core ":abstract-outbound-端点,“ http://www.mulesoft.org/schema/mule/core ”:abstract-mixed-content-message-processor,“ http://www.mulesoft.org/schema/mule/core流'不完整。'{" 之一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://www.mulesoft.org/schema/mule/core列号:8;cvc-complex-type.2.4.b:元素“流”的内容不完整。'{" 之一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://www.mulesoft.org/schema/mule/core嵌套异常是 org.xml.sax.SAXParseException;行号:11;列号:8;cvc-complex-type.2.4.b:元素“流”的内容不完整。'{" 之一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://www.mulesoft.org/schema/mule/core":response}' 是预期的。在 org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:117) 在 org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:116) 在 org.mule.config .spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46) ... 11 更多原因:org.springframework.beans.factory.xml。 XmlBeanDefinitionStoreException:来自 URL [file:/D:/MuleStudioExperiment/FileTransferUsingHTTP/.mule/apps/test/test.xml] 的 XML 文档中的第 11 行无效;嵌套异常为 org.xml.sax.SAXParseException;lineNumber:11;columnNumber : 8; cvc-complex-type.2.4.b: 元素'flow'的内容不完整。'{" 之一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://www.mulesoft.org/schema/mule/coreAbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89) at org .mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 14 更多原因:org.xml.sax.SAXParseException; 行号:11;列号:8;cvc-complex-type.2.4.b:元素“流”的内容不完整。'{" 之一 mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 14 更多原因:org.xml.sax.SAXParseException; 行号:11;列号:8;cvc-complex-type.2.4.b:元素“流”的内容不完整。'{" 之一 mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 14 更多原因:org.xml.sax.SAXParseException; 行号:11;列号:8;cvc-complex-type.2.4.b:元素“流”的内容不完整。'{" 之一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://www.mulesoft.org/schema/mule/core":response}' 是预期的。在 org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter .reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator $XSIErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(Unknown Source) at org.apache.xerces org.apache.xerces.impl.xs 中的 .impl.xs.XMLSchemaValidator.elementLocallyValidType(未知来源)。XMLSchemaValidator.processElementContent(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source) at org.apache.xerces。 impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces。 org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.parsers.XML11Configuration.parse(Unknown Source)。 org.apache.xerces.jaxp.DocumentBuilderImpl 上的 DOMParser.parse(未知来源)。在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) 的 org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) 解析(未知来源)

请帮忙

4

2 回答 2

3

试试这个

<flow name="flow1" doc:name="flow1" initialState="stopped">
  <file:inbound-endpoint path="C:\Input" responseTimeout="10000" doc:name="File"/>

  <file:outbound-endpoint path="C:\outputfile" responseTimeout="10000" doc:name="File"/>
</flow>

<flow name="flow2" doc:name="flow2">
  <http:inbound-endpoint address="http://localhost:8080/start" doc:name="HTTP" exchange-pattern="request-response"/>

  <expression-component>
    app.registry.filePickupFlow.start();
  </expression-component>

  <set-payload value="File successfully copied" />

</flow>
于 2013-02-05T02:32:24.933 回答
1

文件端点是基于资源的端点(例如 ftp 和 sftp 端点),而不是基于事件的端点(即 jms 和 vm)或基于 tcp 的端点(即 tcp、http、udp 等)

因此,您正在实施的方法不适合您的用例。如果您需要按需加载文件(即当您点击 http 端点时),您应该重构您的流程并使用mule-module-file-utils。此模块需要作为 maven 依赖项添加或安装在 Studio 中。您可以通过克隆git repo来做到这一点,然后您可以按照这些说明安装生成的更新站点 zip 文件

完成后,您的流程将如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:fileutils="http://www.mulesoft.org/schema/mule/fileutils" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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="EE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/fileutils http://www.mulesoft.org/schema/mule/fileutils/3.3/mule-fileutils.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd ">
    <fileutils:config name="Fileutils" doc:name="Fileutils"/>
    <flow name="FileCopier" doc:name="FileCopier">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="copy-file" doc:name="HTTP"/>
        <scripting:transformer doc:name="Script">
            <scripting:script engine="Groovy">
                <scripting:text><![CDATA[def dir = new File("/" + message.getInboundProperty('http.relative.path'))
log.info(dir.getPath())
return Arrays.asList(dir.listFiles())]]></scripting:text>
            </scripting:script>
        </scripting:transformer>
        <logger level="INFO" doc:name="Logger"/>
        <set-variable variableName="fileNumber" value="#[payload.size()]" doc:name="Variable"/>
        <foreach doc:name="Foreach">
            <fileutils:copy-file config-ref="Fileutils" destinationName="#[message.payload.getName()]" destinationPath="/tmp/out/" fileName="#[message.payload.getName()]" filePath="#[message.payload.getParentFile().getPath()]" fileAge="0" doc:name="Fileutils"/>
        </foreach>
        <set-payload value="#[flowVars['fileNumber'] + ' file copied']" doc:name="Set Payload"/>
        <http:response-builder status="200" contentType="text/plain" doc:name="HTTP Response Builder"/>
        </flow>
      </mule>

如果您不想使用 fileutils 模块,可以将其替换为实现文件复制逻辑的脚本组件

现在可以使用以下 curl 命令调用此流程

curl http://${hostname}:8081/copy-file/${path_to_directory_to_copy}

有关 curl 的文档可在此处获得

于 2013-01-24T14:44:17.467 回答