Search in sources :

Example 1 with Action

use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.

the class RouteBuilderImpl method buildRouter.

public DScopedRouter buildRouter() {
    if (pageNotFoundInfo == null)
        throw new IllegalStateException("Client did not call setPageNotFoundRoute for router=" + routerInfo + " and that's required to catch stray not founds");
    else if (internalErrorInfo == null)
        throw new IllegalStateException("Client did not call setInternalErrorRoute for router=" + routerInfo + " and that's required to catch stray bugs in your application");
    List<AbstractRouter> routers = super.buildRoutes(routeFilters);
    // static routes get cached in browser typically so add them last so dynamic routes which are not cached are
    // pattern matched first and we don't waste loop matching static routes
    routers.addAll(staticRouters);
    Map<String, EScopedRouter> pathToRouter = buildScopedRouters(routeFilters);
    SvcProxyFixedRoutes svcProxy = new SvcProxyFixedRoutes(holder.getSvcProxyLogic().getServiceInvoker(), futureUtil);
    FilterCreationMeta notFoundChain = new FilterCreationMeta(resettingLogic.getInjector(), notFoundFilters, svcProxy);
    FilterCreationMeta internalErrorChain = new FilterCreationMeta(resettingLogic.getInjector(), internalErrorFilters, svcProxy);
    Service<MethodMeta, Action> svc = holder.getFinder().loadFilters(internalErrorChain);
    String i18nBundleName = internalErrorInfo.getRouteModuleInfo().getI18nBundleName();
    EInternalErrorRouter internalErrorRouter = new EInternalErrorRouter(holder.getRouteInvoker2(), i18nBundleName, internalErrorController, svc);
    Service<MethodMeta, Action> notFoundSvc = holder.getFinder().loadFilters(notFoundChain);
    String notFoundBundleName = pageNotFoundInfo.getRouteModuleInfo().getI18nBundleName();
    ENotFoundRouter notFoundRouter = new ENotFoundRouter(holder.getRouteInvoker2(), notFoundBundleName, notFoundControllerInst, notFoundSvc);
    return new DScopedRouter(routerInfo, pathToRouter, routers, notFoundRouter, internalErrorRouter, routerFutures, futureUtil);
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) ENotFoundRouter(org.webpieces.router.impl.routers.ENotFoundRouter) MethodMeta(org.webpieces.router.api.routes.MethodMeta) EInternalErrorRouter(org.webpieces.router.impl.routers.EInternalErrorRouter) SvcProxyFixedRoutes(org.webpieces.router.impl.services.SvcProxyFixedRoutes) EScopedRouter(org.webpieces.router.impl.routers.EScopedRouter) AbstractRouter(org.webpieces.router.impl.routers.AbstractRouter) DScopedRouter(org.webpieces.router.impl.routers.DScopedRouter)

Example 2 with Action

use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.

the class SharedMatchUtil method buildRoutes.

protected List<AbstractRouter> buildRoutes(List<FilterInfo<?>> routeFilters) {
    List<AbstractRouter> routers = new ArrayList<>();
    for (RouterAndInfo routerAndInfo : newDynamicRoutes) {
        AbstractDynamicRouter router = routerAndInfo.getRouter();
        MatchInfo matchInfo = router.getMatchInfo();
        String path = matchInfo.getFullPath();
        Port port = matchInfo.getExposedPorts();
        ResolvedMethod methodMeta = routerAndInfo.getMetaAndController().getMethodMeta();
        StreamService streamSvc;
        if (routerAndInfo.getRouteType() == RouteType.STREAMING) {
            streamSvc = new StreamProxy(holder.getFutureUtil(), holder.getServiceInvoker());
        } else {
            // Wire in request/response filters at this point
            List<FilterInfo<?>> filters = findMatchingFilters(methodMeta, path, port, routeFilters);
            FilterCreationMeta chainInfo = new FilterCreationMeta(resettingLogic.getInjector(), filters, routerAndInfo.getSvcProxy());
            Service<MethodMeta, Action> service = holder.getFinder().loadFilters(chainInfo);
            Processor processor;
            if (routerAndInfo.getRouteType() == RouteType.CONTENT) {
                processor = holder.getResponseProcessorContent();
            } else if (routerAndInfo.getRouteType() == RouteType.HTML) {
                processor = holder.getResponseProcessorHtml();
            } else {
                throw new IllegalStateException("RouteType not supported here=" + routerAndInfo.getRouteType());
            }
            String i18nBundleName = routerAndInfo.getRouteInfo().getRouteModuleInfo().getI18nBundleName();
            Endpoint svc = new Endpoint(service);
            streamSvc = new RequestResponseStream(svc, i18nBundleName, processor, holder.getBodyParsers(), holder.getServiceInvoker());
        }
        // Add streaming filters at this point here...
        router.setDynamicInfo(streamSvc);
        routers.add(router);
    }
    return routers;
}
Also used : StreamService(org.webpieces.router.api.streams.StreamService) Action(org.webpieces.router.api.controller.actions.Action) Processor(org.webpieces.router.impl.routeinvoker.Processor) Port(org.webpieces.router.api.routes.Port) ArrayList(java.util.ArrayList) MethodMeta(org.webpieces.router.api.routes.MethodMeta) AbstractDynamicRouter(org.webpieces.router.impl.routers.AbstractDynamicRouter) ResolvedMethod(org.webpieces.router.impl.loader.ResolvedMethod) Endpoint(org.webpieces.router.impl.routers.Endpoint) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) AbstractRouter(org.webpieces.router.impl.routers.AbstractRouter)

Example 3 with Action

use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.

the class AbstractLoader method createServiceFromFiltersImpl.

protected Service<MethodMeta, Action> createServiceFromFiltersImpl(ServiceCreationInfo meta) {
    Injector injector = meta.getInjector();
    List<RouteFilter<?>> filters = createFilters(injector, meta.getFilterInfos());
    Service<MethodMeta, Action> svcWithFilters = loader.loadFilters(meta.getService(), filters);
    return svcWithFilters;
}
Also used : MethodMeta(org.webpieces.router.api.routes.MethodMeta) Action(org.webpieces.router.api.controller.actions.Action) Injector(com.google.inject.Injector) RouteFilter(org.webpieces.router.api.routes.RouteFilter)

Example 4 with Action

use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.

the class ServiceInvoker method invokeSvc.

public XFuture<Void> invokeSvc(MethodMeta meta, String i18nBundleName, Endpoint service, Processor processor, ProxyStreamHandle handle) {
    if (processor == null || meta == null || service == null || handle == null)
        throw new IllegalArgumentException("nothing can be null into this metehod");
    handle.initJustBeforeInvoke(reverseRoutes, meta);
    RequestContext requestCtx = meta.getCtx();
    LoadedController loadedController = meta.getLoadedController();
    Messages messages = new Messages(i18nBundleName, "webpieces");
    requestCtx.setMessages(messages);
    XFuture<Action> response = futureUtil.catchBlockWrap(() -> invokeService(service, meta), (t) -> convert(loadedController, t));
    return response.thenCompose(resp -> continueProcessing(handle, meta, resp, processor));
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) Messages(org.webpieces.ctx.api.Messages) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 5 with Action

use of org.webpieces.router.api.controller.actions.Action in project webpieces by deanhiller.

the class BeansController method pageParamAsync.

public XFuture<Action> pageParamAsync() {
    XFuture<Action> future = new XFuture<>();
    RequestContext ctx = Current.getContext();
    executor.execute(new Runnable() {

        @Override
        public void run() {
            ctx.getFlash().put("testkey", "testflashvalue");
            future.complete(Actions.renderThis("user", "Dean Hiller"));
        }
    });
    return future;
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) XFuture(org.webpieces.util.futures.XFuture) RequestContext(org.webpieces.ctx.api.RequestContext)

Aggregations

Action (org.webpieces.router.api.controller.actions.Action)7 MethodMeta (org.webpieces.router.api.routes.MethodMeta)3 RequestContext (org.webpieces.ctx.api.RequestContext)2 Redirect (org.webpieces.router.api.controller.actions.Redirect)2 AbstractRouter (org.webpieces.router.impl.routers.AbstractRouter)2 Injector (com.google.inject.Injector)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 NotBlank (javax.validation.constraints.NotBlank)1 Size (javax.validation.constraints.Size)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Current (org.webpieces.ctx.api.Current)1 Messages (org.webpieces.ctx.api.Messages)1