【发布时间】:2015-01-29 12:28:25
【问题描述】:
我在 WSO2 ESB 4.8.1 上。 如果它们的路径与正则表达式匹配,我需要阻止一些请求。所以我已经实现了这个代理和这些序列:
在我的代理中:
<target>
<inSequence>
<sequence key="MySequence"></sequence>
<send>
<endpoint key="epProva"></endpoint>
</send>
</inSequence>
MySequence 在哪里:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="MySequence">
<conditionalRouter continueAfter="false">
<conditionalRoute breakRoute="true" asynchronous="true">
<condition>
<match type="url" regex=".*/my/path/.*"></match>
</condition>
<target sequence="conf:/BannedListMessage"></target>
</conditionalRoute>
</conditionalRouter>
</sequence>
BannedListMessage 在哪里:
<sequence xmlns="http://ws.apache.org/ns/synapse">
<header name="To" action="remove"></header>
<property name="HTTP_SC" value="401" scope="axis2"></property>
<property name="RESPONSE" value="true"></property>
<property name="NO_ENTITY_BODY" action="remove" scope="axis2"></property>
<payloadFactory media-type="json">
<format>
{"code":"401", "unhautorized."}
</format>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"></property>
<send></send>
</sequence>
MySquence 的任务是检查请求 url 是否与正则表达式匹配,在这种情况下,它必须在请求到达服务器之前阻止请求流,并调用将发回错误的 BannedListMessage 序列对客户端的响应 (401)。
在我尝试的过程中,我注意到了
如果 MySequence 中的属性 continueAfter=true 我得到 401“未授权”错误作为响应,但请求到达服务器。
如果我设置 continueAfter="false" 我会收到 202 Accepted 响应并且请求不会到达服务器。
我的目标是向客户端发送 BannedListMessage 401 错误并阻止请求。我该怎么办?
【问题讨论】:
标签: routing wso2 wso2esb blocking