Search in sources :

Example 21 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class BatchResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context serverContext, ActionRequest actionRequest) {
    if (!actionRequest.getAction().equals(BATCH)) {
        final String msg = "Action '" + actionRequest.getAction() + "' not implemented for this resource";
        final NotSupportedException exception = new NotSupportedException(msg);
        debug.error(msg, exception);
        return exception.asPromise();
    }
    String scriptId = null;
    try {
        JsonValue scriptIdValue = actionRequest.getContent().get(SCRIPT_ID);
        if (scriptIdValue == null) {
            if (debug.errorEnabled()) {
                debug.error("BatchResource :: actionCollection - ScriptId null. Default scripts not implemented.");
            }
            return new BadRequestException().asPromise();
        } else {
            scriptId = scriptIdValue.asString();
        }
        final JsonValue requests = actionRequest.getContent().get(REQUESTS);
        final String realm = getRealm(serverContext);
        final ScriptConfiguration scriptConfig = scriptingServiceFactory.create(SubjectUtils.createSuperAdminSubject(), realm).get(scriptId);
        final ScriptObject script = new ScriptObject(scriptConfig.getName(), scriptConfig.getScript(), scriptConfig.getLanguage());
        final ScriptResponse response = new ScriptResponse();
        final Bindings bindings = new SimpleBindings();
        bindings.put(PAYLOAD, requests);
        bindings.put(CONTEXT, serverContext);
        bindings.put(LOGGER, debug);
        bindings.put(REQUESTER, requester);
        bindings.put(RESPONSE, response);
        return newResultPromise(newActionResponse((JsonValue) scriptEvaluator.evaluateScript(script, bindings)));
    } catch (ScriptException e) {
        debug.error("BatchResource :: actionCollection - Error running script : {}", scriptId);
        return exceptionMappingHandler.handleError(serverContext, actionRequest, e).asPromise();
    } catch (javax.script.ScriptException e) {
        debug.error("BatchResource :: actionCollection - Error running script : {}", scriptId);
        return new InternalServerErrorException().asPromise();
    }
}
Also used : ScriptObject(org.forgerock.openam.scripting.ScriptObject) JsonValue(org.forgerock.json.JsonValue) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) ScriptException(org.forgerock.openam.scripting.ScriptException) SimpleBindings(javax.script.SimpleBindings) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ScriptConfiguration(org.forgerock.openam.scripting.service.ScriptConfiguration) NotSupportedException(org.forgerock.json.resource.NotSupportedException) ScriptResponse(org.forgerock.openam.scripting.rest.batch.helpers.ScriptResponse)

Aggregations

NotSupportedException (org.forgerock.json.resource.NotSupportedException)21 JsonValue (org.forgerock.json.JsonValue)11 SSOException (com.iplanet.sso.SSOException)8 SMSException (com.sun.identity.sm.SMSException)8 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)8 ResourceException (org.forgerock.json.resource.ResourceException)7 BadRequestException (org.forgerock.json.resource.BadRequestException)5 RealmContext (org.forgerock.openam.rest.RealmContext)4 IdRepoException (com.sun.identity.idm.IdRepoException)3 ArrayList (java.util.ArrayList)3 ForbiddenException (org.forgerock.json.resource.ForbiddenException)3 SSOToken (com.iplanet.sso.SSOToken)2 AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)2 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)2 ServiceConfig (com.sun.identity.sm.ServiceConfig)2 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)2 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)2 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MessagingException (javax.mail.MessagingException)2