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

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
    3316 Posts

    Re: restful API

    ‏2012-02-14T21:34:49Z  
    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

    Re: restful API

    ‏2012-02-14T22:17:26Z  
    • kolban
    • ‏2012-02-14T21:34:49Z
    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
    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
    3316 Posts

    Re: restful API

    ‏2012-02-14T22:26:50Z  
    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.
    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

    Re: restful API

    ‏2012-02-14T22:30:51Z  
    • kolban
    • ‏2012-02-14T22:26:50Z
    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
    that's exactly what I wanted .. thank you Neil ..
  • kolban
    kolban
    3316 Posts

    Re: restful API

    ‏2012-02-14T22:39:01Z  
    that's exactly what I wanted .. thank you Neil ..
    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

    Re: restful API

    ‏2012-02-15T09:15:48Z  
    • kolban
    • ‏2012-02-14T22:39:01Z
    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
    Neil, you're a legend.
    you think this will import into a 7.2 installation?
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: restful API

    ‏2012-02-15T13:07:17Z  
    • kolban
    • ‏2012-02-14T22:39:01Z
    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
    will do .. .thanks a ton ...
  • kolban
    kolban
    3316 Posts

    Re: restful API

    ‏2012-02-15T15:02:33Z  
    Neil, you're a legend.
    you think this will import into a 7.2 installation?
    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

    Re: restful API

    ‏2012-02-15T18:48:32Z  
    will do .. .thanks a ton ...
    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
    3316 Posts

    Re: restful API

    ‏2012-02-15T19:20:54Z  
    my 3rd party rest api url works otherwise, but when accessed from an integration service gives this error :java.net.UnknownHostException:

    any troubleshooting steps ?
    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

    Re: restful API

    ‏2012-02-15T19:42:04Z  
    • kolban
    • ‏2012-02-15T19:20:54Z
    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
    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
    3316 Posts

    Re: restful API

    ‏2012-02-15T19:46:34Z  
    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 ..
    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

    Re: restful API

    ‏2012-02-26T03:52:46Z  
    • kolban
    • ‏2012-02-15T19:46:34Z
    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
    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
    3316 Posts

    Re: restful API

    ‏2012-02-26T05:20:13Z  
    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
    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
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: restful API

    ‏2012-02-26T07:34:35Z  
    • kolban
    • ‏2012-02-26T05:20:13Z
    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
    Yes, thank you
  • JeoffWilks
    JeoffWilks
    29 Posts

    Re: restful API

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