0

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"/>
Justin
  • 855
  • 2
  • 11
  • 30
  • You can use an xpath expression to get the data...so before that you need to construct the xpath expression using the fn:concat function and the evaluate expression, you need something like $ctx:mailConfig//ns:Lead/ns:Feed/ns: credentials/ns:host – Jorge Infante Osorio Jul 27 '20 at 04:24
  • Hi @JorgeInfanteOsorio, Thanks for ur response. that Lead or Feed values comes from input. here Process is the property get userInput. but below is not working.. – Justin Jul 27 '20 at 04:54

1 Answers1

3

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
Jorge Infante Osorio
  • 2,143
  • 15
  • 26