顶点覆盖目标.带有自定义变量的Url



我一直在尝试覆盖目标。url与使用分配消息策略的变量。对于其他解决方案,我将其放在"目标端点"部分。问题是,除非我硬编码URL的根部分,否则替换将失败。我已经尝试了下面所有的注释值stmts,然后开始添加"REF"stmts来试图解决这个问题-无济于事。您可以看到,我已经尝试使用Extract策略将目标切割成各种片段,但无法得到有效的解决方案。

谢谢你的帮助。

对于

下面的代码片段
entireURL = "http://my.root.url/thestuff/morestuff"
AppServerURL = "my.root.url/thestuff/morestuff"
AppServerRoot = "my.root.url"
AppServerSfx = "thestuff/morestuff"

分配消息策略的代码

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Post-to-named-serverL">
    <DisplayName>Post to named server</DisplayName>
    <FaultRules/>
    <Properties/>
    <AssignVariable>
          <Name>target.url</Name>
          <Value>http://${AppServerRoot}/{AppServerSfx}</Value>
          <Ref/>
          <!--
            <Value>http://my.root.url/{AppServerSfx}</Value>  works but I need the root changed
            <Value>http://{AppServerRoot}/{AppServerSfx}</Value>
            <Value>http://${AppServerRoot}/{AppServerSfx}</Value>
            <Value>http://{AppServerURL}</Value>
            <Value>http://${AppServerURL}</Value>
            <Value>entireURL</Value>
            <Value>{entireURL}</Value>  -- this was my first try
            <Value>${entireURL}</Value>
            <Ref>entireURL</Ref>
            <Ref>{entireURL}</Ref>
            <Ref>${entireURL}</Ref>
          -->
    </AssignVariable>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

您正确地将target.url操作放在目标请求流中。

使用AssignMessage/AssignVariable是有限制的。Value元素不允许你做任何变量替换。

下面的方法对我有用:

<Ref>entireURL</Ref>

Ref也不允许变量替换——它只取变量名。因为你必须提前构建该变量的值,所以使用上面的Ref示例并不能给你带来多少好处。

我通常使用类似于以下代码的JavaScript callout完成目标URL重写:

var appServerRoot = context.getVariable("AppServerRoot");
var appServerSfx = context.getVariable("AppServerSfx");
context.setVariable("target.url", "http://" + appServerRoot + "/" + appServerSuffix);

最新更新