public Request(HttpServletRequest servletRequest, Application application) { this.httpServletRequest = servletRequest; this.contentTypeEngines = application.getContentTypeEngines(); applicationPath = application.getRouter().getApplicationPath(); // fill (query&post) parameters if any initParameters(); // empty path parameters for now (see internalSetPathParameters method) pathParameters = Collections.unmodifiableMap(new HashMap<String, ParameterValue>()); // init all parameters initAllParameters(); }
public Response(HttpServletResponse httpServletResponse, Application application) { this.httpServletResponse = httpServletResponse; this.contentTypeEngines = application.getContentTypeEngines(); this.templateEngine = application.getTemplateEngine(); this.httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.toString()); this.contextPath = application.getRouter().getContextPath(); this.applicationPath = StringUtils.removeEnd(application.getRouter().getApplicationPath(), "/"); this.mimeTypes = application.getMimeTypes(); this.status = 0; }
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()); } }
@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); }