微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

布尔类型属性在WSO2 EI 6.1.1中不起作用

如何解决布尔类型属性在WSO2 EI 6.1.1中不起作用

我正在将 BOOLEAN 类型属性值(请参见代码 delete_all_contacts 属性)传递给在WSO2 EI 6.1.1中不起作用的端点URL。出现错误,例如“ delete_all_contacts'是布尔值必需的参数” 。我认为即使属性类型为BOOLEAN,也总是将其视为“ STRING”类型。请有人帮助我解决此问题吗?

参考链接 https://sendgrid.api-docs.io/v3.0/contacts/delete-contacts

API代码

<api context="/contactapi" name="ContactAPI" xmlns="http://ws.apache.org/ns/synapse">
        <resource methods="POST" uri-template="/deletecontact?*">
             <inSequence>
          
          <log level="custom">
                <property name="===Delete contacts " value=" API Called===="/>
                <property expression="get-property('query.param.delete_all_contacts')/" name="===query.param.delete_all_contacts==="/>
                <property expression="get-property('query.param.ids')/" name="===query.param.ids==="/>
            </log>
            
            <property  name="delete_all_contacts" expression="get-property('query.param.delete_all_contacts')" scope="default" type="BOOLEAN"/>
            <property expression="get-property('query.param.ids')" name="ids" scope="default" type="STRING"/>
            <property expression="get-property('Sendgrid-Config')" name="SendgridConfig" scope="default" type="OM"/>
            <property description="apiKey" expression="$ctx:SendgridConfig//*[local-name()='apiKey']" name="apiKey" scope="default" type="STRING"/>
            <header expression="fn:concat('Bearer ',get-property('apiKey'))" name="Authorization" scope="transport"/>
            <filter regex="true" source="boolean(get-property('delete_all_contacts'))">
                <then>
                 
                    <header expression="fn:concat('https://api.sendgrid.com/v3/marketing/contacts','?delete_all_contacts=',get-property('delete_all_contacts'))" name="To" scope="default"/>
                    <log level="custom">
                        <property expression="get-property('To')" name="===To==="/>
                    </log>
                </then>
                <else>
                    <header expression="fn:concat('https://api.sendgrid.com/v3/marketing/contacts','?ids=',get-property('ids'))" name="To" scope="default"/>
                    <log level="custom">
                        <property expression="get-property('To')" name="===To==="/>
                    </log>
                </else>
            </filter>
            <property name="HTTP_METHOD" scope="axis2" type="STRING" value="DELETE"/>
            <call>
                <endpoint>
                    <default/>
                </endpoint>
            </call>
            <respond/>
            </inSequence>
        <outSequence/>
        <faultSequence>
            <log level="custom">
                <property name="===faultSequence" value="Called=="/>
                <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/>
            </log>
        </faultSequence>
    </resource>
</api>

API详细信息:

URL :http:// localhost:8280 / contactapi / deletecontact?delete_all_contacts = true

方法删除

错误响应:

{"message":"'delete_all_contacts' is  boolean required param","parameter":"delete_all_contacts"}

解决方法

我尝试了精简版的API,它似乎可以正常工作。

<api xmlns="http://ws.apache.org/ns/synapse" name="ContactAPI" context="/contactapi">
   <resource methods="POST" uri-template="/deletecontact?*">
      <inSequence>
         <log level="custom">
            <property name="===Delete contacts " value=" API Called===="/>
            <property name="===query.param.delete_all_contacts===" expression="get-property('query.param.delete_all_contacts')/"/>
         </log>
         <property name="delete_all_contacts" expression="get-property('query.param.delete_all_contacts')" scope="default" type="BOOLEAN"/>
         <filter source="boolean(get-property('delete_all_contacts'))" regex="true">
            <then>
               <log level="custom">
                  <property name="===Inside===" value="Then"/>
               </log>
            </then>
            <else>
               <log level="custom">
                  <property name="===Inside===" value="Else"/>
               </log>
            </else>
         </filter>
         <respond/>
      </inSequence>
      <outSequence/>
      <faultSequence>
         <log level="custom">
            <property name="===faultSequence" value="Called=="/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
         </log>
      </faultSequence>
   </resource>
</api>
                        

但是,我注意到您已将资源方法定义为POST,并发送了一个DELETE请求。也许这会引起一些问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。