5 Replies Latest reply: Jan 1, 2013 9:37 PM by vladodias RSS

    How to count the number of parameters from  consumer(ex.soapUI)?

    981848
      Hi,

      I am a beginner is OSB. I am working on a task that has to count the no.of .parameters from the consumer(Soap UI) in the proxy service. And if the parameter is lesser than 4 an error has to be thrown else it should be routed to another business service. Anyone worked on such scenario before?
        • 1. Re: How to count the number of parameters from  consumer(ex.soapUI)?
          AbhishekJ
          What is your input XML message structure?
          You can use count() function to check the count of any XMl nodes.
          For ex. if your request structure as defined in WSDL is this:
          <Request>
          <a>1</a>
          <b>1</b>
          <c>1</c>
          </Request>
          Then your $body variable will have content like below at the starting point of your Proxy message flow:
          <soap-env:Body>
          <Request>
          <a>1</a>
          <b>1</b>
          <c>1</c>
          </Request>
          </soap-env:Body>
          and you cant put a condition like this in the If then Else action condition builder:

          count($body/Request/*) < 4
          • 2. Re: How to count the number of parameters from  consumer(ex.soapUI)?
            981848
            Thanks for the quick reply. I will explain the approach i followed, not sure whether it is correct or not.

            I haven't used any WSDL fiile , instead i used the xquery file.

            In the proxy service assign node i tried to catch the parameters using $inbound/ctx:transport/ctx:request/http:query-string/text() and assigned it to a variable.

            I have configured the assign node with the xquery file, here extracted the parameters using.

            declare function xf:parseRelativeURI($string1 as xs:string)
            as element(ns0:LNIGeneratorRequest) {
            <ns0:LNIGeneratorRequest>
                      <ns0:numberofStampers>{xf:getParameter($string1,"numberofstampers=")}</ns0:numberofStampers>
                           <ns0:partitionId> {xf:getParameter($string1,"partitionid=")}</ns0:partitionId>
                           <ns0:type> {xf:getParameter($string1,"type=")}</ns0:type>
                           <ns0:clientInfo> {xf:getParameter($string1,"clientinfo=")}</ns0:clientInfo>
                      </ns0:LNIGeneratorRequest>
            };


            Then in the replace node i had replaced it with the "body" variable.

            All the conditions i had place in the xquery file. like below

            declare function xf:getParameterCount() as xs:integer{
            let $queryParams := xf:parseRelativeURI($string1)
            let $countParams := fn:count($queryParams/child::*)
            let $error := 0
            let $success := 1
            return if($countParams<10)
            then $error
            else $success
            };

            Thanks in Advance
            • 3. Re: How to count the number of parameters from  consumer(ex.soapUI)?
              AbhishekJ
              Can you please post the definition of function xf:getParameter() as well.
              Seems like the way you have written the below two functions, <LNIGeneratorRequest> will always have fixed number of child elements. You will need to create the child elements only if the parameter data is present:
              SOmething like this:

              if(string-length(xf:getParameter($string1,"numberofstampers=")) > 0)
              then
              <ns0:numberofStampers>{xf:getParameter($string1,"numberofstampers=")}</ns0:numberofStampers>
              else ()

              Only then the number of child elements in LNIGeneratorRequest will give you number of parameters actually present.
              • 4. Re: How to count the number of parameters from  consumer(ex.soapUI)?
                981848
                please find below the xf:getParameter method

                declare function xf:getParameter($string1 as xs:string,$string2 as xs:string)
                as xs:string {
                     
                let $param1:= fn:substring-after($string1,$string2)
                     return if((fn:matches($param1,'&amp;')))
                     then fn:substring-before($param1,'&amp;')
                else $param1
                };

                $string1 value comes from the request URL after "?". The entire value is retrieved as a single string and from this the parameter values are extracted.

                For your information, i have declared the transport of the proxy as "any xml service".

                Thanks,
                Sathish.
                • 5. Re: How to count the number of parameters from  consumer(ex.soapUI)?
                  vladodias
                  Have a look at this...
                  https://blogs.oracle.com/jeffdavies/entry/enhanced_rest_support_in_oracl

                  Cheers,
                  Vlad