首页 > 解决方案 > 读取 WSO2 EI 中的 LocalEntry 值

问题描述

我正在尝试根据动态用户输入读取本地条目值(如果Feed是用户输入,则应获取 Feed 中的值(主机、用户、密码等)。但没有为我获取值。任何人都可以建议我实现这个?

本地入口

<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="MailTo_Details">
   <MAIL_Details xmlns="http://mail.com/localentry">
      <Lead>
         <credentials>
            <host>smtp.gmail.com</host>
            <port>587</port>
            <starttls.enable>true</starttls.enable>
            <auth>false</auth>
            <user>Demouser</user>
            <password>email1pws</password>
            <from>email1@gmail.com</from>
         </credentials>
      </Lead>
      <Feed>
         <credentials>
            <host>smtp.gmail.com</host>
            <port>587</port>
            <starttls.enable>true</starttls.enable>
            <auth>false</auth>
            <user>Testuser</user>
            <password>email2pws</password>
            <from>email2@gmail.com</from>
         </credentials>
      </Feed>
   </MAIL_Details>
   <description/>
</localEntry>

我已加载 localentry 并将值设置为 OM 类型。但我不知道动态检索值的方法。

<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
             xmlns:ns="http://org.apache.synapse/xsd"
             xmlns:ns3="http://org.apache.synapse/xsd"
             name="mailConfig"
             expression="get-property('MailTo_Details')"
             scope="default"
             type="OM"/>

标签: wso2wso2carbonwso2eisynapse

解决方案


试试这个代理:

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="loadPayloadfromLocalEntry" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property expression="get-property('MailTo_Details')" name="mailConfig" scope="default" type="OM" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>
            <property name="getinput" scope="default" type="STRING" expression="$body/getdata/mailinput"/>
            <property name="apos" scope="default" type="STRING" value="'"/>
            <log>
                <property name="printValueEmail" expression="$ctx:mailConfig"/>
                <property name="getinput" scope="default" type="STRING" expression="$body/getdata/mailinput"/>
                 <property name="HOST" expression="evaluate(fn:concat('$ctx:mailConfig//ns:',get-property('getinput'),'/ns:credentials/ns:host'))" xmlns:ns="http://mail.com/localentry"/>                                
            </log>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>

以有效载荷为主体:

<body>
<getdata>
    <mailinput>Feed</mailinput>
</getdata>
</body>

我的日志消息:

[2020-07-27 11:39:32,487]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /services/loadPayloadfromLocalEntry.loadPayloadfromLocalEntryHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bc74622a-3843-4813-ab35-769138d5f8e6, Direction: request, printValueEmail = <MAIL_Details xmlns="http://mail.com/localentry">
        <Lead>
            <credentials>
                <host>smtp.gmail.com</host>
                <port>587</port>
                <starttls.enable>true</starttls.enable>
                <auth>false</auth>
                <user>Demouser</user>
                <password>email1pws</password>
                <from>email1@gmail.com</from>
            </credentials>
        </Lead>
        <Feed>
            <credentials>
                <host>smtp.gmail.com</host>
                <port>587</port>
                <starttls.enable>true</starttls.enable>
                <auth>false</auth>
                <user>Testuser</user>
                <password>email2pws</password>
                <from>email2@gmail.com</from>
            </credentials>
        </Feed>
    </MAIL_Details>, getinput = Feed, HOST = smtp.gmail.com

推荐阅读