在WSO2 Integration Studio中定义端点。

huangapple go评论61阅读模式
英文:

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:
在WSO2 Integration Studio中定义端点。

and the flow code api definition is the next:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;api context=&quot;/animalstore&quot; name=&quot;AnimalStoreFlowServices&quot; xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
&lt;resource methods=&quot;POST&quot;&gt;
&lt;inSequence&gt;
&lt;!-- L&#243;gica para llamar al procedimiento almacenado --&gt;
&lt;log description=&quot;Log Request Payload&quot; level=&quot;full&quot;/&gt;
&lt;switch description=&quot;Route based on the Operation&quot; source=&quot;json-eval($.Operation)&quot;&gt;
&lt;case regex=&quot;datosCliente&quot;&gt;
&lt;dblookup&gt;
&lt;connection&gt;
&lt;pool&gt;
&lt;driver&gt;org.postgresql.Driver&lt;/driver&gt;
&lt;url&gt;jdbc:postgresql://localhost:5432/animalstore&lt;/url&gt;
&lt;user&gt;postgres&lt;/user&gt;
&lt;password&gt;passwd12&lt;/password&gt;
&lt;/pool&gt;
&lt;/connection&gt;
&lt;statement&gt;
&lt;sql&gt;&lt;![CDATA[SELECT * FROM get_animals_data();]]&gt;&lt;/sql&gt;
&lt;result column=&quot;nombrecompleto&quot; name=&quot;variable1&quot;/&gt;
&lt;result column=&quot;cuenta_id&quot; name=&quot;variable3&quot;/&gt;
&lt;result column=&quot;domicilio&quot; name=&quot;variable2&quot;/&gt;
&lt;/statement&gt;
&lt;!-- Set database connection --&gt;
&lt;/dblookup&gt;
&lt;!-- Mapping the captured values in a property list--&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable1&quot; name=&quot;VariableList1&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable2&quot; name=&quot;VariableList2&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable3&quot; name=&quot;VariableList3&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;!-- Configure the response with the captured values --&gt;
&lt;payloadFactory description=&quot;Create response payload&quot; media-type=&quot;xml&quot;&gt;
&lt;format&gt;
&lt;Response xmlns=&quot;&quot;&gt;
&lt;datosCliente&gt;
&lt;Nombre&gt;$1&lt;/Nombre&gt;
&lt;Domicilio&gt;$2&lt;/Domicilio&gt;
&lt;N&#250;meroCliente&gt;$3&lt;/N&#250;meroCliente&gt;
&lt;/datosCliente&gt;
&lt;/Response&gt;
&lt;/format&gt;
&lt;args&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList1&quot;/&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList2&quot;/&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList3&quot;/&gt;
&lt;/args&gt;
&lt;/payloadFactory&gt;
&lt;/case&gt;
&lt;case regex=&quot;datosCuenta&quot;&gt;
&lt;dblookup&gt;
&lt;connection&gt;
&lt;pool&gt;
&lt;driver&gt;org.postgresql.Driver&lt;/driver&gt;
&lt;url&gt;jdbc:postgresql://localhost:5432/animalstore&lt;/url&gt;
&lt;user&gt;postgres&lt;/user&gt;
&lt;password&gt;passwd12&lt;/password&gt;
&lt;/pool&gt;
&lt;/connection&gt;
&lt;statement&gt;
&lt;sql&gt;&lt;![CDATA[SELECT * FROM get_herfamily_data();]]&gt;&lt;/sql&gt;
&lt;result column=&quot;numerocuenta&quot; name=&quot;variable1&quot;/&gt;
&lt;result column=&quot;nombrebanco&quot; name=&quot;variable3&quot;/&gt;
&lt;result column=&quot;vigencia&quot; name=&quot;variable2&quot;/&gt;
&lt;/statement&gt;
&lt;!-- Set database connection --&gt;
&lt;/dblookup&gt;
&lt;!-- Mapping the captured values in a property list--&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable1&quot; name=&quot;VariableList1&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable2&quot; name=&quot;VariableList2&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable3&quot; name=&quot;VariableList3&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;!-- Configure the response with the captured values --&gt;
&lt;payloadFactory description=&quot;Create response payload&quot; media-type=&quot;xml&quot;&gt;
&lt;format&gt;
&lt;Response xmlns=&quot;&quot;&gt;
&lt;datosCuenta&gt;
&lt;numeroCuenta&gt;$1&lt;/numeroCuenta&gt;
&lt;vigencia&gt;$2&lt;/vigencia&gt;
&lt;banco&gt;$3&lt;/banco&gt;
&lt;/datosCuenta&gt;
&lt;/Response&gt;
&lt;/format&gt;
&lt;args&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList1&quot;/&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList2&quot;/&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList3&quot;/&gt;
&lt;/args&gt;
&lt;/payloadFactory&gt;
&lt;/case&gt;
&lt;case regex=&quot;datosSaldo&quot;&gt;
&lt;dblookup&gt;
&lt;connection&gt;
&lt;pool&gt;
&lt;driver&gt;org.postgresql.Driver&lt;/driver&gt;
&lt;url&gt;jdbc:postgresql://localhost:5432/animalstore&lt;/url&gt;
&lt;user&gt;postgres&lt;/user&gt;
&lt;password&gt;passwd12&lt;/password&gt;
&lt;/pool&gt;
&lt;/connection&gt;
&lt;statement&gt;
&lt;sql&gt;&lt;![CDATA[SELECT * FROM get_clinic_profile();]]&gt;&lt;/sql&gt;
&lt;result column=&quot;saldo&quot; name=&quot;variable1&quot;/&gt;
&lt;result column=&quot;fecha&quot; name=&quot;variable2&quot;/&gt;
&lt;/statement&gt;
&lt;!-- Set database connection --&gt;
&lt;/dblookup&gt;
&lt;!-- Mapping the captured values in a property list--&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable1&quot; name=&quot;VariableList1&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;property description=&quot;Set response properties&quot; expression=&quot;$ctx:variable2&quot; name=&quot;VariableList2&quot; scope=&quot;default&quot; type=&quot;STRING&quot;/&gt;
&lt;!-- Configure the response with the captured values --&gt;
&lt;payloadFactory description=&quot;Create response payload&quot; media-type=&quot;xml&quot;&gt;
&lt;format&gt;
&lt;Response xmlns=&quot;&quot;&gt;
&lt;datosSaldo&gt;
&lt;saldo&gt;$1&lt;/saldo&gt;
&lt;fecha&gt;$2&lt;/fecha&gt;
&lt;/datosSaldo&gt;
&lt;/Response&gt;
&lt;/format&gt;
&lt;args&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList1&quot;/&gt;
&lt;arg evaluator=&quot;xml&quot; expression=&quot;$ctx:VariableList2&quot;/&gt;
&lt;/args&gt;
&lt;/payloadFactory&gt;
&lt;/case&gt;
&lt;default&gt;
&lt;payloadFactory description=&quot;Create response payload for unsupported operation&quot; media-type=&quot;xml&quot;&gt;
&lt;format&gt;
&lt;Message xmlns=&quot;&quot;&gt;Unsupported operation.&lt;/Message&gt;
&lt;/format&gt;
&lt;args/&gt;
&lt;/payloadFactory&gt;
&lt;/default&gt;
&lt;/switch&gt;
&lt;property description=&quot;Set message type&quot; name=&quot;messageType&quot; scope=&quot;axis2&quot; type=&quot;STRING&quot; value=&quot;application/json&quot;/&gt;
&lt;respond description=&quot;Send result to the client&quot;/&gt;
&lt;/inSequence&gt;
&lt;outSequence/&gt;
&lt;faultSequence/&gt;
&lt;/resource&gt;
&lt;/api&gt;

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.

huangapple
  • 本文由 发表于 2023年6月13日 09:52:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定