如何使用curl从命令行界面(CLI)调用Mule的文件入站端点?

时间:2013-01-24 05:25:37

标签: curl mule mule-studio

我正在尝试使用以下流程将多个文件从源移动/上传到目标(可以是任何内容,例如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(命令行界面)调用作业。

但我收到以下错误

错误:

  

线程中的异常&#34; main&#34;   org.mule.module.launcher.DeploymentInitException:SAXParseException:   cvc-complex-type.2.4.b:元素流的内容&#39;不完整。   之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。在   org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:220)     在   org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64)     在   org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:46)     在   org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:56)     在   org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:88)   引起:org.mule.api.config.ConfigurationException:XML中的第11行   来自URL的文档   [文件:/ d:/MuleStudioExperiment/FileTransferUsingHTTP/.mule/apps/test/test.xml]   是无效的;嵌套异常是org.xml.sax.SAXParseException;   lineNumber:11; columnNumber:8; cvc-complex-type.2.4.b:内容   元素的流动&#39;不完整。之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。   (org.mule.api.lifecycle.InitialisationException)   (org.mule.api.config.ConfigurationException)at   org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52)     在   org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)     在   org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:80)     在   org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:208)     ... 4更多引起:org.mule.api.config.ConfigurationException:   来自URL的XML文档中的第11行   [文件:/ d:/MuleStudioExperiment/FileTransferUsingHTTP/.mule/apps/test/test.xml]   是无效的;嵌套异常是org.xml.sax.SAXParseException;   lineNumber:11; columnNumber:8; cvc-complex-type.2.4.b:内容   元素的流动&#39;不完整。之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。   (org.mule.api.lifecycle.InitialisationException)at   org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52)     在   org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)     在   org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101)     在   org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57)     在   org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)     ... 7更多引起:org.mule.api.lifecycle.InitialisationException:   来自URL的XML文档中的第11行   [文件:/ d:/MuleStudioExperiment/FileTransferUsingHTTP/.mule/apps/test/test.xml]   是无效的;嵌套异常是org.xml.sax.SAXParseException;   lineNumber:11; columnNumber:8; cvc-complex-type.2.4.b:内容   元素的流动&#39;不完整。之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。在   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)     在   org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)     ... 11更多引起:   org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:   来自URL的XML文档中的第11行   [文件:/ d:/MuleStudioExperiment/FileTransferUsingHTTP/.mule/apps/test/test.xml]   是无效的;嵌套异常是org.xml.sax.SAXParseException;   lineNumber:11; columnNumber:8; cvc-complex-type.2.4.b:内容   元素的流动&#39;不完整。之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)     在   org.mule.config.spring.MuleApplicationContext.loadBeanDefinitions(MuleApplicationContext.java:112)     在   org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)     在   org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)     在   org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89)     在   org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109)     ... 14更多引起:org.xml.sax.SAXParseException; lineNumber:11;   columnNumber:8; cvc-complex-type.2.4.b:元素流的内容&#39;   不完整。之一   &#39; {&#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象出站端点   &#34; http://www.mulesoft.org/schema/mule/core&#34;:抽象混合内容消息处理器,   &#34; http://www.mulesoft.org/schema/mule/core&#34;:响应}&#39;是期待。在   org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(未知   来自org.apache.xerces.util.ErrorHandlerWrapper.error(未知   来源)at   org.apache.xerces.impl.XMLErrorReporter.reportError(未知来源)     在org.apache.xerces.impl.XMLErrorReporter.reportError(未知   来源)at   org.apache.xerces.impl.XMLErrorReporter.reportError(未知来源)     在   org.apache.xerces.impl.xs.XMLSchemaValidator $ XSIErrorReporter.reportError(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidType(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.processElementContent(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(未知   来源)at   org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(未知   来源)at   org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(未知   来源)at   org.apache.xerces.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDispatcher.dispatch(未知   来源)at   org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(未知   来自org.apache.xerces.parsers.XML11Configuration.parse(未知   来自org.apache.xerces.parsers.XML11Configuration.parse(未知   来源)org.apache.xerces.parsers.XMLParser.parse(未知来源)     在org.apache.xerces.parsers.DOMParser.parse(未知来源)at   org.apache.xerces.jaxp.DocumentBuilderImpl.parse(未知来源)at   org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)

请帮忙

2 个答案:

答案 0 :(得分:2)

试试这个

<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>

答案 1 :(得分:1)

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

因此,您实施的方法不适合您的使用案例。如果您需要按需加载文件(即当您点击http端点时),您应该重构您的流并使用mule-module-file-utils。此模块需要作为maven依赖项添加或安装在Studio中。您可以通过克隆git repo来执行此操作,然后您可以在these instructions

之后安装生成的更新站点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的文档可用here