Search in sources :

Example 1 with SvcProxyFixedRoutes

use of org.webpieces.router.impl.services.SvcProxyFixedRoutes 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 SvcProxyFixedRoutes

use of org.webpieces.router.impl.services.SvcProxyFixedRoutes 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)

Example 3 with SvcProxyFixedRoutes

use of org.webpieces.router.impl.services.SvcProxyFixedRoutes in project webpieces by deanhiller.

the class DevRouteInvoker method invokeNotFound.

/**
 * This one is definitely special
 */
@Override
public XFuture<Void> invokeNotFound(InvokeInfo invokeInfo, Endpoint info, RouteData data) {
    // special case for if stuff didn't compile and we flag it
    Throwable exc = (Throwable) invokeInfo.getRequestCtx().getRequest().requestState.get(ERROR_KEY);
    if (exc != null) {
        log.error("Could not compile your code", exc);
        RouteInfoForInternalError error = new RouteInfoForInternalError(exc);
        return invokeErrorController(invokeInfo, info, error);
    }
    RequestContext requestCtx = invokeInfo.getRequestCtx();
    ProxyStreamHandle handler = invokeInfo.getHandler();
    RouteInfoForNotFound notFoundData = (RouteInfoForNotFound) data;
    NotFoundException notFoundExc = notFoundData.getNotFoundException();
    RouterRequest req = requestCtx.getRequest();
    if (notFoundData.getNotFoundException() == null) {
        throw new IllegalArgumentException("must have not found exception to be here");
    } else if (req.queryParams.containsKey(DevelopmentController.NOT_FOUND_KEY)) {
        // This is a callback so render the original webapp developer's not found page into the iframe
        return super.invokeNotFound(invokeInfo, info, data);
    }
    // ok, in dev mode, we hijack the not found page with one with a route list AND an iframe containing the developers original
    // notfound page
    log.error("(Development only log message) Route not found!!! Either you(developer) typed the wrong url OR you have a bad route.  Either way,\n" + " something needs a'fixin.  req=" + req, notFoundExc);
    Injector webAppInjector = webInjector.getCurrentInjector();
    RouteInfo routeInfo = new RouteInfo(new RouteModuleInfo("", null), "/org/webpieces/devrouter/impl/DevelopmentController.notFound");
    SvcProxyFixedRoutes svcProxy = new SvcProxyFixedRoutes(serviceInvoker, futureUtil);
    LoadedController newLoadedController = controllerFinder.loadGenericController(webAppInjector, routeInfo).getLoadedController();
    Endpoint newInfo = new Endpoint(svcProxy);
    String reason = "Your route was not found in routes table";
    if (notFoundExc != null)
        reason = notFoundExc.getMessage();
    RouterRequest newRequest = new RouterRequest();
    newRequest.putMultipart("webpiecesError", "Exception message=" + reason);
    newRequest.putMultipart("url", req.relativePath);
    newRequest.isHttps = req.isHttps;
    newRequest.isBackendRequest = req.isBackendRequest;
    newRequest.originalRequest = req.originalRequest;
    newRequest.requestState.put(DevelopmentController.ORIGINAL_REQUEST, req);
    ApplicationContext ctx = webInjector.getAppContext();
    RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), newRequest, ctx);
    InvokeInfo newInvokeInfo = new InvokeInfo(overridenCtx, handler, RouteType.NOT_FOUND, newLoadedController, null);
    RequestContext oldContext = Current.getContext();
    Current.setContext(overridenCtx);
    try {
        return super.invokeNotFound(newInvokeInfo, newInfo, data);
    } finally {
        Current.setContext(oldContext);
    }
}
Also used : LoadedController(org.webpieces.router.impl.loader.LoadedController) NotFoundException(org.webpieces.http.exception.NotFoundException) RouteInfoForNotFound(org.webpieces.router.impl.services.RouteInfoForNotFound) 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) RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) InvokeInfo(org.webpieces.router.impl.routeinvoker.InvokeInfo) RouteInfo(org.webpieces.router.impl.routebldr.RouteInfo) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo)

Aggregations

SvcProxyFixedRoutes (org.webpieces.router.impl.services.SvcProxyFixedRoutes)3 Injector (com.google.inject.Injector)2 WebInjector (org.webpieces.router.impl.WebInjector)2 LoadedController (org.webpieces.router.impl.loader.LoadedController)2 RouteModuleInfo (org.webpieces.router.impl.model.RouteModuleInfo)2 ProxyStreamHandle (org.webpieces.router.impl.proxyout.ProxyStreamHandle)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 NotFoundException (org.webpieces.http.exception.NotFoundException)1 Action (org.webpieces.router.api.controller.actions.Action)1 MethodMeta (org.webpieces.router.api.routes.MethodMeta)1 AbstractRouter (org.webpieces.router.impl.routers.AbstractRouter)1 DScopedRouter (org.webpieces.router.impl.routers.DScopedRouter)1 EInternalErrorRouter (org.webpieces.router.impl.routers.EInternalErrorRouter)1 ENotFoundRouter (org.webpieces.router.impl.routers.ENotFoundRouter)1 EScopedRouter (org.webpieces.router.impl.routers.EScopedRouter)1 RouteInfoForInternalError (org.webpieces.router.impl.services.RouteInfoForInternalError)1 RouteInfoForNotFound (org.webpieces.router.impl.services.RouteInfoForNotFound)1