如何从wso2代理服务调用python脚本文件

Vik*_*ran 1 wso2 wso2esb wso2-enterprise-integrator

如何从wso2代理服务调用python脚本文件。

我们尝试使用send mediator调用位于我本地计算机上的python脚本文件。

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="FilepythonTest"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target >
      <inSequence>
         <send>
            <endpoint>
               <address uri="local:///Users/vikashsaharan/Desktop/python/testpy.py"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full"/>
      </outSequence>
   </target>
</proxy>
Run Code Online (Sandbox Code Playgroud)

我们无法通过此电话致电。请指导我如何从wso2调用python脚本

小智 6

WSO2 EI具有使用脚本介体执行python脚本的内置功能。以下是一个示例配置。

**sample api configuration** 

<api xmlns="http://ws.apache.org/ns/synapse" name="api" context="/api-context">
   <resource methods="POST GET">
      <inSequence>
         <log level="full">
            <property name="Message" value="Before transformation"/>
         </log>
         <script language="py" key="conf:/repository/script/stockquoteTransformResponse.py" function="transformRequest"/>
         <log level="full">
            <property name="Message" value="After transformation"/>
         </log>
         <respond/>
      </inSequence>
   </resource>
</api>
Run Code Online (Sandbox Code Playgroud)

**stockquoteTransformResponse.py file saved in carbon registry.**

from org.apache.synapse.util.xpath import SynapseXPath

def transformRequest(mc):
    symbolXPath = SynapseXPath("//*[local-name()='Code']/text()")
    symbol = symbolXPath.stringValueOf(mc)
    mc.setPayloadXML('''
	<m:getQuote xmlns:m="http://services.samples">
		<m:request>
			<m:symbol>''' + symbol + '''</m:symbol>
		</m:request>
	</m:getQuote>''')
Run Code Online (Sandbox Code Playgroud)

我们需要将jython jar添加到WSO2EI_HOME / lib目录。使用http://central.maven.org/maven2/org/python/jython/2.2.1/jython-2.2.1.jar的 jython-2.2.1.jar进行了测试

一旦调用上述api,就可以看到以下输出。 在此处输入图片说明