Mule中DataWeave的资源属性不接受流变量

时间:2016-01-06 07:54:13

标签: mule classpath esb dataweave

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

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

2 个答案:

答案 0 :(得分:0)

您不能这样做,但您可以使用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

答案 1 :(得分:0)

我在使用Mule 3.9.0的Anypoint Studio中也遇到了相同的问题 我必须使用以下指南在我的Anypoint Studio中更正Java库。

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

这应该可以解决您的问题