Visual Builder

Get Involved. Join the Conversation.

Topic

    John Graves
    Service call in Groovy ScriptAnswered
    Topic posted November 26, 2018 by John GravesSilver Trophy: 7,500+ Points, tagged Business Objects, Custom Code, Groovy, REST, Services 
    318 Views, 3 Comments
    Title:
    Service call in Groovy Script
    Summary:
    Having issues calling a service call in a groovy script.
    Content:

    There was a nice blog showing how to do this in an old version:

    https://blogs.oracle.com/pdit-cas/how-to-call-any-rest-api-from-vbcs-groovy-code

    But this doesn't seem to work anymore.

    I've defined a REST service  with one POST endpoint. 

    I try calling it based on the service name:

    def VBSocketUpdateService = newService("VBSocketUpdate")
    def callBody = '{ "label": "UpdateSampleData" }'
    def callResponse = VBSocketUpdateService.post(callBody)
    

    But I get an error:

    Exception in expression "SampleData" trigger "BeforeUpdate_Rule_0" : oracle.adf.model.connection.rest.exception.RestConnectionException Service not found
    at "SampleData" trigger "BeforeUpdate_Rule_0" line 11

    In the BLOG entry, there was no separate endpoint config.  How does the groovy script know what endpoint to use?

    I tried VBSocketUpdate.postNotify and VBSocketUpdate/postNotify, but both give me a "oracle.jbo.InvalidObjNameException Object name" error.

    Any help?

    Thanks.

    -John

    Version:
    18.3.3
    Image:
    Code Snippet:

    Best Comment

    John Graves

    Special thanks to Aminur Rashid and Anand Kalyanasundaram from engineering who pointed out that the operation on my method call needed to match the service ID of the operation.  The ".post" was failing because that wasn't a standard ".post" operation on all objects, it needed to be a service ID.  So, this is the code that works:

    def VBSocketUpdateService = newService("VBSocketUpdate")
    def callBody = '{ "label": "UpdateSampleData" }'
    def callResponse = VBSocketUpdateService.postNotify(callBody)
    

    The "postNotify" was the name of my service; which pointed to the operation "/notify"

    Thanks again!

    Comment

     

    • Christopher Maggiulli

      Are you familiar with grape? I have no tried this but possibly you could add the following dependencies then use http-builder?

       

      @Grapes([
        @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'),
        @Grab(group='org.codehaus.groovy', module='groovy-json', version='2.0.1')
       

      ])

       

       

       

       

      If that doesn't work and the service is a POST you could adapt the following code to groovy https://technology.amis.nl/2015/05/12/make-http-post-request-from-java-se-no-frills-no-libraries-just-plain-java/

      • John Graves

        Thanks for the reply Christopher.  I started to look at Grape, and it seemed to be working, but then I found a solution using the connector.

    • John Graves

      Special thanks to Aminur Rashid and Anand Kalyanasundaram from engineering who pointed out that the operation on my method call needed to match the service ID of the operation.  The ".post" was failing because that wasn't a standard ".post" operation on all objects, it needed to be a service ID.  So, this is the code that works:

      def VBSocketUpdateService = newService("VBSocketUpdate")
      def callBody = '{ "label": "UpdateSampleData" }'
      def callResponse = VBSocketUpdateService.postNotify(callBody)
      

      The "postNotify" was the name of my service; which pointed to the operation "/notify"

      Thanks again!