wso2wso2-enterprise-integratorapache-synapse

To read LocalEntry values in WSO2 EI


I am trying to read local Entry values based on dynamic user input(if Feed is user Input, then values inside Feed (host,user,password etc) should be fetched. but values not getting fetched for me. can anyone suggest me to achueve this?

LocalEntry:

<?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>

I have loaded localentry and setting values as OM type.But i don't know way to retrieving values by dynamically.

<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"/>

Solution

  • Try this proxy:

    <?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>
    

    With payload as body:

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

    My log message:

    [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