我已经创建了一个REST,它使用数据库查找中介器搜索microsoft,我希望根据我的数据库中是否存在UserCode字段来重定向到网页。在尝试测试我的API时,我不会收到错误,但它也不会重定向。请看下面我在EI上创建的API代码。
<api xmlns="http://ws.apache.org/ns/synapse" name="DBLookupAPI" context="/dblookup">
<resource methods="GET" uri-template="/{UserCode}">
<inSequence>
<log level="custom">
<property name="Value" expression="get-property('uri.var.UserCode')"/>
</log>
<dblookup>
<connection>
<pool>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://10.1.1.111\test;databaseName=UserDB</url>
<user>admin</user>
<password>admin</password>
</pool>
</connection>
<statement>
<sql>select UserCode from UserDB.dbo.Users where UserCode =?;</sql>
<parameter expression="get-property('uri.var.UserCode ')" type="CHAR"/>
<result name="foundnr" column="UserCode "/>
</statement>
</dblookup>
<log level="custom">
<property name="Value" expression="get-property('foundnr')"/>
</log>
<filter source="boolean(get-property('foundnr'))" regex="true">
<then>
<log>
<property name="Message" value="Name Exists Lets redirect"/>
</log>
<property name="HTTP_SC" value="302"/>
<property name="Location" value="https://wso2.com/"/>
</then>
<else>
<log>
<property name="Message" value="Name Does Not Exist Lets redirect"/>
</log>
<property name="HTTP_SC" value="302"/>
<property name="Location" value="https://www.youtube.com/"/>
</else>
</filter>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api> 我的wso2-ei-api日志显示
TID: [-1234] [2022-11-10 15:57:12,665] INFO {API_LOGGER.DBLookupAPI} - Value = Sash18
TID: [-1234] [2022-11-10 15:57:12,727] INFO {API_LOGGER.DBLookupAPI} - Value = Sash18
TID: [-1234] [2022-11-10 15:57:12,728] INFO {API_LOGGER.DBLookupAPI} - To: /dblookup/Sash18, MessageID: urn:uuid:e37541a7-eabd-4d70-8bde-6f9dfc2ebfee, Direction: request, Message = Name Exists Lets redirect
TID: [-1234] [2022-11-10 15:57:19,067] INFO {API_LOGGER.DBLookupAPI} - Value = No
TID: [-1234] [2022-11-10 15:57:19,120] INFO {API_LOGGER.DBLookupAPI} - Value = null
TID: [-1234] [2022-11-10 15:57:19,121] INFO {API_LOGGER.DBLookupAPI} - To: /dblookup/No, MessageID: urn:uuid:6fd1a264-5f1b-45d8-bcc4-b52a079abbd3, Direction: request, HTTP_SC = 302, Location = https://www.youtube.com/首先输入Sash18,这是我的数据库中的UserCode,然后输入no,它不是数据库中的UserCode。
我甚至尝试创建一个API来调用数据服务,而不是使用db查找中介,而且这种方法也没有重定向。(我把这个作为另一个问题发布了)
发布于 2022-11-09 12:05:01
DBLookupMediator的结果将被设置为名为foundnr的属性。因此,在您的FileterMediator中,您需要检查该属性的可用性。
<filter source="boolean(get-property('foundnr'))" regex="true">
<then>
<log>
<property name="Message" value="Name Exists Lets redirect"/>
</log>
<property name="HTTP_SC" value="302" scope="axis2" type="STRING"/>
<property name="Location" value="https://wso2.com/" scope="transport" type="STRING"/>
</then>
<else>
<log>
<property name="HTTP_SC" value="302"/>
<property name="Location" value="https://www.youtube.com/"/>
</log>
</else>
</filter>https://stackoverflow.com/questions/74373497
复制相似问题