public RouteContext getRouteContext() { return RouteDispatcher.getRouteContext(); }
protected void processRequest(Request request, Response response) throws IOException, ServletException { // dispatch route(s) routeDispatcher.dispatch(request, response); }
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()); }
/** * Dispatches the Request/Response. * * @param request * @param response * @throws IOException * @throws ServletException */ public void dispatch(Request request, Response response) throws IOException, ServletException { onPreDispatch(request, response); onRouteDispatch(request, response); onPostDispatch(request, response); }
@Override public void init(ServletConfig servletConfig) { if (System.getProperty("pippo.hideLogo") == null) { log.info(PippoUtils.getPippoLogo()); } // check for runtime mode in filter init parameter String mode = servletConfig.getInitParameter(MODE_PARAM); if (!StringUtils.isNullOrEmpty(mode)) { System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode); } if (application == null) { createApplication(servletConfig); log.debug("Created application '{}'", application); } ServletContext servletContext = servletConfig.getServletContext(); // save the servlet context object in application application.setServletContext(servletContext); // set the application as an attribute of the servlet container if (servletContext.getAttribute(WebServer.PIPPO_APPLICATION) == null) { servletContext.setAttribute(WebServer.PIPPO_APPLICATION, application); } String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/"); application.getRouter().setContextPath(contextPath); log.debug("Serving application on context path '{}'", contextPath); log.debug("Initializing Route Dispatcher"); routeDispatcher = new RouteDispatcher(application); routeDispatcher.init(); String runtimeMode = application.getRuntimeMode().toString().toUpperCase(); log.info("Pippo started ({})", runtimeMode); }
@Override public void init() { routeDispatcher.init(); }
routeDispatcher = new RouteDispatcher(application); routeDispatcher.init();
@Override public void init() { routeDispatcher.init(); }
/** * Returns not null only in the context of the web layer (on a HTTP request). * It cannot be useful in a service (server side business layer). * For example if want to have access to PippoSettings from a service you must to inject PippoSettings * in that service and not to use Application.get().getPippoSettings(). * * @return The application instance or null */ public static Application get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getApplication() : null; }
@Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; // set the application path from the servlet request since we don't know it at initialization String applicationPath = application.getRouter().getContextPath() + httpServletRequest.getServletPath(); application.getRouter().setApplicationPath(applicationPath); // create Request, Response objects RequestResponseFactory requestResponseFactory = application.getRequestResponseFactory(); RequestResponse requestResponse = requestResponseFactory.createRequestResponse(httpServletRequest, httpServletResponse); Request request = requestResponse.getRequest(); Response response = requestResponse.getResponse(); // create a URI to automatically decode the path URI uri = URI.create(httpServletRequest.getRequestURL().toString()); String requestUri = uri.getPath(); String requestPath = request.getPath(); log.trace("The relative path for '{}' is '{}'", requestUri, requestPath); log.debug("Request {} '{}'", request.getMethod(), requestPath); // dispatch route(s) routeDispatcher.dispatch(request, response); }
public static Response get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getResponse() : null; }
@Override public void service(ServletRequest req, ServletResponse resp) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) req; HttpServletResponse httpResponse = (HttpServletResponse) resp; Request request = new Request(httpRequest, application); Response response = new Response(httpResponse, application); routeDispatcher.dispatch(request, response); }
public static Request get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getRequest() : null; }
@Override public void service(ServletRequest req, ServletResponse resp) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) req; HttpServletResponse httpResponse = (HttpServletResponse) resp; Request request = new Request(httpRequest, application); Response response = new Response(httpResponse, application); routeDispatcher.dispatch(request, response); }
public static Session get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getRequest().getSession(false) : null; }
public RouteContext getRouteContext() { return RouteDispatcher.getRouteContext(); }
protected Account getAccount() { Context context = RouteDispatcher.getRouteContext(); Account account = authExtractor.extract(context); return account; }
protected Account getAccount() { Context context = RouteDispatcher.getRouteContext(); Account account = authExtractor.extract(context); return account; }
@Override public String getDefaultValue() { Context context = RouteDispatcher.getRouteContext(); if (context == null) { // no context because we are generated a Swagger specification return DEFAULT; } // return the primary account token or DEFAULT Account account = new AuthExtractor().extract(context); return Optional.fromNullable(account.getToken()).or(DEFAULT); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { RequireToken requireToken = ClassUtil.getAnnotation(invocation.getMethod(), RequireToken.class); String tokenName = requireToken.value(); Context context = RouteDispatcher.getRouteContext(); // extract the named token from a header or a query parameter String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName)); token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString("")); if (Strings.isNullOrEmpty(token)) { throw new AuthorizationException("Missing '{}' token", tokenName); } Account account = getAccount(); if (account.isGuest()) { // authenticate by token TokenCredentials credentials = new TokenCredentials(token); account = securityManager.get().authenticate(credentials); if (account == null) { throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token); } context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account); log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token); } else { // validate token account.checkToken(token); } return invocation.proceed(); }