Wso2缓存介体未返回预期的响应

问题描述

我将缓存介体用于令牌生成,因为所有方法都将使用相同的令牌。我遇到的问题是,没有从不同API的缓存中选择响应。 让我在下面用例子解释一下 如果我有User方法,并且想获取用户列表,则我在API Manager中的网址会喜欢 /t/abc.com/context1/getUser 获取方法) 如果我想创建User,则url看起来像 /t/abc.com/context1/用户(发布方法) 如果我想要getUserAttributes,则url看起来像 /t/abc.com/context2/getUserAttributes 获取方法)。请注意,这里的上下文与之前的2

不同

在所有3种情况下,都使用相同的In Sequence和Out Sequence文件。请注意,在InSequence文件调用令牌生成方法之前,将删除所有动态标头值。下面是相同的代码段。

无序列(inSeq_1.xml)

<script language="js"><![CDATA[var payload = mc.getPayloadJSON();
    mc.setProperty("jsonPayload",JSON.stringify(payload));]]></script>
    <payloadFactory media-type="json"> // to make payload empty
        <format/>
        <args/>
    </payloadFactory>

<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
    <property action="remove" name="Cookie" scope="transport"/>
    <property action="remove" name="id" scope="transport"/>
    <cache collector="false" timeout="3600">
        <onCacheHit>
            <sequence key="gov:/apimgt/customsequences/in/inSeq_2.xml"/>
        </onCacheHit>
        <protocol type="HTTP">
            <methods>*</methods>
            <headersToExcludeInHash/>
            <responseCodes>.*</responseCodes>
            <enableCacheControl>false</enableCacheControl>
            <includeAgeHeader>false</includeAgeHeader>
            <hashGenerator>org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator</hashGenerator>
        </protocol>
        <implementation maxSize="500"/>
    </cache>
    <send receive="gov:/apimgt/customsequences/out/outSeq_1.xml">
        <endpoint>
            <http method="get" uri-template="{uri.var.tokenGenerationUrl}"/>
        </endpoint>
    </send>

OutSequence (outSeq_1.xml)

<cache collector="true"/>
    <sequence key="gov:/apimgt/customsequences/in/inSeq_2.xml"/>

这是我面临的问题

  • 如果我两次调用getUser API,则会得到相同的令牌。但是,如果稍后再调用getUser之后再调用user(Post),则会得到不同的令牌,这是为什么呢?缓存是否应该与uri.var.tokenGenerationUrl相关,而不是与getUser或user(Post)方法有关?
  • 如果我先调用getUser方法,然后再调用getUserAttributes(请注意,两者均具有不同的上下文,并且在API Manager中属于不同的API),则两者均返回不同的Jwt。

注意:甚至To To Header都已指向tokenGenerationUrl。

因此有人可以告诉我缓存代码有什么问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)