Wednesday, October 12, 2011

Restful Service in webMethods

This is another of those things that should be easy right?  Well, it is once you know what to do.

++++ Added note ++++
After I figured out how to do this indirectly, I found the actual Webmethods REST users guide.  It is a more complete way to implement RESTful services. This only works in version 8.2 however.

See http://documentation.softwareag.com/webmethods/wmsuites/wmsuite8-2_ga/Integration_Server/8-2-SP1_REST_Developers_Guide.pdf
++++++++++++

I had a rest service call coming into the Integration Server with an HTTP Post request to http://<server>:5555/invoke/TestForKev.esla.pub/event with a type of application/xml in UTF-8.

  1. So I wrote a flow service in TestForKev/esla/pub called event.  
  2. I created an input parameter of contentStream with an object type.
  3. I called pub.io:streamToString to convert the contentStream to a string
  4. I called pub.xml:xmlStringToXMLNode to create the XML node.
  5. Then I called pub.xml:xmlNodeToDocument to finally convert to a webmethods document.

It should look something like this.



Now you have a webmethods document from your rest service interface.


URL Parameters

If you need to take a rest service input that uses URL parameters, you can still get to them.  Say you have a url like http://<server>:5555/invoke/TestForKev.esla.pub/event_change/98765 where 98765 is the event_id.  


Just write the service as above, but add in a call to pub.flow:getTransportInfo.  The requestURL returned will contain the service name and the parameters at the end of the url, so you can parse them out.   


<value name="requestUrl">/invoke/TestForKev.esla.pub/event_change/98765</value>

Response Values

Found out how to send the http status and message back to the caller.  Use pub.flow:setResponseCode to explicitly set the response values.  Otherwise defaults are chosen for you.

5 comments:

  1. Hi Kevin,

    First of all, thanks for all the information in your blog. It is very helpful !

    I've a little question about webmethods.

    What are the relevant configuration files? and there default place /opt/...

    I start with webmethods and i've not find this information yet.

    Thks for your help and blog.

    ReplyDelete
  2. Hi Kevin,

    This works in Integration Server version 7.1.3 as well. Much thanks for your findings!

    ReplyDelete
  3. Hi Kevin
    Do you have information about how to consume REST in webMethods 7.1.2

    ReplyDelete
  4. Hi Kevin,
    Could you pls explain how to create a URL alais for RESTful services ? For ex, we want to implement a reverse proxy gateway before passing this req on to the IS.

    ReplyDelete
  5. Thank you for posting this - this works in version 9.8 as well and I wanted to thank you for it.

    ReplyDelete