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

查看:32
本文介绍了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 Accepted.

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 中查询数据库.你也得到了结果.但问题是结果不会发送回客户端.这里的问题是您在 inSequence 中编写的中介没有调用 outSequence.因此 outSequence 不会被击中.例如,如果您在 inSequence 中调用后端服务,则响应会命中 outSequence.在您的情况下,响应返回到 inSequence.因此,我们可以执行以下任一选项:

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. 在inSequence中的</log>介体之后添加介体.这会将消息从 inSequence 移动到 outSequence.
  2. 将在 outSequence 中编写的逻辑移动到 inSequence.然后加 在 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.

希望以上回答有所帮助.

Hope above answer helps.

干杯!

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

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