8 Replies Latest reply: Mar 15, 2013 10:35 PM by 991448 RSS

    Embedded Java Code - How to retrieve multivalue payload value

    Kevin Pinsky
      I'm working in my SOA-Composite which is used with OIM and our approval process. Here is an example of the payload data:
      >
      <ns2:RequesterDetails>
      <ns2:FirstName>System</ns2:FirstName>
      <ns2:MiddleName/>
      <ns2:LastName>Administrator</ns2:LastName>
      <ns2:Login>XELSYSADM</ns2:Login>
      <ns2:DisplayName>System Administrator</ns2:DisplayName>
      <ns2:ManagerLogin/>
      <ns2:OrganizationName>Xellerate Users</ns2:OrganizationName>
      <ns2:Email>xelsysadm@test.com</ns2:Email>
      <ns2:StartDate/>
      <ns2:EndDate/>
      <ns2:Status>Active</ns2:Status>
      <ns2:XellerateType>End-User Administrator</ns2:XellerateType>
      <ns2:UserType>Full-Time</ns2:UserType>
      <ns2:Role>SYSTEM ADMINISTRATORS</ns2:Role>
      <ns2:Role>Test Role 1</ns2:Role>
      <ns2:Role>Test Role 2</ns2:Role>
      </ns2:RequesterDetails>
      >
      I am able to retrieve single values with code like this:
      >
      //Retrieve Requester Login
      Object requesterXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails/ns4:Login");
      String requesterLogin = ((oracle.xml.parser.v2.XMLElement)requesterXMLElem).getText();
      >
      How do i retrieve the multivalue Role values and not just a single entry?

      Thanks,
      Kevin
        • 1. Re: Embedded Java Code - How to retrieve multivalue payload value
          991448
          Try this Kevin,
          Object requesterXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails//ns4:Role");

          Edited by: 988445 on Mar 13, 2013 7:30 PM
          • 2. Re: Embedded Java Code - How to retrieve multivalue payload value
            Kevin Pinsky
            988445 wrote:
            Try this Kevin,
            Object requesterXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails//ns4:Role");

            Edited by: 988445 on Mar 13, 2013 7:30 PM
            Give me a little credit here. I did try that already and it returned only a single role entry. I use the same format to return other attributes from the payload. In this case though, I need the full list, or a way to step through the multi value item.

            Thanks,
            Kevin
            • 3. Re: Embedded Java Code - How to retrieve multivalue payload value
              991448
              Hi Kevin,
              Not sure why would you use // to retrieve a single node. Essentially // is supposed to return all the nodes which match the xpath.
              //     Selects nodes in the document from the current node that match the selection no matter where they are

              See http://www.w3schools.com/xpath/xpath_syntax.asp

              Will try at my end and let you know
              • 4. Re: Embedded Java Code - How to retrieve multivalue payload value
                Kevin Pinsky
                I see what i missed with the doube slash, i thought you had a typo and assumed i used it. If i use the following:

                //Retrieve Requester Roles
                Object requesterRolesXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails//ns4:Role");
                System.out.println("Requester Roles Type[" + requesterRolesXMLElem.getClass() + "]");
                int requesterRolesCount = ((oracle.xml.parser.v2.XMLElement)requesterRolesXMLElem).getAttributes().getLength();
                System.out.println("Requester Roles Length[" + requesterRolesCount + "]");
                String requesterRole = ((oracle.xml.parser.v2.XMLElement)requesterRolesXMLElem).getText();
                System.out.println("Requester Roles[" + requesterRole + "]");

                I get the following output:

                Requester Roles Type[class oracle.xml.parser.v2.XMLElement]
                Requester Roles Length[0]
                Requester Roles[SYSTEM ADMINISTRATORS]

                I am not seeing how to loop through each if the type is class oracle.xml.parser.v2.XMLElement

                Thanks,
                Kevin
                • 5. Re: Embedded Java Code - How to retrieve multivalue payload value
                  991448
                  Hi Kevin,
                  Here is another thing which you can try..
                  In your BPEL process decalre a variable say (NumberOfRoles)of type int and use a assign the value of this function "count(/ns3:process/ns4:RequeasterDetails/ns4:Role)" which will return you the count of role element.
                  Then in your java code retrive the value of variable NumberOfRoles first and then try to loop as follows.

                  for(int i=1 ;i<getVariableData(value of variable NumberOfRoles);i++) {

                  Object roleElement= getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails/ns4:Role [ i ] ");
                  String requesterLogin = ((oracle.xml.parser.v2.XMLElement)roleElement).getText();

                  }

                  The "[]" is called a predicate in xpath and used for referencing the element by its poisiton.
                  http://www.w3schools.com/xpath/xpath_examples.asp see example /bookstore/book[1]/title

                  This should work let us know how it goes.

                  Edited by: 988445 on Mar 15, 2013 5:31 AM
                  • 6. Re: Embedded Java Code - How to retrieve multivalue payload value
                    Kevin Pinsky
                    I have gone this route for now which seems to be working:

                    //Retrieve Requester Roles
                    Object requesterNodeXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails");
                    org.w3c.dom.NodeList childNodes = ((oracle.xml.parser.v2.XMLElement)requesterNodeXMLElem).getChildNodes();
                    CHILDNODES: for (int i=0;i<childNodes.getLength();i++){
                    if (childNodes.item(i).getNodeName().equals("ns2:Role")){
                    if(childNodes.item(i).getFirstChild().getNodeValue().equals(groupApprover)){
                    groupApprover = "false";
                    System.out.println("Bypass");
                    break CHILDNODES;
                    }
                    }
                    }

                    When i get a chance, i will try out your technique.

                    Thanks!
                    -Kevin
                    • 7. Re: Embedded Java Code - How to retrieve multivalue payload value
                      Kevin Pinsky
                      My final code is the following:

                      //Retrieve Requester Roles
                      Object requesterNodeXMLElem = getVariableData("inputVariable", "payload","/ns3:process/ns4:RequesterDetails");
                      org.w3c.dom.NodeList childNodes = ((oracle.xml.parser.v2.XMLElement)requesterNodeXMLElem).getChildrenByTagName("ns2:Role");
                      CHILDNODES: for (int i=0;i<childNodes.getLength();i++){
                      if(childNodes.item(i).getFirstChild().getNodeValue().equals(groupApprover)){
                      groupApprover = "false";
                      System.out.println("Bypass");
                      break CHILDNODES;
                      }
                      }

                      -Kevin
                      • 8. Re: Embedded Java Code - How to retrieve multivalue payload value
                        991448
                        Thanks for sharing the code.
                        So we were missing the function getChildrenByTagName.