Mule: Access file resource from Python script component in CloudHub

时间:2015-10-29 15:42:29

标签: mule cloudhub anypoint-studio

In a mule project, I have a Python script component that needs to access a cert.pem file.

In AnyPointStudio I've placed it in the ./src/main/resources/ folder. When I create a Mule Deployable Archive, it ends up in the ./target/classes/ folder.

What path should I specify to access this file.

I've tried

path = 'cert.pem'

## And ## 

cwd = os.getcwd()
path = os.path.join(cwd, 'classes','cert.pem')
path = os.path.join(cwd, 'target','classes','cert.pem')
path = os.path.join(cwd, 'src','main', 'resources','cert.pem')

None of which work.
Any advice?

Side Question: In CloudHub simple print() statements in the .py script don't log, I tried log("message") but that raised an exception. Any ideas?

2 个答案:

答案 0 :(得分:0)

我不知道python,但该文件应该只在类路径上可用。因此,src / main / resources中的所有内容都将在类路径中可用。因此'src / main / resources / cert.pem'应该被引用为'cert.pem'

答案 1 :(得分:0)

所以,至少在Python中,类路径与工作目录路径不同。但我最终弄清楚如何使用MULE_HOME env变量进入类路径。

base = os.path.join(os.getenv('MULE_HOME'), 'apps', 'your-app-name', 'classes')

然后你可以得到这样的证书文件:

certfile = os.path.join(base, 'cert.pem')