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

Unable to update/add a property in response.content object in Javascript script (launched from router onResponse hook)

    Details

    • Verified Version/s:
    • Story Points:
      0
    • Sprint:
      OpenIDM Sprint 51, OpenIDM Sprint 57

      Description

      Updating or adding a property in response.content object in Javascript script launched from router onResponse hook not possible anymore. This seem to be broken since we moved to CREST 3.

      Here is an example of configuration in router.json:

      {
            "pattern" : "^managed/user.*",
            "onResponse" : {
              "type" : "text/javascript",
              "source" : "logger.info('Response.content contains: {}',response.content);response.content.telephoneNumber = '987654321';"
            },
            "methods" : [
              "read"
            ]
          },
      

      This should log response.content and update one property that we get in the response of the request when we do a GET on a managed user.

      the log works fine and we get:

      INFO: Response.content contains: { "userName": "rsutter", "telephoneNumber": "6669876987", "givenName": "rick", "description": "Just another John Doe or Joe Smith", "sn": "sutter", "mail": "rick@example.com", "evaluatedConditionTrue": "triggered on true evaluated condition", "conditionTrue": "triggered on true condition", "filterMatch": "method matching test successful", "onRequestHook1": "hook#1", "onRequestHook2": "hook#2", "onRequestHook3": "hook#3", "onRequestScript": "onRequest script test successful", "accountStatus": "active", "roles": [ "openidm-authorized" ], "lastPasswordSet": "", "postalCode": "", "stateProvince": "", "passwordAttempts": "0", "lastPasswordAttempt": "Tue Sep 08 2015 10:23:15 GMT+0200 (CEST)", "postalAddress": "", "address2": "", "country": "", "city": "", "effectiveRoles": [ "openidm-authorized" ], "effectiveAssignments": [  ], "_id": "ricksutter", "_rev": "1" }
      

      But the update is failing with this error

      Sep 08, 2015 10:23:15 AM org.forgerock.openidm.servlet.internal.ServletConnectionFactory$4 handleException
      WARNING: Resource exception: 500 Internal Server Error: "Java class "org.forgerock.json.JsonValue" has no public instance field or method named "telephoneNumber". (64584E8A10DC5362E398DDA6DCA8A85284C16BFD#1) in 64584E8A10DC5362E398DDA6DCA8A85284C16BFD at line number 1 at column number 0"
      org.forgerock.json.resource.InternalServerErrorException: Java class "org.forgerock.json.JsonValue" has no public instance field or method named "telephoneNumber". (64584E8A10DC5362E398DDA6DCA8A85284C16BFD#1) in 64584E8A10DC5362E398DDA6DCA8A85284C16BFD at line number 1 at column number 0
      	at org.forgerock.json.resource.ResourceException.getException(ResourceException.java:211)
      	at org.forgerock.script.engine.Utils.adapt(Utils.java:261)
      

      Note: this works fine in Groovy with a config like:

      {
            "testName" : "----- property updated in response -----",
            "pattern" : "^managed/user.*",
            "onResponse" : {
              "type" : "groovy",
              "source" : "response.content.put('postalCode','42'); return response;"
            },
            "methods" : [
              "read"
            ]
          },
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                brmiller Brendan Miller
                Reporter:
                laurent.bristiel Laurent Bristiel [X] (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: