public Object executeScripts(ResourceResponse response) throws Exception { String resourcePath = response.inReplyTo().resourcePath().toString(); ResourceResponse.ResponseType type = response.responseType(); ResourceTriggeredScript.FUNCTIONS resourceFunction = ResourceTriggeredScript.FUNCTIONS.POSTREAD; switch (type) { case CREATED: resourceFunction = ResourceTriggeredScript.FUNCTIONS.POSTCREATE; break; case READ: resourceFunction = ResourceTriggeredScript.FUNCTIONS.POSTREAD; break; case UPDATED: resourceFunction = ResourceTriggeredScript.FUNCTIONS.POSTUPDATE; break; case DELETED: resourceFunction = ResourceTriggeredScript.FUNCTIONS.POSTDELETE; break; case ERROR: resourceFunction = ResourceTriggeredScript.FUNCTIONS.ONERROR; break; } Set<ResourceTriggeredScript> scripts = scriptRegistry.getByTarget(resourcePath, resourceFunction, true); // CREATE is special since we apply the create to /foo/bar to create /foo/bar/baz so we should // also check /foo/bar/* if (resourceFunction == ResourceTriggeredScript.FUNCTIONS.POSTCREATE) { scripts.addAll(scriptRegistry.getByPath(resourcePath + "/*", resourceFunction, true)); } for (ResourceTriggeredScript script : scripts) { Object reply = runScript(resourceFunction.getFunctionName(), script, response); if (reply != null) { return reply; } } if (resourceFunction == ResourceTriggeredScript.FUNCTIONS.POSTREAD) { // we are on a post read, which means expand could have been used to return expanded members // check if the members were set to be expanded or not Object handleMembers = handleMembers( response, response.state(), response.inReplyTo().requestContext().returnFields()); if (handleMembers != null) { return handleMembers; } } return null; }