我定义了一个简单的pass-thru API,其中包含oauthService
来验证访问令牌。与此类似:
<api xmlns="http://ws.apache.org/ns/synapse" name="aservice" context="/aservice/v1">
<resource methods="POST PUT GET" uri-template="/*" faultSequence="ServiceFault">
<inSequence>
<oauthService remoteServiceUrl="https://identityserver:9444/services/" username="admin" password="admin" description="oauth2"/>
<send>
<endpoint name="aservice-endpoint">
<address uri="http://aservice:8080/aservice/v1"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
它包括ServiceFault将一般消息发送回客户端。
我的问题是,是否有可能有一个单独的错误处理程序来处理来自oauthService
的验证错误?我也想处理来自地址端点的错误(即主机关闭等)。在一个故障序列定义中调用所有这些?
我希望能够设置不同的HTTP响应代码和标头,具体取决于错误是oauth2错误还是其他错误类型。
答案 0 :(得分:1)
有一种方法可以通过使用单独的序列来实现它。您可以将oauthService放到一个单独的序列中,然后在标记onError
中有自己的faultSequence:
<api xmlns="http://ws.apache.org/ns/synapse" name="aservice" context="/aservice/v1">
<resource methods="POST PUT GET" uri-template="/*" faultSequence="ServiceFault">
<inSequence>
<sequence key="oauthSequence"/>
<send>
<endpoint name="aservice-endpoint">
<address uri="http://aservice:8080/aservice/v1"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="oauthSequence" onError="myOauthFaultSequence">
<oauthService remoteServiceUrl="https://identityserver:9444/services/" username="admin" password="admin" description="oauth2"/>
</sequence>
请参阅序列的onError描述:https://docs.wso2.com/display/ESB481/Mediation+Sequences