protected void validateRoute(Route route) { // validate the request method if (StringUtils.isNullOrEmpty(route.getRequestMethod())) { throw new PippoRuntimeException("Unspecified request method!"); } // validate the uri pattern String uriPattern = route.getUriPattern(); if (StringUtils.isNullOrEmpty(uriPattern)) { throw new PippoRuntimeException("The uri pattern cannot be null or empty"); } }
@Override public void setContextPath(String contextPath) { if (StringUtils.isNullOrEmpty(contextPath) || "/".equals(contextPath.trim())) { this.contextPath = ""; } else { this.contextPath = StringUtils.addStart(contextPath, "/"); } }
@Override public void setApplicationPath(String applicationPath) { if (StringUtils.isNullOrEmpty(applicationPath) || "/".equals(applicationPath.trim())) { this.applicationPath = ""; } else { this.applicationPath = StringUtils.removeEnd(StringUtils.addStart(applicationPath, "/"), "/"); } }
@Override public void init(FilterConfig filterConfig) throws ServletException { if (System.getProperty("pippo.hideLogo") == null) { log.info(PippoUtils.getPippoLogo()); } // check for runtime mode in filter init parameter String mode = filterConfig.getInitParameter(MODE_PARAM); if (!StringUtils.isNullOrEmpty(mode)) { System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode); } if (application == null) { createApplication(filterConfig); log.debug("Created application '{}'", application); } ServletContext servletContext = filterConfig.getServletContext(); application.setServletContext(servletContext); try { String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/"); application.getRouter().setContextPath(contextPath); if (filterPath == null) { initFilterPath(filterConfig); } String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(filterPath, "/"); application.getRouter().setApplicationPath(applicationPath); if (!contextPath.equals(applicationPath)) { log.debug("Context path is '{}'", contextPath); } log.debug("Serving application on path '{}'", applicationPath); log.debug("Initializing Route Dispatcher"); routeDispatcher = new RouteDispatcher(application); routeDispatcher.init(); String runtimeMode = application.getRuntimeMode().toString().toUpperCase(); log.info("Pippo started ({})", runtimeMode); } catch (Exception e) { destroy(); throw new ServletException(e); } }
private void removeBinding(Route route) { String nameOrUriPattern = StringUtils.isNullOrEmpty(route.getName()) ? route.getUriPattern() : route.getName(); PatternBinding binding = getBinding(nameOrUriPattern); bindingsCache.get(route.getRequestMethod()).remove(binding); }