class RestAuthCallbackHandlerManager {

    public JsonValue handleCallbacks(HttpServletRequest request,
            HttpServletResponse response, Callback[] callbacks)
            throws RestAuthException {

        List<Object> jsonCallbacks = new ArrayList<>();
        int callbackIndex = 0;
        // check if can be completed by headers and/or request
        // if so then attempt it and response true if successful
        boolean handledInternally = handleCallbacksInternally(request, response, callbacks);

        // else or on false convert callback into json
        if (!handledInternally) {
            logger.message("Cannot handle callbacks internally. Converting to JSON instead.");
            for (Callback callback : callbacks) {
                callbackIndex++;
                RestAuthCallbackHandler restAuthCallbackHandler =
                        restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(callback.getClass());

                JsonValue jsonCallback = restAuthCallbackHandler.convertToJson(callback, callbackIndex);
                jsonCallbacks.add(jsonCallback.getObject());
            }
        }

        return new JsonValue(jsonCallbacks);
    }

    @Inject public  RestAuthCallbackHandlerManager(RestAuthCallbackHandlerFactory restAuthCallbackHandlerFactory);

}