@SuppressWarnings("unchecked") public ControllerHandler(ControllerApplication application, Method controllerMethod) { this.application = application; this.controllerClass = (Class<? extends Controller>) controllerMethod.getDeclaringClass(); this.controllerMethod = controllerMethod; ContentTypeEngines engines = application.getContentTypeEngines(); this.declaredConsumes = ControllerUtils.getConsumes(controllerMethod); validateConsumes(engines.getContentTypes()); this.declaredProduces = ControllerUtils.getProduces(controllerMethod); validateProduces(engines.getContentTypes()); this.isNoCache = ClassUtils.getAnnotation(controllerMethod, NoCache.class) != null; initInterceptors(); initExtractors(); }
private void logEngines() { if (!settings.getBoolean(SETTING_ENGINES_LOG, true)) { return; } TemplateEngine templateEngine = application.getTemplateEngine(); ContentTypeEngines engines = application.getContentTypeEngines(); List<String> contentTypes = new ArrayList<>(engines.getContentTypes()); Collections.sort(contentTypes); int maxContentTypeLen = 0; int maxTemplateEngineLen = templateEngine == null ? 0 : templateEngine.getClass().getName().length(); for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length()); maxTemplateEngineLen = Math.max(maxTemplateEngineLen, engine.getClass().getName().length()); } if (templateEngine != null) { log.info("{} => {}", Strings.padEnd("templates", maxContentTypeLen, ' '), templateEngine.getClass().getName()); } for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); log.info("{} => {}", Strings.padEnd(contentType, maxContentTypeLen, ' '), engine.getClass().getName()); } }
private void logEngines() { if (!settings.getBoolean(SETTING_ENGINES_LOG, true)) { return; } TemplateEngine templateEngine = application.getTemplateEngine(); ContentTypeEngines engines = application.getContentTypeEngines(); List<String> contentTypes = new ArrayList<>(engines.getContentTypes()); Collections.sort(contentTypes); int maxContentTypeLen = 0; int maxTemplateEngineLen = templateEngine == null ? 0 : templateEngine.getClass().getName().length(); for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length()); maxTemplateEngineLen = Math.max(maxTemplateEngineLen, engine.getClass().getName().length()); } if (templateEngine != null) { log.info("{} => {}", Strings.padEnd("templates", maxContentTypeLen, ' '), templateEngine.getClass().getName()); } for (String contentType : contentTypes) { ContentTypeEngine engine = engines.getContentTypeEngine(contentType); log.info("{} => {}", Strings.padEnd(contentType, maxContentTypeLen, ' '), engine.getClass().getName()); } }
@SuppressWarnings("unchecked") public ControllerHandler(ControllerApplication application, Method controllerMethod) { this.application = application; this.controllerClass = (Class<? extends Controller>) controllerMethod.getDeclaringClass(); this.controllerMethod = controllerMethod; ContentTypeEngines engines = application.getContentTypeEngines(); this.declaredConsumes = ControllerUtils.getConsumes(controllerMethod); validateConsumes(engines.getContentTypes()); this.declaredProduces = ControllerUtils.getProduces(controllerMethod); validateProduces(engines.getContentTypes()); this.isNoCache = ClassUtils.getAnnotation(controllerMethod, NoCache.class) != null; initInterceptors(); initExtractors(); }
public ControllerHandler(Injector injector, Class<? extends Controller> controllerClass, String methodName) { if (controllerClass.isAnnotationPresent(Singleton.class) || controllerClass.isAnnotationPresent(javax.inject.Singleton.class)) { throw new FathomException("Controller '{}' may not be annotated as a Singleton!", controllerClass.getName()); } this.controllerClass = controllerClass; this.controllerProvider = injector.getProvider(controllerClass); this.method = findMethod(controllerClass, methodName); this.messages = injector.getInstance(Messages.class); Preconditions.checkNotNull(method, "Failed to find method '%s'", Util.toString(controllerClass, methodName)); log.trace("Obtained method for '{}'", Util.toString(method)); this.routeInterceptors = new ArrayList<>(); for (Class<? extends RouteHandler<Context>> handlerClass : ControllerUtil.collectRouteInterceptors(method)) { RouteHandler<Context> handler = injector.getInstance(handlerClass); this.routeInterceptors.add(handler); } ContentTypeEngines engines = injector.getInstance(ContentTypeEngines.class); this.declaredConsumes = ControllerUtil.getConsumes(method); validateConsumes(engines.getContentTypes()); this.declaredProduces = ControllerUtil.getProduces(method); validateProduces(engines.getContentTypes()); this.declaredReturns = ControllerUtil.getReturns(method); validateDeclaredReturns(); this.contentTypeSuffixes = configureContentTypeSuffixes(engines); configureMethodArgs(injector); this.isNoCache = ClassUtil.getAnnotation(method, NoCache.class) != null; }
public ControllerHandler(Injector injector, Class<? extends Controller> controllerClass, String methodName) { if (controllerClass.isAnnotationPresent(Singleton.class) || controllerClass.isAnnotationPresent(javax.inject.Singleton.class)) { throw new FathomException("Controller '{}' may not be annotated as a Singleton!", controllerClass.getName()); } this.controllerClass = controllerClass; this.controllerProvider = injector.getProvider(controllerClass); this.method = findMethod(controllerClass, methodName); this.messages = injector.getInstance(Messages.class); Preconditions.checkNotNull(method, "Failed to find method '%s'", Util.toString(controllerClass, methodName)); log.trace("Obtained method for '{}'", Util.toString(method)); this.routeInterceptors = new ArrayList<>(); for (Class<? extends RouteHandler<Context>> handlerClass : ControllerUtil.collectRouteInterceptors(method)) { RouteHandler<Context> handler = injector.getInstance(handlerClass); this.routeInterceptors.add(handler); } ContentTypeEngines engines = injector.getInstance(ContentTypeEngines.class); this.declaredConsumes = ControllerUtil.getConsumes(method); validateConsumes(engines.getContentTypes()); this.declaredProduces = ControllerUtil.getProduces(method); validateProduces(engines.getContentTypes()); this.declaredReturns = ControllerUtil.getReturns(method); validateDeclaredReturns(); this.contentTypeSuffixes = configureContentTypeSuffixes(engines); configureMethodArgs(injector); this.isNoCache = ClassUtil.getAnnotation(method, NoCache.class) != null; }