Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2011-12-02T11:07:01Z by SystemAdmin
SLONGO
SLONGO
3 Posts
ACCEPTED ANSWER

Pinned topic Configuring HTTP Post activity for JSON REST web services

‏2011-08-12T22:03:02Z |
I have a project that requires the use of RESTful web services to query Item data from Firepond. The Firepond data can only be accessed by using an HTTP activity configured as a GET using a URL similar to the following:
GET https://od1.fpx.com/rs/1/cpaas/configs/query?cql=select+SKU.ID%2C+SKU.ExtendedDescriptionList%2C+SKU.ProdPostingCode%2C+SKU.ProductCode%2C+SKU.UOM+from+SKU+where+DiffCode+%3C%3E+%27%27+

I've set the HTTP Header Content-Type = application/json and the charset=utf-8 but each time I try to validate the activity, I get an HTTP 404 error - Page not found. I understand that there are 2 steps that must be configured prior to running the query: Login and Configuration

Login is POST https://od1.fpx.com/rs/1/cpq/login
Configuration is POST https://sbx.fpx.com/rs/1/cpaas/configs?ds_guid=70804111e8d0c430:117fb16e:11c9f4e24d0:-7f21%7C0

I'm not sure if I have to put the full URL in the URI and the Method in the Method parameter or if I can configure the entire statement as
"POST https://od1.fpx.com/rs/1/cpq/login" in the URI. I've used other HTTP Headers for the Username and Password for the login activity but each attempt at verifying the activity has failed with a 404 error. I set up the HTTP endpoint as a remote server by entering the IP Address using the default of port 80. I can connect to the endpoint by clicking the "Test Connection" button but I can't get any of the HTTP activities to validate. If anyone has used REST web services in Cast Iron, I would welcome any insight you may have. Feel free to contact me directly at steve.longo@cloudtrigger.com. Thanks.

Steve
Updated on 2011-12-02T11:07:01Z at 2011-12-02T11:07:01Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1250 Posts
    ACCEPTED ANSWER

    Re: Configuring HTTP Post activity for JSON REST web services

    ‏2011-08-23T13:43:53Z  in response to SLONGO
    Hi Steve,
    Since you are mentioning that this is a two-steps process (first authentication and then call of the web service), you may want to have a look at the TIPs where you'll find good example of how to use an authentication token in subsequent queries.
    In your HTTP activity, I would do the following:
    URL: rs/1/cpaas/configs/query?cql=select+SKU.ID%2C+SKU.ExtendedDescriptionList%2C+SKU.ProdPostingCode%2C+SKU.ProductCode%2C+SKU.UOM+from+SKU+where+DiffCode+%3C%3E+%27%27+
    in the map input activity: add you authentication token and set the method to GET.

    Regards,
    Magali
    • SLONGO
      SLONGO
      3 Posts
      ACCEPTED ANSWER

      Re: Configuring HTTP Post activity for JSON REST web services

      ‏2011-08-24T18:00:59Z  in response to SystemAdmin
      Thanks. I will give it a try. I have installed Fiddler to monitor the HTTP traffic being sent by Cast Iron and my main problem is configuring the HTTP endpoint to be an HTTPS endpoint. I configured the server IP and used Port 443 but couldn't connect once I made that change. I selected the HTTPS radio button but once again, could not connect. It seems to connect fine using HTTP and Port 80. The Firepond endpoint only support HTTPS so I will need to correct the endpoint configuration prior to attempting the test you suggested. I will also search for TIPs that use Authentication tokens. I appreciate the suggestions. Thanks.
      Steve
      • SLONGO
        SLONGO
        3 Posts
        ACCEPTED ANSWER

        Re: Configuring HTTP Post activity for JSON REST web services

        ‏2011-09-14T22:23:56Z  in response to SLONGO
        I configured the Firepond Endpoint to be a URL instead of a Server IP (od1.fpx.com) port 443. In the HTTP Post activities, I clicked on the menu Map, Show Optional Parameters. In the Checklist at the left, I set the "Configure" link to have the same URL as the URI (/rs/1/cpq/login). I then configured the Optional Parameters for the FPX Login activity:

        URI: /rs/1/cpq/login
        Method: POST
        HTTPHeaders:
        Key: Content-Type
        Value: application/x-www-form-urlencoded
        Key: Connection
        Value: Keep-alive

        Body = un=[firepond_user_name}&pw={firepond_pw} which were actually hard-coded with the values then turned into configuration properties.

        The trick to get the endpoint to respond correctly came by configuring the httpConnParameters:
        @timeout = set at a default of 300
        @domain = set at a default of www.fpx.com
        host = od1.fpx.com
        port = 443
        isSecure = true

        If you have set up Fiddler like I did to monitor the traffic, Fiddler automatically sets up a proxy server at 127.0.0.1 on the local machine. I couldn't get Fiddler to work unless the PC was part of a domain. In the Proxy parameters, I entered the following:

        @domain = full domain of the computer. In this case it was corp.broadsoft.com
        Host = 127.0.0.1
        Port = 8888
        Username = Use windows authentication username here for the machine you installed Fiddler on which is most like the PC you're working on
        Password = Use window authentication password here

        Filling out the Proxy field channels all of your HTTP/HTTPS calls through Fiddler where the requests and response can be viewed in RAW xml. This provided me with a view of exactly what was being sent to Firepond. The login activity proved to be the easiest REST call to make to Firepond. I was able to filter the Response HTTP Headers and store the Cookies (JSESSIONID=nTWfZBbyPBGYR7TemMTbEA__; Path=/; Secure; HttpOnly) to a variable which could later be passed in as a value in the HTTP Post activities.

        It took quite many attempts to set the configuration and to get the select statement to work for Firepond in HTTPS. Here's a summary of how I configured the HTTP Post activities for Setting the Configuration and running the Select statement. Notice there are subtle differences in the values you provide for a URL vs a URI and what is being passed in as the body of the request:

        Configuration of HTTP Post Map Inputs:

        Configure link in checklist: /rs/1/cpaas/configs?ds_guid=70804111e8d0c430:117fb16e:11c9f4e24d0:-7f21%7C0%20 - this is the fully escaped URL value

        URI: /rs/1/cpaas/configs?ds_guid=70804111e8d0c430:117fb16e:11c9f4e24d0:-7f21|0 - as you notice the URI did not require the escaped values (there is a space after the |0 at the end of the string that is represented by %20 in the URL
        Method: GET
        HTTPHeaders:
        Key: Connection
        Value: Keep-alive
        Key: Content-Type
        Value: application/x-www-form-urlencoded
        Key: Cookie
        Value: passed in by mapping a string variable that contained the cookie value: $Version=0; JSESSIONID=nTWfZBbyPBGYR7TemMTbEA__; Path=/; Secure; HttpOnly. NOTE: I had to prepend the "$Version=0; " before the cookie value for it to work properly
        Body: 70804111e8d0c430:117fb16e:11c9f4e24d0:-7f21|0 - I passed in only the GUID of the configuration
        httpConnParameters
        Same as Login activity

        SELECT statement:

        Configure link in the checklist: /rs/1/cpaas/configs/query?cql=select+SKU.ID,SKU.ExtendedDescriptionList,SKU.ProdPostingCode,SKU.ProductCode,SKU.UOM,SKU.UnitQuantity,SKU.DescriptionList,SKU.InactiveSKU+from+SKU+WHERE+SKU.ExtendedDescriptionList+is+not+null
        URI: blank
        Method: GET
        HTTPHeaders:
        Key: Connection
        Value: Keep-alive
        Key: Content-Type
        Value: application/x-www-form-urlencoded
        Key: Cookie
        Value: passed in by mapping a string variable that contained the cookie value
        Body: select+SKU.ID,REPLACE(SKU.ExtendedDescriptionList,',',' '),SKU.ProdPostingCode,SKU.ProductCode,SKU.UOM,SKU.UnitQuantity, SKU.DescriptionList,SKU.InactiveSKU+from+SKU+WHERE+SKU.ExtendedDescriptionList+is+not+null - this is unescaped version of the select statement.
        htttpConnParameters
        Same as Login activity

        The query results come back in a perfect JavaScript object with column headings and rows but the format is one giant string that looked like this:
        {"columns":,"success":true,"rows":[,,,,,,,,,,,,["80-BL6052","BW Platform (AS,NS,MS) Software ......

        In between the square brackets [ ] is all of the column values expressed as an array. The trick was how to get the data into true XML format so it could used and manipulated by Cast Iron.
        . To reformat this string, I could not use the eval() function in JavaScript as Firepond was already returning the data in a JavaScript object. I created a number of functions to replace certain characters to create beginning and end tags:

        This function replaces the internal double quotes with pipes so I could later parse the data easier and it created beginning and end tags moving the string data closer to an XML string representation.
        instring=instring+'';
        var len = instring.length;
        if(len>0)
        var outvalue = instring.replace(/\"\,\"/g,'|').replace(/\"/g,'').replace(/[/g, '<data>"').replace(/]/g, '"</data>').replace(/\&/g, '&');
        else
        var outvalue = instring;
        return outvalue;


        This function removes any line feeds or cr/lf embedded in the string data and replaces the , at the end of each array with a carriage return line feed so the sting moved closer to true XML string format
        instring=instring+'';
        var len = instring.length;
        if(len>0)
        var outvalue = instring.replace(/\n/g,'').replace(/\r\n/g,'').replace(/\>\,\</g, '>\r\n<');
        else
        var outvalue = instring;
        return outvalue;

        I then concatenated beginning and end Item and rows tags with new lines after each to create a true xml structure. The XML structure I was moving toward had the following schema:

        <Item>
        <rows>data......

        </rows>
        </Item>
        I then used Read XML to read the XML string into XML - however, we noticed that some of the column data in Firepond was coming back with embedded new line and or carriage returns. I mapped the resulting XML variable to another XML variabble that had a slightly different schema:
        <Item>
        <row>
        <data> data....
        Sounds strange but it worked to clean up the XML. Once I mapped it to the new XML variable, I then write it to a Flat File structure of the same schema to create a string. Then using the Read Flat File activity, I read the string back into true XML. It was only at this point that the data was in a usable format - all of the columns represented by a single row (essentially an array of all the column values). From there it was easy to use a JavaScript split function to split on the pipes and map the resulting value by array position to it's corresponding column in the XML variable.
        • SystemAdmin
          SystemAdmin
          1250 Posts
          ACCEPTED ANSWER

          Re: Configuring HTTP Post activity for JSON REST web services

          ‏2011-12-02T10:44:22Z  in response to SLONGO
          Hi, I am not able to monitor SOAP messages through Fiddler. Is there any config settings needed on Cast Iron/Fiddler ?
          I have my castiron studio in a separate network and I am accessing the Microsoft CRM Webservice from the remote server which is in a
          different network through a VPN connection.

          Any suggestions please to monitor the SOAP messages ?

          Thanks.
          • SystemAdmin
            SystemAdmin
            1250 Posts
            ACCEPTED ANSWER

            Re: Configuring HTTP Post activity for JSON REST web services

            ‏2011-12-02T11:07:01Z  in response to SystemAdmin
            Hi,

            I found this, it's a bit old but which might be useful anyway: http://blogs.msdn.com/b/commerce/archive/2006/12/03/using-fiddler-to-capture-soap-messages-between-the-cs2007-web-services-and-clients.aspx

            Regards,
            Magali