public void init() { log.debug("Initializing application '{}'", application); application.init(); router = application.getRouter(); errorHandler = application.getErrorHandler(); notFoundRouteHandler = application.getNotFoundRouteHandler(); routeContextFactory = getRouteContextFactory(); routeContextFactory.init(application); log.debug("RouteContext factory is '{}'", routeContextFactory.getClass().getName()); }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }
@Override protected void setup() { String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim(); serve(basePath + "/*").with(RestServlet.class); final PippoSettings pippoSettings = getPippoSettings(getSettings()); final Application application = new Application(pippoSettings); // must set context path before starting application application.getRouter().setContextPath(getSettings().getContextPath()); // must set application path before starting application String contextPath = application.getRouter().getContextPath(); String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(basePath, "/"); application.getRouter().setApplicationPath(applicationPath); // start the application which sets up all initializers application.init(); bind(Application.class).toInstance(application); bind(Router.class).toInstance(application.getRouter()); bind(Messages.class).toInstance(application.getMessages()); bind(Languages.class).toInstance(application.getLanguages()); bind(MimeTypes.class).toInstance(application.getMimeTypes()); bind(ErrorHandler.class).toInstance(application.getErrorHandler()); bind(TemplateEngine.class).toInstance(application.getTemplateEngine()); bind(HttpCacheToolkit.class).toInstance(application.getHttpCacheToolkit()); bind(ContentTypeEngines.class).toInstance(application.getContentTypeEngines()); bind(RestService.class); }
@Override protected void setup() { String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim(); serve(basePath + "/*").with(RestServlet.class); final PippoSettings pippoSettings = getPippoSettings(getSettings()); final Application application = new Application(pippoSettings); // must set context path before starting application application.getRouter().setContextPath(getSettings().getContextPath()); // must set application path before starting application String contextPath = application.getRouter().getContextPath(); String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(basePath, "/"); application.getRouter().setApplicationPath(applicationPath); // start the application which sets up all initializers application.init(); bind(Application.class).toInstance(application); bind(Router.class).toInstance(application.getRouter()); bind(Messages.class).toInstance(application.getMessages()); bind(Languages.class).toInstance(application.getLanguages()); bind(MimeTypes.class).toInstance(application.getMimeTypes()); bind(ErrorHandler.class).toInstance(application.getErrorHandler()); bind(TemplateEngine.class).toInstance(application.getTemplateEngine()); bind(HttpCacheToolkit.class).toInstance(application.getHttpCacheToolkit()); bind(ContentTypeEngines.class).toInstance(application.getContentTypeEngines()); bind(RestService.class); }