WSO2 IntegrationStudio 8.2.0开关中介程序问题

huangapple go评论64阅读模式
英文:

WSO2 IntegrationStudio 8.2.0 Switch Mediator Issue

问题

我试图使用Switch中介程序构建API以设置属性并在后续阶段重用其值。这是代码。变量{environment}在API调用(例如http://localhost:8290/.../environmentvalue/test ->设置uri.var.environment = environmentvalue)时初始化。我在switch case中介程序中使用它来设置名为"target"的新属性。

这是代码的一部分:

<resource methods="POST" uri-template="/{environment}/test">
    <inSequence>
        <log level="custom">
            <property expression="get-property('uri.var.environment')" name="environment"/>
        </log>
        <switch source="get-property('uri.var.environment')">
            <case regex="prod">
                <log level="custom">
                    <property name="target" value="production"/>
                </log>
            </case>
            <case regex="pre">
                <log level="custom">
                    <property name="target" value="preproduction"/>
                </log>
            </case>
            <case regex="stag">
                <log level="custom">
                    <property name="target" value="staging"/>
                </log>
            </case>
            <default>
                <log level="custom">
                    <property name="target" value="invalid"/>
                </log>
            </default>
        </switch>
        <log level="custom">
            <property name="target" expression="get-property('target')"/>
        </log>
    </inSequence>
</resource>

当我从POSTMAN调用API(POST http://localhost:8290/.../prod/test时,在WSO2 IS控制台中我得到以下结果:

[2023-05-10 17:36:15,250] INFO {LogMediator} - {api:myapi} environment = prod
[2023-05-10 17:36:15,250] INFO {LogMediator} - {api:myapi} target = production
[2023-05-10 17:36:15,250] INFO {LogMediator} - {api:myapi} target = null

switch中介程序正常工作。URL的{environment}部分被分配给environment属性,然后用作切换情况的来源。匹配正确,switch中介程序中的target属性被正确设置为相应的情况。但在外部,它被设置为null!我尝试了几种组合来检索target属性,因为它像switch case一样已经正确初始化,但我总是得到一个'null',就好像属性范围仅限于switch嵌套。我还尝试了在switch case实例中显式分配target属性的作用域为axis2,然后通过get-property('axis2', 'target')来检索它...但一切都没有改变。每当我尝试在外部访问它时,我总是得到null。我不明白我做错了什么。

英文:

I'm trying to build an API using Switch Mediator to set up a property and reuse its value at a later stage in the sequence. Here is the code. Variable {environment} is initialized ad API call (e.g. http://localhost:8290/.../environmentvalue/test -> sets uri.var.environment = environmentvalue. I use it in the switch case mediator to set up a new property named "target".

Here is part of the code:

<resource methods="POST" uri-template="/{environment}/test">
      <inSequence>
            <log level="custom">
              <property expression="get-property('uri.var.environment')" name="environment"/>
          </log>
          <switch source="get-property('uri.var.environment')">
              <case regex="prod">
                  <log level="custom">
                      <property name="target" value="production"/>
                  </log>
              </case>
              <case regex="pre">
                  <log level="custom">
                      <property name="target" value="preproduction"/>
                  </log>
              </case>
              <case regex="stag">
                  <log level="custom">
                      <property name="target" value="staging"/>
                  </log>
              </case>
              <default>
                  <log level="custom">
                      <property name="target" value="invalid"/>
                  </log>
              </default>
          </switch>
          <log level="custom">
              <property name="target" expression="get-property('target')"/>
          </log>
   </inSequence> 
</resource>      

As I invoke the API from POSTMAN (POST http://localhost:8290/.../prod/test, IN WSO2 IS Consolle I get the following:

[2023-05-10 17:36:15,250]  INFO {LogMediator} - {api:myapi} environment = prod
[2023-05-10 17:36:15,250]  INFO {LogMediator} - {api:myapi} target = production
[2023-05-10 17:36:15,250]  INFO {LogMediator} - {api:myapi} target = null

The switch mediator works fine. {environment} part of the URL is assigned to the environment property, then used as the source for switching cases. Match is found correctly and the target property in the switch mediator is set correctly to the corresponding case. But outside it is set to null!
I tried several combinations to retrieve the target property as it has been correctly initialized as for switch case, but I always get a 'null', as if the property scope is limited to the switch nest. I also tried to explicitly assign the scope of the target property as axis2 in the switch case instances, and then retrieve it by get-property('axis2', 'target')... but nothing changed. I always get a null as I try to access it outside. I don't understand what I'm doing wrong.

答案1

得分: 1

以下是翻译好的内容:

您在日志中介者中进行了属性初始化和值分配,因此它只会被记录。因此,将属性中介者添加到日志中介者之外,就像下面这样。

英文:

You have your property initialization and value assignment in a log mediator, hence it will only be logged. So add the property mediator outside of the log mediator, like below.

<resource methods="POST" uri-template="/{environment}/test">
    <inSequence>
        <log level="custom">
            <property expression="get-property('uri.var.environment')" name="environment"/>
        </log>
        <switch source="get-property('uri.var.environment')">
            <case regex="prod">
                <property name="target" scope="default" type="STRING" value="production"/>
                <log level="custom">
                    <property name="target" value="production"/>
                </log>
            </case>
            <case regex="pre">
                <log level="custom">
                    <property name="target" value="preproduction"/>
                </log>
            </case>
            <case regex="stag">
                <log level="custom">
                    <property name="target" value="staging"/>
                </log>
            </case>
            <default>
                <log level="custom">
                    <property name="target" value="invalid"/>
                </log>
            </default>
        </switch>
        <log level="custom">
            <property expression="get-property('target')" name="target"/>
        </log>
    </inSequence>
</resource>

huangapple
  • 本文由 发表于 2023年5月11日 00:16:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定