英文:
define endpoint in WSO2 Integration Studio
问题
我有一个执行3个来自Postgress的存储过程的流程,她的流程如下:
流程代码API定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/animalstore" name="AnimalStoreFlowServices" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<!-- 调用存储过程的逻辑 -->
<log description="Log Request Payload" level="full"/>
<switch description="Route based on the Operation" source="json-eval($.Operation)">
<case regex="datosCliente">
<dblookup>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/animalstore</url>
<user>postgres</user>
<password>passwd12</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM get_animals_data();]]></sql>
<result column="nombrecompleto" name="variable1"/>
<result column="cuenta_id" name="variable3"/>
<result column="domicilio" name="variable2"/>
</statement>
</dblookup>
<!-- 将捕获的值映射到属性列表中 -->
<property description="Set response properties" expression="$ctx:variable1" name="VariableList1" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable2" name="VariableList2" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable3" name="VariableList3" scope="default" type="STRING"/>
<!-- 使用捕获的值配置响应 -->
<payloadFactory description="Create response payload" media-type="xml">
<format>
<Response xmlns="">
<datosCliente>
<Nombre>$1</Nombre>
<Domicilio>$2</Domicilio>
<NúmeroCliente>$3</NúmeroCliente>
</datosCliente>
</Response>
</format>
<args>
<arg evaluator="xml" expression="$ctx:VariableList1"/>
<arg evaluator="xml" expression="$ctx:VariableList2"/>
<arg evaluator="xml" expression="$ctx:VariableList3"/>
</args>
</payloadFactory>
</case>
<!-- 其他存储过程的处理逻辑 -->
...
<default>
<payloadFactory description="Create response payload for unsupported operation" media-type="xml">
<format>
<Message xmlns="">Unsupported operation.</Message>
</format>
<args/>
</payloadFactory>
</default>
</switch>
<property description="Set message type" name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond description="Send result to the client"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
到目前为止,我使用POSTMAN获取存储过程的值,并且可以正确执行。
但我了解到,为了进行单元测试,我应该为每个存储过程定义一个端点,有人可以指导我如何定义一个端点吗?应该使用哪一个?来自Palette的端点还是Defined Endpoint?我需要两个示例来完全理解如何创建WSO2流程服务。
英文:
i have a flow which execute 3 stored procedures from Postgress and her flow is the next:
and the flow code api definition is the next:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/animalstore" name="AnimalStoreFlowServices" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<!-- Lógica para llamar al procedimiento almacenado -->
<log description="Log Request Payload" level="full"/>
<switch description="Route based on the Operation" source="json-eval($.Operation)">
<case regex="datosCliente">
<dblookup>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/animalstore</url>
<user>postgres</user>
<password>passwd12</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM get_animals_data();]]></sql>
<result column="nombrecompleto" name="variable1"/>
<result column="cuenta_id" name="variable3"/>
<result column="domicilio" name="variable2"/>
</statement>
<!-- Set database connection -->
</dblookup>
<!-- Mapping the captured values in a property list-->
<property description="Set response properties" expression="$ctx:variable1" name="VariableList1" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable2" name="VariableList2" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable3" name="VariableList3" scope="default" type="STRING"/>
<!-- Configure the response with the captured values -->
<payloadFactory description="Create response payload" media-type="xml">
<format>
<Response xmlns="">
<datosCliente>
<Nombre>$1</Nombre>
<Domicilio>$2</Domicilio>
<NúmeroCliente>$3</NúmeroCliente>
</datosCliente>
</Response>
</format>
<args>
<arg evaluator="xml" expression="$ctx:VariableList1"/>
<arg evaluator="xml" expression="$ctx:VariableList2"/>
<arg evaluator="xml" expression="$ctx:VariableList3"/>
</args>
</payloadFactory>
</case>
<case regex="datosCuenta">
<dblookup>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/animalstore</url>
<user>postgres</user>
<password>passwd12</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM get_herfamily_data();]]></sql>
<result column="numerocuenta" name="variable1"/>
<result column="nombrebanco" name="variable3"/>
<result column="vigencia" name="variable2"/>
</statement>
<!-- Set database connection -->
</dblookup>
<!-- Mapping the captured values in a property list-->
<property description="Set response properties" expression="$ctx:variable1" name="VariableList1" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable2" name="VariableList2" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable3" name="VariableList3" scope="default" type="STRING"/>
<!-- Configure the response with the captured values -->
<payloadFactory description="Create response payload" media-type="xml">
<format>
<Response xmlns="">
<datosCuenta>
<numeroCuenta>$1</numeroCuenta>
<vigencia>$2</vigencia>
<banco>$3</banco>
</datosCuenta>
</Response>
</format>
<args>
<arg evaluator="xml" expression="$ctx:VariableList1"/>
<arg evaluator="xml" expression="$ctx:VariableList2"/>
<arg evaluator="xml" expression="$ctx:VariableList3"/>
</args>
</payloadFactory>
</case>
<case regex="datosSaldo">
<dblookup>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/animalstore</url>
<user>postgres</user>
<password>passwd12</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM get_clinic_profile();]]></sql>
<result column="saldo" name="variable1"/>
<result column="fecha" name="variable2"/>
</statement>
<!-- Set database connection -->
</dblookup>
<!-- Mapping the captured values in a property list-->
<property description="Set response properties" expression="$ctx:variable1" name="VariableList1" scope="default" type="STRING"/>
<property description="Set response properties" expression="$ctx:variable2" name="VariableList2" scope="default" type="STRING"/>
<!-- Configure the response with the captured values -->
<payloadFactory description="Create response payload" media-type="xml">
<format>
<Response xmlns="">
<datosSaldo>
<saldo>$1</saldo>
<fecha>$2</fecha>
</datosSaldo>
</Response>
</format>
<args>
<arg evaluator="xml" expression="$ctx:VariableList1"/>
<arg evaluator="xml" expression="$ctx:VariableList2"/>
</args>
</payloadFactory>
</case>
<default>
<payloadFactory description="Create response payload for unsupported operation" media-type="xml">
<format>
<Message xmlns="">Unsupported operation.</Message>
</format>
<args/>
</payloadFactory>
</default>
</switch>
<property description="Set message type" name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond description="Send result to the client"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
at this point i use POSTMAN for get the stored procedure values and i can do it corrrectly
But i have understand that for do a unit tests i should have an end-point define for each stored procedure, anyone can orient me about how define an EndPoint?
which one should i use?
an endpoint from the Pallette or a Defined Endpoint? i need two kicks for understand completely how do a wso2 flow service.
答案1
得分: 0
你的情况下无法为存储过程执行创建端点,端点用于进行HTTP调用。由于你正在使用DBLookup中介程序,因此无法对其进行HTTP调用。所以你可以编写一个单元测试来测试整个API。如果你真的想要进行HTTP调用来执行存储过程,可以创建一个数据服务,而不是使用DbLookup中介程序,然后使用Call中介程序来调用它。
英文:
You can't create an Endpoint for the stored procedure execution in your case, Endpoints are used to do HTTP calls. Since you are using the DBLookup mediator you can't do a HTTP call on it. So you can write a unit test to test the entire API. If you really want to do an HTTP call to execute the stored procedure you can create a Dataservice instead of using the DbLookup mediator and then use the Call Mediator to call it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论