我有一个 WSO2 突触文件来处理网关级别的 API 请求。我已经为端点配置了我的 GET 和 POST/PUT,如下所示。我有一个自定义处理程序,它处理允许特定主机调用这些 API。我要求允许来自任何主机的 GET 和仅来自特定主机的 POST/PUT。但是,我无法在我的突触文件中配置它,因为我们在文件中定义的处理程序正在应用于所有 HTTP 方法。有没有办法为同一端点/上下文配置基于 HTTP 方法的处理程序。如何让我的自定义处理程序 (com.abc.wso2.handler.HostRestrictionHandler) 仅适用于 POST?PUT 调用?下面是我的配置。
<api xmlns="http://ws.apache.org/ns/synapse" context="/user/notification/v3" version="v2" version-type="context">
<resource methods="GET" uri-template="/*">
<inSequence>
<class name="org.wso2.carbon.apimgt.gateway.mediators.TokenPasser"/>
<filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
<then>
<class name="com.abc.mediators.DispatchMediator">
<property name="url" value="http://api.{HOST_NAME}.com/user/notification/v3"/>
</class>
<send>
<endpoint name="Notification_API">
<address>
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</send>
</then>
<else>
<sequence key="_sandbox_key_error_"/>
</else>
</filter>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
<resource methods="POST PUT" uri-template="/*">
<inSequence>
<property name="X-Forwarded-Host" scope="transport" expression="$trp:Host"/>
<class name="org.wso2.carbon.apimgt.gateway.mediators.TokenPasser"/>
<filter regex="PRODUCTION" source="$ctx:AM_KEY_TYPE">
<then>
<class name="com.abc.mediators.DispatchMediator">
<property name="url" value="http://api.{HOST_NAME}.com/user/notification/v3"/>
</class>
<send>
<endpoint name="Notification_API_2">
<address>
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</send>
</then>
<else>
<sequence key="_sandbox_key_error_"/>
</else>
</filter>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="com.abc.wso2.handler.HostRestrictionHandler">
<property name="allowedHosts" value="my.customhost.com" />
</handler>
</handlers>
</api>