【问题标题】:Resource attribute of DataWeave in Mule is not accepting flow variableMule中DataWeave的资源属性不接受流变量
【发布时间】:2019-10-10 16:56:43
【问题描述】:

我的dataweave代码配置xml如下:

<dw:transform-message doc:name="Transform Message">
    <dw:set-payload  resource="#[flowVars['sample']]" />
 </dw:transform-message>

其中 sample 是一个流变量,其中包含具有实际转换逻辑的 .dwl 文件的文件路径。

<set-variable doc:name="Variable" value="file:D:/Transformer/sample.dwl" variableName="sample"/>

我在部署应用程序时看到的错误如下:

org.mule.module.launcher.DeploymentInitException: FileNotFoundException: class path resource [#[flowVars['sample']]] cannot be opened because it does not exist
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:197) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.artifact.ArtifactWrapper$2.execute(ArtifactWrapper.java:62) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.artifact.ArtifactWrapper.executeWithinArtifactClassLoader(ArtifactWrapper.java:129) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.artifact.ArtifactWrapper.init(ArtifactWrapper.java:57) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:25) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArchiveDeployer.guardedDeploy(DefaultArchiveDeployer.java:324) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:345) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:163) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:268) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:83) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DeploymentDirectoryWatcher.deployPackedApps(DeploymentDirectoryWatcher.java:275) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.DeploymentDirectoryWatcher.start(DeploymentDirectoryWatcher.java:150) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:104) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:170) ~[mule-module-launcher-3.7.3.jar:3.7.3]
at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:15) ~[tooling-support-3.7.3.jar:?]
Caused by: org.mule.api.config.ConfigurationException: IOException parsing XML document from URL [file:/C:/Users/Satyakeerthika_Ch/AnypointStudio/workspaceLatest/.mule/apps/sample/sample.xml]; nested exception is java.io.FileNotFoundException: class path resource [#[flowVars['sample']]] cannot be opened because it does not exist (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:49) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:89) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:222) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81) ~[mule-core-3.7.3.jar:3.7.3]
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:188) ~[mule-module-launcher-3.7.3.jar:3.7.3]
... 14 more

有人可以帮我如何读取资源中的变量吗?

【问题讨论】:

    标签: mule classpath esb dataweave


    【解决方案1】:

    您不能那样做,但您可以使用 MEL 函数来评估 set-payload 内的 dataweave 脚本。

    #[dw(<dw-script-string>)]
    #[dw(<dw-script-string>, <out-content-type>)]
    

    如果您不指定内容类型,则默认为 java。

    所以,它最终会是:

    <set-payload value="#[dw(<dw-script-string>)]" doc:name="Set Payload"/>
    

    Link to docs

    【讨论】:

    • 感谢您的回复。我已尝试按照您的建议使用 dw() 函数。我使用的 set payload 中的值如下:#[dw( payload map { First : $."First Name", number : $.Age, Last :$."Last Name", Date : $.DOB} , application/csv)] 但它在尝试保存 xml 时抛出了一些错误。 [错误:未知类或非法语句:org.mule.mvel2.ParserContext@2689a2] [Near :{...dw(payload map {....}] ^ [Line1 Column16]
    • 它正在工作。我已将脚本制作为字符串。我不能在有效负载之前添加输入和输出指令吗?因为当我尝试添加它时会抛出错误。
    • 错误是:无效输入“0 %”,预期版本Minor,wsnoeol or eol
    【解决方案2】:

    我在使用 Mule 3.9.0 的 anypoint 工作室中也遇到了同样的问题 我必须使用以下指南来更正我的 anypoint 工作室中的 java 库。

    1. 右键单击项目
    2. 从上下文菜单中选择属性
    3. 在项目属性页面选择java构建路径
    4. 在 java 构建路径中点击库
    5. 选择添加库 -> 点击 JRE 系统库
    6. 选择备用 JRE 并浏览到要添加到项目中的 JDK

    这应该可以解决您的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2014-03-26
      • 1970-01-01
      • 2016-11-06
      相关资源
      最近更新 更多