class ApplicationsResource extends RealmAwareResource {

    @Override
    public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {

        final Subject subject = getContextSubject(context);
        if (subject == null) {
            debug.error("ApplicationsResource :: CREATE : Unknown Subject");
            return new BadRequestException().asPromise();
        }

        final String realm = getRealm(context);
        String applicationId = null;
        try {
            ApplicationWrapper applicationWrapper = createApplicationWrapper(request.getContent(), subject);
            ensureApplicationIdMatch(applicationWrapper, request.getNewResourceId());
            applicationId = applicationWrapper.getName();
            validateApplicationId(applicationId);
            if (applicationExists(applicationId, realm, subject)) {
                throw new EntitlementException(EntitlementException.APPLICATION_ALREADY_EXISTS);
            }
            Application application = appService(subject, realm).saveApplication(applicationWrapper.getApplication());
            return newResultPromise(newResourceResponse(application.getName(),
                    Long.toString(application.getLastModifiedDate()), applicationToJson(application)));
        } catch (EntitlementException e) {
            debug.error("ApplicationsResource :: CREATE by {}: Application creation failed. {}",
                    getPrincipalNameFromSubject(subject), applicationId, e);
            return exceptionMappingHandler.handleError(context, request, e).asPromise();
        }
    }

    @Inject public  ApplicationsResource(@Named("frRest") Debug debug, ApplicationServiceFactory applicationServiceFactory,
            ApplicationTypeManagerWrapper appTypeManagerWrapper,
            ExceptionMappingHandler<EntitlementException, ResourceException> exceptionMappingHandler);

}