我试图了解筛选介体的工作方式。 我有一个与SOAP API通讯的代理服务。我尝试将Filter Mediator引入其中,以用于基于标头的路由,但是它不再起作用。
请查看并让我知道我在这里做错了。
soapProxy.xml
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="soapProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<filter regex="test" source="get-property('transport','header1')">
<then>
<log description="ifLog" level="custom">
<property name="value" value="---------- Then Clause ---"/>
</log>
<send>
<endpoint key="SoapEndpoint"/>
</send>
</then>
<else>
<log description="elseLog" level="custom">
<property name="value" value="--- Else Clause ---"/>
</log>
<log description="log1" level="custom" separator="
 ---> ">
<property name="log1.message" value=" ---> printing log1"/>
<property expression="get-property('transport','header1')" name="log1.headerProperty"/>
</log>
<property description="welcomeMsgProperty" name="welcomeMsg" scope="default" type="STRING" value="------ Hello World Property Mediator"/>
<log description="log2" separator="
 ---> ">
<property name="log2.message" value=" -------------> Welcome to Log Mediator"/>
<property expression="get-property("log2.message")" name="log2.MyProperty"/>
<property expression="get-property("MessageID")" name="log2.msgID"/>
<property expression="get-property("welcomeMsg")" name="log2.welcomeMsg"/>
<property expression="$trp:Content-Type" name="log2.stockprop"/>
</log>
<send>
<endpoint key="SoapEndpoint"/>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<log description="resLog" separator="
 ---> ">
<property expression="get-property("welcomeMsg")" name="welcomeMsg"/>
<property name="test" value="*****"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
**SoapEndpoint.xml**
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="SoapEndpoint" xmlns="http://ws.apache.org/ns/synapse">
<address format="soap12" optimize="swa" uri="http://localhostlocal:9090/ws/countries.wsdl"/>
<property name="ENDPOINT_ADDRESS" value="http://localhost.local:9090/ws/countries.wsdl"/>
</endpoint>
然后,我尝试使用序列介体重定向请求,但在那里也出现了错误。 错误-找不到名为Value {name ='null',keyValue ='sequence1'}的SequenceMediator序列
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sequence1" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<send>
<endpoint>
<address uri="http://localhost:9090/ws/countries.wsdl"/>
</endpoint>
</send>
</sequence>
<filter regex="test" source="get-property('transport','header1')">
<then>
<log description="ifLog" level="custom">
<property name="value" value="---------- Then Clause ---"/>
</log>
<sequence key="sequence1"/>
</then>
.....
.....
答案 0 :(得分:2)
以下代理对我有用
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="soapProxy" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<filter regex="test" source="get-property('transport','header1')">
<then>
<log level="custom">
<property name="value" value="---------- Then Clause ---"/>
</log>
<send>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed"/>
</endpoint>
</send>
</then>
<else>
<log level="custom">
<property name="value" value="--- Else Clause ---"/>
</log>
<send>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed"/>
</endpoint>
</send>
</else>
</filter>
<respond/>
</inSequence>
</target>
<description/>
使用以下CURL命令。
卷曲-X POST \ http://localhost:8280/services/soapProxy \ -H'cache-control:no-cache'\ -H'内容类型:application / json'\ -H'header1:test2'\ -H'邮递员令牌:d4d1e767-3cd7-39a6-2782-58ab0ffba987'\ -d' { “ a”:“ a” }'
卷曲-X POST \ http://localhost:8280/services/soapProxy \ -H'cache-control:no-cache'\ -H'内容类型:application / json'\ -H'header1:测试' -H'邮递员令牌:d4d1e767-3cd7-39a6-2782-58ab0ffba987'\ -d' { “ a”:“ a” }'