Uploaded image for project: 'OpenIDM'
  1. OpenIDM
  2. OPENIDM-14548

External REST: Calling endpoints which return a JSON array throws error

    XMLWordPrintable

    Details

    • Target Version/s:
    • Verified Version/s:
    • Story Points:
      3
    • Sprint:
      2020.05 - IDM, 2020.06 - IDM, 2020.07 - IDM
    • Support Ticket IDs:

      Description

      When using openidm.action() to call a remote endpoint which returns an array of JSON objects, the following error is returned:

      {"code":500,"reason":"Internal Server Error","message":"/: List index out of range: -1"}

      To reproduce, install IDM and set up a mock service to return the below (I used SoapUI for this):

      [
        {
          "someAttr" : "someContent"
        }
      ] 

      Next, call the new endpoint from IDM:

       curl \
      --header "X-OpenIDM-Username: openidm-admin" \
      --header "X-OpenIDM-Password: openidm-admin" \
      --header "Content-Type: application/json" \
      --request POST \
      --data '{
      "type": "groovy",
      "source": "def result = openidm.action(\"external/rest\", \"call\", [\"url\": \"http://localhost:9080/\",\"method\": \"GET\"]); return result;" }' \
      "https://localhost:8443/openidm/script?_action=eval" -k | jq .

       Working behaviour (IDM 6.5.0):

      $ curl \
      > --header "X-OpenIDM-Username: openidm-admin" \
      > --header "X-OpenIDM-Password: openidm-admin" \
      > --header "Content-Type: application/json" \
      > --request POST \
      > --data '{
      > "type": "groovy",
      > "source": "def result = openidm.action(\"external/rest\", \"call\", [\"url\": \"http://localhost:9080/\",\"method\": \"GET\"]); return result;" }' \
      > "https://localhost:8443/openidm/script?_action=eval" -k | jq .
      
      
      [
        {
          "someAttr": "someContent"
        }
      ] 

      Incorrect behaviour (IDM 7.0.0):

      $  curl \
      > --header "X-OpenIDM-Username: openidm-admin" \
      > --header "X-OpenIDM-Password: openidm-admin" \
      > --header "Content-Type: application/json" \
      > --request POST \
      > --data '{
      > "type": "groovy",
      > "source": "def result = openidm.action(\"external/rest\", \"call\", [\"url\": \"http://localhost:9080/\",\"method\": \"GET\"]); return result;" }' \
      > "https://localhost:8443/openidm/script?_action=eval" -k | jq .
      
      {
        "code": 500,
        "reason": "Internal Server Error",
        "message": "/: List index out of range: -1"
      }

      Removing the array and only returning a simple JSON object causes no errors:

      $ curl \
      > --header "X-OpenIDM-Username: openidm-admin" \
      > --header "X-OpenIDM-Password: openidm-admin" \
      > --header "Content-Type: application/json" \
      > --request POST \
      > --data '{
      > "type": "groovy",
      > "source": "def result = openidm.action(\"external/rest\", \"call\", [\"url\": \"http://localhost:9080/\",\"method\": \"GET\"]); return result;" }' \
      > "https://localhost:8443/openidm/script?_action=eval" -k | jq .
      
      
      {
        "someAttr": "someContent",
        "code": 200
      } 

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cgdrake Chris Drake
              Reporter:
              tom.wood Tom Wood
              QA Assignee:
              Travis Haagen Travis Haagen
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: