Topic
23 replies Latest Post - ‏2013-07-02T20:52:59Z by SudhakarChellam
SystemAdmin
SystemAdmin
255 Posts
ACCEPTED ANSWER

Pinned topic Parsing/Using data returned from Webservice call

‏2012-10-13T01:03:41Z |
So, I've gone through the wizard and created a web service call to a 3rd party webservice. I get the return xml data back. I can write it to a log like all the examples show. But, how can I actually parse the data to do something with it? Does Impact create some secret DSA that I can use some methods on? Do I use XML functions? I cannot find one single example of using data returned from a webservice in impact other than writing the results to a log file. Any help is appreciated. Impact 6.1 btw.
Updated on 2012-10-16T09:19:38Z at 2012-10-16T09:19:38Z by R@J
  • SystemAdmin
    SystemAdmin
    255 Posts
    ACCEPTED ANSWER

    Re: Parsing/Using data returned from Webservice call

    ‏2012-10-13T05:09:59Z  in response to SystemAdmin
    Hi,

    I hope u r getting response in XML format and you can use parsing logic to obtain the results

    For Example :
    log("About to invoke Web Service call CreateInterfaceRequest ......");
    WSInvokeDLResult = WSInvokeDL(WSService, WSEndPoint, WSMethod, WSParams);
    log("About to invoke Web Service call CreateInterfaceRequest ...: " +WSInvokeDLResult);
    // Printing the Response

    Assume you are getting response in xml like this
    <WSInvokeDLResult>
    <CreateInterfaceRequestResponse>
    <DestObjectID> 12345 </DestObject>
    </CreateInterfaceRequestResponse>
    </WsInvokeDLResult>

    DEST_OBJ_ID = WSInvokeDLResult.CreateInterfaceRequestResponse.DestObjectID;
    Thanks and RegardsSatya
  • SystemAdmin
    SystemAdmin
    255 Posts
    ACCEPTED ANSWER

    Re: Parsing/Using data returned from Webservice call

    ‏2012-10-13T13:42:25Z  in response to SystemAdmin
    Ah ok. So you basically just provide the full path to the element in dot format?

    Can IPL handle multiple elements with the same name, like as an array to loop over?

    Thanks.
  • SystemAdmin
    SystemAdmin
    255 Posts
    ACCEPTED ANSWER

    Re: Parsing/Using data returned from Webservice call

    ‏2012-10-13T20:13:24Z  in response to SystemAdmin
    Ok, still having problems.

    Here's the XML returned:
    <GetAlertHistoryResponse xmlns="http://www.xxxxxxx.com/webservices/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <alertHistoryResponse>
    <status>SUCCESS</status>
    </alertHistoryResponse>
    </GetAlertHistoryResponse>

    I'm trying to get the 'status'. If I do this:
    status = GetAlertHistoryResponse.alertHistoryResponse.status;
    Log("The status is: " +status);

    I get: Parser log: The status is: NULL
    • R@J
      R@J
      39 Posts
      ACCEPTED ANSWER

      Re: Parsing/Using data returned from Webservice call

      ‏2012-10-15T12:05:04Z  in response to SystemAdmin
      Hi silver8ack,

      pls test the following

      outPut = RExtract(WSInvokeDLResult,"<status\\b^>*>(.*?)</status>");
      log("Output --------------->" +outPut );
  • SystemAdmin
    SystemAdmin
    255 Posts
    ACCEPTED ANSWER

    Re: Parsing/Using data returned from Webservice call

    ‏2012-10-15T13:39:40Z  in response to SystemAdmin
    Parser log: Output --------------->
    I don't understand. It seems I can't actually do anything with the results.
    Here's the code(Certain parts replaced to protect privacy):
    
    log(
    "About to invoke Web Service call GetAlertHistory ......");   WSInvokeDLResult = WSInvokeDL(WSService, WSEndPoint, WSMethod, WSParams); log(
    "Web Service call GetAlertHistory return result: " +WSInvokeDLResult); outPut = RExtract(WSInvokeDLResult,
    "<status\\b^>*>(.*?)</status>"); log(
    "Output --------------->" +outPut );
    


    Here's the output:
    
    October 15, 2012 9:36:45 AM EDT[PolicyLogger][XXXX_Alert_History][pool-1-thread-15]Parser log: About to invoke Web Service call GetAlertHistory ...... October 15, 2012 9:36:45 AM EDT[PolicyLogger][XXXX_Alert_History][pool-1-thread-15]Parser log: Web Service call GetAlertHistory 
    
    return result: <GetAlertHistoryResponse xmlns=
    "http://www.url.com/webservices/" xmlns:xsd=
    "http://www.w3.org/2001/XMLSchema" xmlns:soap=
    "http://www.w3.org/2003/05/soap-envelope" xmlns:xsi=
    "http://www.w3.org/2001/XMLSchema-instance"> <alertHistoryResponse> <status>SUCCESS</status> </alertHistoryResponse> </GetAlertHistoryResponse> October 15, 2012 9:36:45 AM EDT[PolicyLogger][XXXX_Alert_History][pool-1-thread-15]Parser log: Output --------------->
    
    • R@J
      R@J
      39 Posts
      ACCEPTED ANSWER

      Re: Parsing/Using data returned from Webservice call

      ‏2012-10-15T15:44:51Z  in response to SystemAdmin
      sorry,missed some braces in the previous post.
      pls try with this---
      output=RExtract(WSInvokeDLResult,"<status\\b^>*>(.*?)</status>");
      log("o/p -------> "+output);

      now this should work.
      let me know if it does not.
      • R@J
        R@J
        39 Posts
        ACCEPTED ANSWER

        Re: Parsing/Using data returned from Webservice call

        ‏2012-10-15T15:51:29Z  in response to R@J
        having problem with characters....
        it was not taking "[" in post.

        put a opening '' before "*>(.*?)</status>"
        output=RExtract(WSInvokeDLResult,"<status\\b ^> *>(.*?)</status>");
        //without any spaces before and after ''.
        log("o/p------->>>>" +output);
        • R@J
          R@J
          39 Posts
          ACCEPTED ANSWER

          Re: Parsing/Using data returned from Webservice call

          ‏2012-10-15T16:00:11Z  in response to R@J
          It's frustrating that I cant delete my own post.
          after 3 consecutive post I hope I 'll be able to end the problem.

          it is not taking third bracket "" without double quotation... :(

          whatever, put one opening third bracket i.e. "" before "*>(.*?)</status>"
          don't put any spaces before or after "" .

          it should not be a problem any more.

          enjoy,
          Raj
          • SystemAdmin
            SystemAdmin
            255 Posts
            ACCEPTED ANSWER

            Re: Parsing/Using data returned from Webservice call

            ‏2012-10-15T16:14:35Z  in response to R@J
            Raj, can you try putting a beginning and ending {code} markup around your code because I'm not sure what it should look like.
            • SystemAdmin
              SystemAdmin
              255 Posts
              ACCEPTED ANSWER

              Re: Parsing/Using data returned from Webservice call

              ‏2012-10-15T16:17:43Z  in response to SystemAdmin
              Raj, cancel that I was able to get it with the following:

              
              output = RExtract(WSInvokeDLResult,
              "<status>(.*?)</status>");
              


              I just don't understand why Impact doesn't work like it's supposed to. What's the selling point of Web Services DSA if I still have to parse all the data? I can do that in Python or anything else much easier.
            • R@J
              R@J
              39 Posts
              ACCEPTED ANSWER

              Re: Parsing/Using data returned from Webservice call

              ‏2012-10-15T16:42:06Z  in response to SystemAdmin
              sorry, dont know how to use
              
              markup. :P
              

              output=RExtract(WSInvokeDLResult,"<status\\b^>*>(.*?)</status>");
              log("o/p ----> " +output);
              {code}

              donno whether this time it 'll take the correct value or not.

              whatever,
              opening third bracket after the following sub-string "<status\\b"
              closing third bracket before the sub-string "*>(.*?)</status>");"

              which means,
              <status\\b OpeningThirdBracket ^> ClosingThirdBracket *>(.*?)</status>

              without any spaces.

              if it messes up this time too,
              then I would like to suggest you to go through the policy reference guide of netcool/impact 5.1
              u can find function RExtractAll in the guide.
              read and try the example 2 (both IPL and Java Script).
              in your case,
              u ll have to replace RExtractAll(expression with RExtract(WSInvokeDLResult
              and
              replace plantId with status
              hope it 'll help.

              regards,
              Raj
              • R@J
                R@J
                39 Posts
                ACCEPTED ANSWER

                Re: Parsing/Using data returned from Webservice call

                ‏2012-10-15T16:45:36Z  in response to R@J
                o ho
                finally got it. lol lol :P

                
                output = RExtract(WSInvokeDLResult,
                "<status\\b[^>]*>(.*?)</status>"); log(
                "o/p---"+output);
                
  • SystemAdmin
    SystemAdmin
    255 Posts
    ACCEPTED ANSWER

    Re: Parsing/Using data returned from Webservice call

    ‏2012-10-15T20:10:16Z  in response to SystemAdmin
    So this is ok if I have one single element that I need to get.

    However, in real life, we usually need much more. This doesn't help me at all really. I need to be able to iterate of the contents of an XML response. The 'status' element actually occurs several times and with this method, it will only pick up the last one.

    Any other ideas of how to parse the data and take action on it? Otherwise I'm going to management and recommending we DO NOT buy any additional licenses for Impact. It seems to be a roadblock to actually getting things done.
    • SystemAdmin
      SystemAdmin
      255 Posts
      ACCEPTED ANSWER

      Re: Parsing/Using data returned from Webservice call

      ‏2012-10-15T20:56:00Z  in response to SystemAdmin
      Ugh, I think I figured out what I have to do... I'll report back tomorrow. I have to create the Objects first using WSNewObject it seems. I tried quickly, but didn't have any luck... gonna look into a but more.
      • R@J
        R@J
        39 Posts
        ACCEPTED ANSWER

        Re: Parsing/Using data returned from Webservice call

        ‏2012-10-16T09:19:38Z  in response to SystemAdmin
        Hi silver8ack ,
        try to use RExtractAll to fetch multiple data at a time.

        You can have the reference in the below link ---

        http://publib.boulder.ibm.com/infocenter/tivihelp/v8r1/index.jsp?topic=%2Fcom.ibm.netcoolimpact.doc6.1%2Fpolicy%2Fimpr_parser_rextractall_c.html
      • RayPatil
        RayPatil
        4 Posts
        ACCEPTED ANSWER

        Re: Parsing/Using data returned from Webservice call

        ‏2013-06-05T05:40:54Z  in response to SystemAdmin

        Hi

        It would be great if you let us know how you finally managed to handle the webservice data in IMPACT!

        How to use "WSNewObject" to fetch xml data in impact policy or How to use RExtract/RExtractAll ???

        Please reply ASAP, this is roadblock to my release!

         

        Regards,

        Ray

        • OskarZinger
          OskarZinger
          45 Posts
          ACCEPTED ANSWER

          Re: Parsing/Using data returned from Webservice call

          ‏2013-06-06T17:51:10Z  in response to RayPatil

          Hi Ray,

           

          WSNewObject is documented here.

          RExtract is documented here.

          RExtractAll is documented here.

          You can also look at using GetByXPath which is documented here. It can help you deal with XML.

           

          Hope this helps,

          Oskar

          • RayPatil
            RayPatil
            4 Posts
            ACCEPTED ANSWER

            Re: Parsing/Using data returned from Webservice call

            ‏2013-06-07T07:59:20Z  in response to OskarZinger

            Thank u Oskar for your quick response.

            I am looking to parse and use the XML response coming from webservice. Few lines of my IPL code looks as below and using webservice method.

            CalculateServiceImpactDocument=WSNewObject("<***>.CalculateServiceImpactDocument");
            WSInvokeDLResult = WSInvokeDL(WSService, WSEndPoint, WSMethod, WSParams);
            output = RExtractAll(WSInvokeDLResult,"<regular expression>");

            Instead of RExtract/RExtractall function can I use any other way like making the response as an context/object and fetch the data with . notation? Please share some examples...

             

            please help asap.

            Regards,

            Ray

             


             

            • SudhakarChellam
              SudhakarChellam
              19 Posts
              ACCEPTED ANSWER

              Re: Parsing/Using data returned from Webservice call

              ‏2013-06-09T18:56:56Z  in response to RayPatil

              Hello,

              You have couple o options

              1.  GetByXPath

              2.  Processing the data as is..

              Here is how you will handle the results...

              WSInvokeDLResult.CalculateServiceImpactDocumentResponse.<VariableName>.  

              You could access it directly like that.

               

              If you are using Impact 6.1.1 , we do have a helper tool that will show you the policy format on how to process the request.

               

              Here is the link ..

               

              https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Tivoli%20Netcool%20Impact/page/Netcool%20Impact%206.1.1

              Please read the following pacakge.

              Helper functionality to identify Netcool/Impact policy syntax for retrieving web service response data

              Thanks and Regards

              Sudhakar

               

              • RayPatil
                RayPatil
                4 Posts
                ACCEPTED ANSWER

                Re: Parsing/Using data returned from Webservice call

                ‏2013-06-26T16:01:43Z  in response to SudhakarChellam

                Hi Sudhakar/Oscar,

                I code looks like this:

                WSInvokeDLResult = WSInvokeDL(WSService, WSEndPoint, WSMethod, WSParams);

                log(WSInvokeDLResult); >> will print the xml as attached.

                log(WSInvokeDLResult.CalculateServiceImpactResponse); >> will also print the next level output.

                log(WSInvokeDLResult.CalculateServiceImpactResponse.RESPONSE); >> NULL !!!!!
                 

                I am handling the XML response in impact policy to fetch the individual item values, But result is NULL!! I want to drill down to last item to fetch the value in it.

                Please find attached soapui-XML response format and help me. Please do the needful

                Attachments

                • SudhakarChellam
                  SudhakarChellam
                  19 Posts
                  ACCEPTED ANSWER

                  Re: Parsing/Using data returned from Webservice call

                  ‏2013-06-26T18:11:43Z  in response to RayPatil

                  Can you please try Response ? instead of RESPONSE.

                  We may have to look at the jar file , do not post the jar file here..

                   

                  Thanks and Regards

                  Sudhakar

                  • RayPatil
                    RayPatil
                    4 Posts
                    ACCEPTED ANSWER

                    Re: Parsing/Using data returned from Webservice call

                    ‏2013-06-27T06:03:54Z  in response to SudhakarChellam

                    Hi Sudhakar,

                    Thank you verymuch for your quick response. I tried with Response instead of RESPONSE: No method error!

                    Caused by: com.micromuse.common.parser.PolicyException: Unhandled Exception: java.lang.NoSuchMethodException in policy: Ray_WS_Test1 at line: 41 .com.micromuse.common.parser.internal.core.DefaultExceptionHandler.handle(DefaultExceptionHandler.java:77)

                     

                    please find the log which shows the response coming from webservice (stored in return variable WSInvokeDLResult).

                    RESPONSE doesn't reply any value!

                    log(WSInvokeDLResult); >> will print the xml as attached.

                    log(WSInvokeDLResult.CalculateServiceImpactResponse); >> will also print the next level output.

                    log(WSInvokeDLResult.CalculateServiceImpactResponse.RESPONSE); >> NULL !!!!!

                     

                    Regards,

                    Ray

                     

                     

                     

                     

                     

                     

                    Attachments

                    • SudhakarChellam
                      SudhakarChellam
                      19 Posts
                      ACCEPTED ANSWER

                      Re: Parsing/Using data returned from Webservice call

                      ‏2013-07-02T20:52:59Z  in response to RayPatil

                      Hi,

                      Does the WSDL contains the Response as one of the output element ? If its defined as xsd:any then you will not find the Response or RESPONSE object.

                      In that scenario you have the option of using GetByXPath if you are using 6.1 Impact.

                       

                      Thanks and Regards

                      Sudhakar