问题描述
我已根据文档配置了全局中介扩展。文件 global_ext.xml 放在 wso2am-3.2.0\repository\deployment\server\synapse-configs\default\sequences 下。
<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
<property name="token" expression="get-property('transport','Authorization')"/>
</sequence>
public boolean handleRequest(MessageContext messageContext) {
String accesstoken = (String) messageContext.getProperty("token");
但是,令牌属性在 MessageContext 属性中不可用。知道这里出了什么问题吗?或者如何在handler中获取token的值?
解决方法
如果 handleRequest(MessageContext messageContext)
方法是扩展 AbstractHandler
(Writing Custom handlers) 的某个 CustomHandler 类,那么它不会像您期望的那样工作。
这是因为处理程序在序列之前运行。 WSO2 文档中描述了消息流:Message flow in the API Manager Gateway,看起来像这样:
所以你可以在handler中设置一些属性并按顺序读取,其他方式不起作用。