【发布时间】:2016-04-15 19:22:13
【问题描述】:
我想向数据库发送一个查询,并使用 WSO2 rest api 将结果返回给客户端。这是突触配置:
<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>
当我用 rest 客户端调用 url http://localhost:8280/dblookup/channel/someChannel 时,我在 dblookup 之后得到日志
LogMediator ID = 40810162, State = after db
但是outSequence 没有执行,我只在没有正文的其余客户端上得到状态 202 Accepted。
所以问题是如何构造一些响应(例如 JSON 格式)并将其发送给客户端?
【问题讨论】:
标签: api rest wso2 wso2esb synapse