Topic
16 replies Latest Post - ‏2012-02-27T14:44:01Z by JeoffWilks
SystemAdmin
SystemAdmin
7615 Posts
ACCEPTED ANSWER

Pinned topic restful API

‏2012-02-14T21:29:22Z |
How to connect to a restful web service API having basic authentication in 7.5.1
Updated on 2012-02-27T14:44:01Z at 2012-02-27T14:44:01Z by JeoffWilks
  • kolban
    kolban
    3314 Posts
    ACCEPTED ANSWER

    Re: restful API

    ‏2012-02-14T21:34:49Z  in response to SystemAdmin
    Hi there AG1572,
    I'm tempted to suggest downloading a set of notes I made available in PDF format ... see:

    https://www.ibm.com/developerworks/forums/thread.jspa?threadID=403721

    An example of Basic Authentication of REST service calls to IBPM can be found on page 430 (February 2012 edition). I am also assuming you are calling from Java.

    Neil
    • SystemAdmin
      SystemAdmin
      7615 Posts
      ACCEPTED ANSWER

      Re: restful API

      ‏2012-02-14T22:17:26Z  in response to kolban
      No, not from java. I have a service (with GET method)outside TW exposed as rest api url with basic authentication. How can I access that from TW.
      • kolban
        kolban
        3314 Posts
        ACCEPTED ANSWER

        Re: restful API

        ‏2012-02-14T22:26:50Z  in response to SystemAdmin
        Aha ... if I understand you, you have a 3rd party app (not an IBM thing) which exposes itself as a REST exposed service and you wish to invoke that from within the IBM BPM environment?

        By and large, I would look to using the IBM BPM Advanced edition of the product for integrations with external systems. If you choose not to use that capability ....

        Recently I had to call an external REST exposed service from IBM BPM Standard. I looked at the System Data provided toolkit but could not find what I was looking for. In that instance, I wrote my own wrapper to make the REST caller that supported GET, POST and PUT as well as supported Basic Auth security.

        Bizarrely, just yesterday, I thought to release this as-is to anyone who wanted it. See:

        http://www.neilkolban.com/IBM/KolbanTK.html

        Is this something like what you are looking for?

        Neil
        • SystemAdmin
          SystemAdmin
          7615 Posts
          ACCEPTED ANSWER

          Re: restful API

          ‏2012-02-14T22:30:51Z  in response to kolban
          that's exactly what I wanted .. thank you Neil ..
          • kolban
            kolban
            3314 Posts
            ACCEPTED ANSWER

            Re: restful API

            ‏2012-02-14T22:39:01Z  in response to SystemAdmin
            Excellent ... I love it when timing comes together. The complete source code of the toolkit is provided with the package and you must understand that there is no support nor warranty on this code. However, if you post to the forum with any questions or comments, I'll sure try as hard as I can to address ... but the bottom line is that you should understand the code fully and consider it as though you had written it yourself.

            If you should find problems, please feel free to post them as well so that others may benefit or, as time and inclination permits, I'll try and resolve for an unspecified future release.

            Neil
            • SystemAdmin
              SystemAdmin
              7615 Posts
              ACCEPTED ANSWER

              Re: restful API

              ‏2012-02-15T09:15:48Z  in response to kolban
              Neil, you're a legend.
              you think this will import into a 7.2 installation?
              • kolban
                kolban
                3314 Posts
                ACCEPTED ANSWER

                Re: restful API

                ‏2012-02-15T15:02:33Z  in response to SystemAdmin
                J0n35y,
                As you guessed, I built it against the latest and greatest version of the product (7.5.1 as of writing). I doubt that a 7.5.1 TWX file will import into a back-level version of the product (but that is indeed a good question ... I wonder what happens if we try). The toolkit has no dependencies on anything in the product that shouldn't already have been there in 7.2.

                So ... I'd suggest downloading the toolkit and attempting to install it in your Process Center. It will either import or not. If it does, end of job.

                If it doesn't....

                Our options are more limited but do-able. At this stage, the toolkit is trivial (one service) so all you would really need to do is download the Eclipse project, build the JAR and then import that JAR into your own toolkit and provide your own service wrapper.

                Neil
            • SystemAdmin
              SystemAdmin
              7615 Posts
              ACCEPTED ANSWER

              Re: restful API

              ‏2012-02-15T13:07:17Z  in response to kolban
              will do .. .thanks a ton ...
              • SystemAdmin
                SystemAdmin
                7615 Posts
                ACCEPTED ANSWER

                Re: restful API

                ‏2012-02-15T18:48:32Z  in response to SystemAdmin
                my 3rd party rest api url works otherwise, but when accessed from an integration service gives this error :java.net.UnknownHostException:

                any troubleshooting steps ?
                • kolban
                  kolban
                  3314 Posts
                  ACCEPTED ANSWER

                  Re: restful API

                  ‏2012-02-15T19:20:54Z  in response to SystemAdmin
                  AG1572,
                  Help is at hand :-)

                  Looking at the code and how the URL is mapped, the following is the code in Java

                  URL url = new URL(urlString);
                  HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();

                  This tells me that the URL value should be a "proper" URL string ... eg ...

                  http://myhost:myport/myocation?myoption=value

                  (note ... not all of the above are necessary)

                  What did you define in the call to the RESTRequest for the "URL" parameter?

                  Neil
                  • SystemAdmin
                    SystemAdmin
                    7615 Posts
                    ACCEPTED ANSWER

                    Re: restful API

                    ‏2012-02-15T19:42:04Z  in response to kolban
                    URL input would be my rest
                    url : "http://<hostname>:<port>/WIP_Inventory_WS/restful/deliverables/reporting/"

                    when i access this url directly from the browser on my computer , it returns the xml output

                    I have 7.5.1 installed on a virtual server from where :
                    ping <hostname> doesn't reach back, but ping <ip of the host> is returned successfully.

                    do you think this might be an issue .. thank u again ..
                    • kolban
                      kolban
                      3314 Posts
                      ACCEPTED ANSWER

                      Re: restful API

                      ‏2012-02-15T19:46:34Z  in response to SystemAdmin
                      AG1572,
                      Oh heck yeah... that will be your problem.

                      Let me be clear. If your browser runs a service on IBPM and that service wishes to make a REST call ... then the REST call will be made not from the browser but from the runtime environment where IBPM is installed. If the target of the REST request is <hostname> and the environment on which IBPM is installed can not resolve <hostname> at the TCP/IP level then you will get exactly the error described in your previous post.

                      Your solutions are:

                      1. Add <hostname> as a resolvable entity on the machine where IBPM is installed. For example, edit the "hosts" file or change your DNS lookup configuration.
                      2. Use the actual IP address of the target server on which the REST service is installed as the target of your REST request.

                      Neil
                      • SystemAdmin
                        SystemAdmin
                        7615 Posts
                        ACCEPTED ANSWER

                        Re: restful API

                        ‏2012-02-26T03:52:46Z  in response to kolban
                        Hey Neil,
                        I am using your RESTRequest service in the toolkit, but my 3rd party REST would return a xml element rather than a string. So, how can I avoid the double work of changing the string from RESTRequest back to xml ?

                        Thank you
                        • kolban
                          kolban
                          3314 Posts
                          ACCEPTED ANSWER

                          Re: restful API

                          ‏2012-02-26T05:20:13Z  in response to SystemAdmin
                          Hi there AG1572,
                          A REST request (any REST request) is going to send back a string of bytes. It is up to the consumer of the REST request how that data is interpreted. Commonly the string returned from a REST request is either JSON encoded or XML encoded. If the data you are getting back from your 3rd party REST service provider is XML encoded then when you get the string back, you will want to parse it as XML to get to the element content within.

                          My notes seem to show that within the runtime, we can use

                          var myDocument = new tw.object.XMLDocument(xmlString)

                          to create/parse an XML string into a DOM document.

                          Let me know if this is what you needed.

                          Neil
  • JeoffWilks
    JeoffWilks
    29 Posts
    ACCEPTED ANSWER

    Re: restful API

    ‏2012-02-27T14:44:01Z  in response to SystemAdmin
    Also see http://wiki.lombardi.com/display/commwiki/REST+Web+Services