Search in sources :

Example 1 with LoadedController

use of org.webpieces.router.impl.loader.LoadedController in project webpieces by deanhiller.

the class AbstractRouteInvoker method invokeSvc.

private XFuture<Void> invokeSvc(InvokeInfo invokeInfo, Endpoint dynamicInfo, RouteData data, Processor processor) {
    LoadedController loadedController = invokeInfo.getLoadedController();
    ProxyStreamHandle handle = invokeInfo.getHandler();
    RequestContext requestCtx = invokeInfo.getRequestCtx();
    MethodMeta methodMeta = new MethodMeta(loadedController, requestCtx, invokeInfo.getRouteType(), data);
    String i18nBundleName = "";
    return serviceInvoker.invokeSvc(methodMeta, i18nBundleName, dynamicInfo, processor, handle);
}
Also used : MethodMeta(org.webpieces.router.api.routes.MethodMeta) LoadedController(org.webpieces.router.impl.loader.LoadedController) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 2 with LoadedController

use of org.webpieces.router.impl.loader.LoadedController in project webpieces by deanhiller.

the class AbstractRouteInvoker method invokeRealRoute.

protected RouterStreamRef invokeRealRoute(InvokeInfo invokeInfo, StreamService endpoint, RouteData data) {
    if (endpoint == null)
        throw new IllegalStateException("Bug, service should never be null at this point");
    LoadedController loadedController = invokeInfo.getLoadedController();
    RequestContext requestCtx = invokeInfo.getRequestCtx();
    Messages messages = new Messages(invokeInfo.getI18nBundleName(), "webpieces");
    requestCtx.setMessages(messages);
    MethodMeta methodMeta = new MethodMeta(loadedController, requestCtx, invokeInfo.getRouteType(), data);
    return endpoint.openStream(methodMeta, invokeInfo.getHandler());
}
Also used : MethodMeta(org.webpieces.router.api.routes.MethodMeta) Messages(org.webpieces.ctx.api.Messages) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 3 with LoadedController

use of org.webpieces.router.impl.loader.LoadedController in project webpieces by deanhiller.

the class ScopedRouteBuilderImpl method addRoute.

@Override
public void addRoute(Port port, HttpMethod method, String path, String controllerMethod, RouteId routeId, boolean checkToken) {
    if (!controllerMethod.contains("."))
        throw new IllegalArgumentException("controllerMethod='" + controllerMethod + " does not contain a '.' which is required separating class name and method");
    UrlPath p = new UrlPath(routerInfo, path);
    boolean isPostOnly = method == HttpMethod.POST;
    RouteModuleInfo moduleInfo = CurrentRoutes.get();
    RouteInfo routeInfo = new RouteInfo(moduleInfo, controllerMethod);
    // MUST DO loadControllerIntoMetat HERE so stack trace has customer's line in it so he knows EXACTLY what
    // he did wrong when reading the exception!!
    MethodMetaAndController metaAndController = holder.getFinder().loadHtmlController(resettingLogic.getInjector(), routeInfo, isPostOnly);
    MatchInfo matchInfo = createMatchInfo(p, port, method, holder.getUrlEncoding());
    LoadedController loadedController = metaAndController.getLoadedController();
    FHtmlRouter router = new FHtmlRouter(holder.getRouteInvoker2(), loadedController, moduleInfo.getI18nBundleName(), matchInfo, checkToken);
    SvcProxyForHtml svc = new SvcProxyForHtml(holder.getSvcProxyLogic(), futureUtil);
    RouterAndInfo routerAndInfo = new RouterAndInfo(router, routeInfo, metaAndController, svc);
    newDynamicRoutes.add(routerAndInfo);
    resettingLogic.getReverseRoutes().addRoute(routeId, router);
    log.info("scope:'" + routerInfo + "' added route=" + matchInfo + " method=" + routeInfo.getControllerMethodString());
}
Also used : SvcProxyForHtml(org.webpieces.router.impl.services.SvcProxyForHtml) LoadedController(org.webpieces.router.impl.loader.LoadedController) UrlPath(org.webpieces.router.impl.UrlPath) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo) FHtmlRouter(org.webpieces.router.impl.routers.FHtmlRouter) MethodMetaAndController(org.webpieces.router.impl.loader.MethodMetaAndController)

Example 4 with LoadedController

use of org.webpieces.router.impl.loader.LoadedController in project webpieces by deanhiller.

the class ScopedRouteBuilderImpl method addContentRoute.

@Override
public void addContentRoute(Port port, HttpMethod method, String path, String controllerMethod, RouteId routeId) {
    UrlPath p = new UrlPath(routerInfo, path);
    RouteModuleInfo moduleInfo = CurrentRoutes.get();
    RouteInfo routeInfo = new RouteInfo(moduleInfo, controllerMethod);
    // MUST DO loadControllerIntoMeta HERE so stack trace has customer's line in it so he knows EXACTLY what
    // he did wrong when reading the exception!!
    BinderAndLoader container = holder.getFinder().loadContentController(resettingLogic.getInjector(), routeInfo);
    MatchInfo matchInfo = createMatchInfo(p, port, method, holder.getUrlEncoding());
    LoadedController loadedController = container.getMetaAndController().getLoadedController();
    FContentRouter router = new FContentRouter(holder.getRouteInvoker2(), loadedController, moduleInfo, matchInfo, container.getBinder());
    SvcProxyForContent svc = new SvcProxyForContent(holder.getSvcProxyLogic(), futureUtil);
    RouterAndInfo routerAndInfo = new RouterAndInfo(router, routeInfo, container.getMetaAndController(), svc);
    newDynamicRoutes.add(routerAndInfo);
    if (// if there is a routeId, then add the reverse mapping
    routeId != null)
        resettingLogic.getReverseRoutes().addRoute(routeId, router);
    log.info("scope:'" + routerInfo + "' added content route=" + matchInfo + " method=" + routeInfo.getControllerMethodString());
}
Also used : BinderAndLoader(org.webpieces.router.impl.loader.BinderAndLoader) LoadedController(org.webpieces.router.impl.loader.LoadedController) UrlPath(org.webpieces.router.impl.UrlPath) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) SvcProxyForContent(org.webpieces.router.impl.services.SvcProxyForContent) FContentRouter(org.webpieces.router.impl.routers.FContentRouter) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo)

Example 5 with LoadedController

use of org.webpieces.router.impl.loader.LoadedController in project webpieces by deanhiller.

the class DevRouteInvoker method invokeDevelopmentErrorPage.

private XFuture<Void> invokeDevelopmentErrorPage(InvokeInfo invokeInfo, RouteInfoForInternalError data) {
    RequestContext requestCtx = invokeInfo.getRequestCtx();
    ProxyStreamHandle handler = invokeInfo.getHandler();
    RouterRequest req = requestCtx.getRequest();
    Throwable exception = data.getException();
    Injector webAppInjector = webInjector.getCurrentInjector();
    RouteInfo routeInfo = new RouteInfo(new RouteModuleInfo("", null), "/org/webpieces/devrouter/impl/DevelopmentController.internalError");
    SvcProxyFixedRoutes svcProxy = new SvcProxyFixedRoutes(serviceInvoker, futureUtil);
    LoadedController newLoadedController = controllerFinder.loadGenericController(webAppInjector, routeInfo).getLoadedController();
    Endpoint newInfo = new Endpoint(svcProxy);
    RouterRequest newRequest = new RouterRequest();
    newRequest.putMultipart("url", req.relativePath);
    newRequest.isHttps = req.isHttps;
    newRequest.isBackendRequest = req.isBackendRequest;
    newRequest.originalRequest = req.originalRequest;
    newRequest.requestState.put(DevelopmentController.ORIGINAL_REQUEST, req);
    newRequest.requestState.put(DevelopmentController.EXCEPTION, exception);
    newRequest.requestState.put(DevRouteInvoker.ERROR_KEY, req.requestState.get(DevRouteInvoker.ERROR_KEY));
    ApplicationContext ctx = webInjector.getAppContext();
    RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), newRequest, ctx);
    InvokeInfo newInvokeInfo = new InvokeInfo(overridenCtx, handler, RouteType.INTERNAL_SERVER_ERROR, newLoadedController, null);
    RequestContext oldContext = Current.getContext();
    Current.setContext(overridenCtx);
    try {
        return super.invokeErrorController(newInvokeInfo, newInfo, data);
    } finally {
        Current.setContext(oldContext);
    }
}
Also used : LoadedController(org.webpieces.router.impl.loader.LoadedController) Endpoint(org.webpieces.router.impl.routers.Endpoint) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) WebInjector(org.webpieces.router.impl.WebInjector) Injector(com.google.inject.Injector) SvcProxyFixedRoutes(org.webpieces.router.impl.services.SvcProxyFixedRoutes) InvokeInfo(org.webpieces.router.impl.routeinvoker.InvokeInfo) RouteInfo(org.webpieces.router.impl.routebldr.RouteInfo) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo)

Aggregations

LoadedController (org.webpieces.router.impl.loader.LoadedController)12 RequestContext (org.webpieces.ctx.api.RequestContext)7 RouteModuleInfo (org.webpieces.router.impl.model.RouteModuleInfo)5 ProxyStreamHandle (org.webpieces.router.impl.proxyout.ProxyStreamHandle)4 MethodMeta (org.webpieces.router.api.routes.MethodMeta)3 UrlPath (org.webpieces.router.impl.UrlPath)3 RenderResponse (org.webpieces.router.impl.dto.RenderResponse)3 View (org.webpieces.router.impl.dto.View)3 MatchInfo (org.webpieces.router.impl.routers.MatchInfo)3 Injector (com.google.inject.Injector)2 Method (java.lang.reflect.Method)2 Messages (org.webpieces.ctx.api.Messages)2 WebInjector (org.webpieces.router.impl.WebInjector)2 BinderAndLoader (org.webpieces.router.impl.loader.BinderAndLoader)2 RouteInfo (org.webpieces.router.impl.routebldr.RouteInfo)2 InvokeInfo (org.webpieces.router.impl.routeinvoker.InvokeInfo)2 Endpoint (org.webpieces.router.impl.routers.Endpoint)2 FContentRouter (org.webpieces.router.impl.routers.FContentRouter)2 SvcProxyFixedRoutes (org.webpieces.router.impl.services.SvcProxyFixedRoutes)2 SvcProxyForContent (org.webpieces.router.impl.services.SvcProxyForContent)2