WSO2 API マネージャーの「フィルター」調整は、入力する必要があるとおりに入力されません。

WSO2 API マネージャーの「フィルター」調整は、入力する必要があるとおりに入力されません。

ローカルにインストールされたWSO2 APIマネージャの背後にAPIをデプロイする作業中です。 APIを設計し、エンドポイントを追加し、実行時に認証ヘッダーを追加する最初の調停シーケンスを追加しました。そしてそれは素晴らしい作品です。

これで、トークンが存在しないときにトークンを取得して期限が切れた場合は、トークンを更新するように他の仲介シーケンスを改善しています。取得したトークンはレジストリに保存されます。このために私は使用しますhttps://medium.com/@athiththan11/wso2-api-manager-oauth2-protected-endpoint-aa51c62f0ad7そしてhttps://medium.com/@menakajayawardena/wso2-how-to-using-oauth2-protected-back-ends-with-api-manager-5d7e234c61c参考のための投稿。

私の注文は次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="bapi_in_dev" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property description="Retrieve stored token data" expression="get-property('registry','gov:/bapi/token_data')" name="stored_token_data" scope="default" type="STRING"/>
    <property description="Retrieve the time token_data was generated" expression="get-property('registry', 'gov:/bapi/token_generation_time')" name="token_generation_time" scope="default" type="STRING"/>
    <filter description="Renouveller le token tmoney si il est vieux de plus d'une heure" xpath="fn:number(get-property('SYSTEM_TIME')) - fn:number(get-property('token_generation_time')) > fn:number(360000)">
        <then>
            <property description="Sauvegarde du body de la requete" expression="json-eval($)" name="client_request_body" scope="default" type="STRING"/>
            <property description="Sauvegarde de la resource demandée" expression="get-property('axis2', 'REST_URL_POSTFIX')" name="client_request_resource" scope="default" type="STRING"/>
            <payloadFactory description="Body de la requete d'obtention de token" media-type="json">
                <format>{
    "nomUtilisateur": "username",
    "motDePasse": "password"
}</format>
                <args/>
            </payloadFactory>
            <header description="Header requis par bapi" name="Content-Type" scope="transport" value="application/json"/>
            <property description="Suppression  initialisation de la resource avant demande de token" name="REST_URL_POSTFIX" scope="axis2" type="STRING" value=""/>
            <call blocking="true" description="Demande de token">
                <endpoint>
                    <http method="post" statistics="enable" trace="enable" uri-template="https://bapi.domain.tld/login">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <property description="Extraction du token" expression="json-eval($.data.token)" name="tm_resp_data" scope="default" type="STRING"/>
            <property description="Enregistrement du token" expression="get-property('tm_resp_data')" name="gov:/bapi/token_data" scope="registry" type="STRING"/>
            <property description="Enregistrement heure a laquelle code a ete genere" expression="get-property('SYSTEM_TIME')" name="gov:/bapi/token_generation_time" scope="registry" type="LONG"/>
            <property description="Configuration de la resource pour effectuer la requete de l'user" expression="get-property('client_request_resource')" name="REST_URL_POSTFIX" scope="axis2" type="STRING"/>
            <header description="Ajout du token dans le header" expression="get-property('tm_resp_data')" name="Authorization" scope="transport"/>
            <payloadFactory description="Reconstruction du body de requete user" media-type="json">
                <format>$1</format>
                <args>
                    <arg evaluator="xml" expression="get-property('client_request_body')"/>
                </args>
            </payloadFactory>
        </then>
        <else>
            <header description="Ajout de Authorization header sauvegardé" expression="get-property('stored_token_data')" name="Authorization" scope="transport"/>
        </else>
    </filter>
</sequence>

この仲介を受信APIに追加します。ただし、クエリはthenシーケンスの一部として含まれないため、トークンは更新されません。

filterなぜこれが起こるのか教えてください。これを修正するにはどうすればよいですか?

よろしくお願いします。

ベストアンサー1

説明されている中間シーケンスが動作しています。私が誤解するのは、フィルタを追加する前にプロセスのコール調整部分がログに表示されないことです(デバッグする行を設定しました)。

また、演算結果token_generation_timeのタイプを設定したときに理解できなかったことも発見しました。LONGfn:number(get-property('SYSTEM_TIME')) - fn:number(get-property('token_generation_time'))NaN

<log level="custom">
        <property expression="fn:number(get-property('SYSTEM_TIME')) - fn:number(get-property('token_generation_time'))" name="FilterV"/>
    </log>

ログから:

[2020-10-07 15:57:09,539]  INFO - LogMediator FilterV = NaN

私の問題は解決しました。私を助けることを提案したこの記事を読んでいるすべての人に感謝します。

しかし、上記のNaN結果がなぜ出てくるのかは依然として興味がある。また、シーケンスを改善するためのいくつかの提案を聞きたいです。ありがとう

おすすめ記事