Apache Synapse/WSO2 API无响应 [英] Apache Synapse/WSO2 API No response

查看:109
本文介绍了Apache Synapse/WSO2 API无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WSO2 rest api将查询发送到数据库,并将结果返回给客户端.这是突触配置:

I want to send a query to the database and return the result to the client using WSO2 rest api. Here is the synapse config:

<api xmlns="http://ws.apache.org/ns/synapse" name="RestDBLookup" context="/dblookup">
   <resource methods="POST GET" uri-template="/channel/{name}" protocol="http">
      <inSequence>
         <dblookup>
            <connection>
               <pool>
                  <password>pass</password>
                  <driver>oracle.jdbc.driver.OracleDriver</driver>
                  <url>jdbc:oracle:thin:@localhost:1521:ORCL</url>
                  <user>user</user>
               </pool>
            </connection>
            <statement>
               <sql>SELECT ID, CHANNEL_NAME FROM CHANNEL where CHANNEL_NAME = ?</sql>
               <parameter expression="get-property('uri.var.name')" type="VARCHAR"/>
               <result name="channel_id" column="ID"/>
            </statement>
         </dblookup>
         <log level="custom">
            <property name="ID" expression="get-property('channel_id')"/>
            <property name="State" value="after db"/>
         </log>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
         <log level="full"/>
         <send/>
      </outSequence>
      <faultSequence/>
   </resource>
</api>

当我使用其余客户端调用url http://localhost:8280/dblookup/channel/someChannel时,我会在dblookup之后得到日志

When I call the url http://localhost:8280/dblookup/channel/someChannel with rest client I get the log after the dblookup

LogMediator ID = 40810162, State = after db

但未执行outSequence,我在没有主体的其余客户端上只获得状态202接受.

but the outSequence is not executed and I only get Status 202 Accepted on the rest client with no body.

所以问题是如何构造一些响应(例如JSON格式)并将其发送给客户端?

So the question is how can I construct some response (in JSON format for example) and send it to the client?

推荐答案

突触中介具有三个流程:

Synapse mediation has three flows:

  • inSequence-处理即将到来的请求并定义请求的方式 在发送到目标端点
  • 之前应先进行处理(中级)
  • outSequence-处理来自端点的响应,并定义在发送给客户端之前应如何处理(中间)响应
  • faultSequence-如果服务中介期间发生错误,则将故障消息移交给故障序列.您可以根据自己的要求(记录错误,丢弃消息并发送回故障)按故障顺序写下逻辑.
  • inSequence - handle in coming request and define how request should be processed (mediate) before send to target endpoint
  • outSequence - handle response coming back from endpoint and define how response should be processed (mediate) before send to client
  • faultSequence - if error occurred during service mediation, then fault message hand-over to fault sequence. You can write down logic in fault sequence based on your requirement (log error, drop message and send back fault).

现在让我们看看您的用例.您尝试做的是inSequence中的查询数据库.您也会得到结果.但是问题是结果没有寄回给客户.这里的问题是您在inSequence中编写的调解未调用outSequence.因此outSequence不会受到攻击.例如,如果您以inSequence调用后端服务,则响应命中outSequence.在您的情况下,响应会返回到顺序错误.因此,我们可以执行以下任一操作:

Now let's see your use-case. What you trying to do is query database in inSequence. Also you getting result as well. But problem is result not send back to client. Here problem was the mediation you written in inSequence not calling the outSequence. Therefore outSequence not getting hit. For an example if you call backend service in inSequence, then response hit to outSequence. In your case response come back to inSequence. Therefore we can do either one of following option:

  1. 在按顺序排列的</log>介体之后添加<loopback/>介体. 这会将消息从inSequence移到outSequence.
  2. 将以outSequence编写的逻辑移动到inSequence中.然后加 <respond/>在inSequence的末尾.这将发送电流 消息发回给客户.因此,您可能不需要outSequence.
  1. Adding <loopback/> mediator after </log> mediator in inSequence. This will move message from inSequence to outSequence.
  2. Move logic written in outSequence to inSequence. Then add <respond/> at the end of inSequence. This will send current message back to client. So you may not need to have outSequence.

希望以上答案有帮助.

干杯!

这篇关于Apache Synapse/WSO2 API无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆