Search in sources :

Example 1 with RouteInfoForInternalError

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

the class EInternalErrorRouter method invokeErrorRoute.

public XFuture<StreamWriter> invokeErrorRoute(RequestContext ctx, ProxyStreamHandle handle, Throwable exc) {
    Endpoint info = new Endpoint(svc);
    RouteInfoForInternalError data = new RouteInfoForInternalError(exc);
    InvokeInfo invokeInfo = new InvokeInfo(ctx, handle, RouteType.INTERNAL_SERVER_ERROR, loadedController, i18nBundleName);
    return invoker.invokeErrorController(invokeInfo, info, data).thenApply(voidd -> new NullStreamWriter());
}
Also used : RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) InvokeInfo(org.webpieces.router.impl.routeinvoker.InvokeInfo)

Example 2 with RouteInfoForInternalError

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

the class LoginFilter method filter.

@Override
public XFuture<Action> filter(MethodMeta meta, Service<MethodMeta, Action> next) {
    if (meta.getRoute() instanceof RouteInfoForNotFound || meta.getRoute() instanceof RouteInfoForInternalError) {
        // no need to login for routeinfoNotFound NOR internal error pages
        return next.invoke(meta);
    } else if (patternToMatch != null) {
        // If we have a securePath, we act as a NotFoundFilter so we want to redirect to Login ONLY if this is a secure path request
        // This hides known vs. unknown pages
        Matcher matcher = patternToMatch.matcher(meta.getCtx().getRequest().relativePath);
        if (!matcher.matches())
            return next.invoke(meta);
    }
    Session session = Current.session();
    if (session.containsKey(token)) {
        Current.addModifyResponse(resp -> addCacheHeaders(resp));
        return futureUtil.finallyBlock(() -> next.invoke(meta), () -> clearSecureFields(meta));
    }
    RouterRequest request = Current.request();
    if (request.isAjaxRequest) {
        if (request.referrer != null) {
            Current.flash().put("url", request.referrer);
            Current.flash().keep(true);
        }
        return XFuture.completedFuture(Actions.ajaxRedirect(loginRoute));
    } else if (request.method == HttpMethod.GET) {
        // store url requested in flash so after logging in, we can redirect the user
        // back to the original page
        Current.flash().put("url", request.relativePath);
        Current.flash().keep(true);
    } else if (request.method == HttpMethod.POST) {
        // adding a validation error avoids the posting of the form so they post AFTER logging in
        if (request.referrer != null)
            Current.flash().put("url", request.referrer);
        else
            Current.flash().put("url", request.relativePath);
        Set<String> mySet = new HashSet<>(Arrays.asList(secureFields));
        Current.getContext().moveFormParamsToFlash(mySet);
        Current.flash().keep(true);
    }
    // redirect to login page..
    return XFuture.completedFuture(Actions.redirect(loginRoute));
}
Also used : Matcher(java.util.regex.Matcher) RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) RouteInfoForNotFound(org.webpieces.router.impl.services.RouteInfoForNotFound) Session(org.webpieces.ctx.api.Session) RouterRequest(org.webpieces.ctx.api.RouterRequest) HashSet(java.util.HashSet)

Example 3 with RouteInfoForInternalError

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

the class DevRouteInvoker method invokeErrorController.

@Override
public XFuture<Void> invokeErrorController(InvokeInfo invokeInfo, Endpoint dynamicInfo, RouteData data) {
    RouteInfoForInternalError error = (RouteInfoForInternalError) data;
    Throwable exception = error.getException();
    if (exception instanceof SimulateInternalError) {
        // just use the original route at this point
        return super.invokeErrorController(invokeInfo, dynamicInfo, data);
    }
    return invokeDevelopmentErrorPage(invokeInfo, error);
}
Also used : RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) SimulateInternalError(org.webpieces.router.impl.routers.SimulateInternalError)

Example 4 with RouteInfoForInternalError

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

Example 5 with RouteInfoForInternalError

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

the class DevRouteInvoker method invokeHtmlController.

@Override
public RouterStreamRef invokeHtmlController(InvokeInfo invokeInfo, StreamService dynamicInfo, 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);
        XFuture<Void> future = invokeDevelopmentErrorPage(invokeInfo, error);
        XFuture<StreamWriter> writer = future.thenApply(voidd -> new NullWriter());
        return new RouterStreamRef("notCompileError", writer, null);
    }
    if (invokeInfo.getRequestCtx().getRequest().queryParams.containsKey(DevelopmentController.INTERNAL_ERROR_KEY)) {
        // need to simulate the error to show production page
        throw new SimulateInternalError();
    }
    // }
    return super.invokeHtmlController(invokeInfo, dynamicInfo, data);
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouteInfoForInternalError(org.webpieces.router.impl.services.RouteInfoForInternalError) SimulateInternalError(org.webpieces.router.impl.routers.SimulateInternalError) NullWriter(org.webpieces.router.impl.routeinvoker.NullWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Aggregations

RouteInfoForInternalError (org.webpieces.router.impl.services.RouteInfoForInternalError)5 InvokeInfo (org.webpieces.router.impl.routeinvoker.InvokeInfo)2 SimulateInternalError (org.webpieces.router.impl.routers.SimulateInternalError)2 RouteInfoForNotFound (org.webpieces.router.impl.services.RouteInfoForNotFound)2 Injector (com.google.inject.Injector)1 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 Session (org.webpieces.ctx.api.Session)1 NotFoundException (org.webpieces.http.exception.NotFoundException)1 WebInjector (org.webpieces.router.impl.WebInjector)1 LoadedController (org.webpieces.router.impl.loader.LoadedController)1 RouteModuleInfo (org.webpieces.router.impl.model.RouteModuleInfo)1 ProxyStreamHandle (org.webpieces.router.impl.proxyout.ProxyStreamHandle)1 RouteInfo (org.webpieces.router.impl.routebldr.RouteInfo)1 NullWriter (org.webpieces.router.impl.routeinvoker.NullWriter)1 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)1 Endpoint (org.webpieces.router.impl.routers.Endpoint)1 SvcProxyFixedRoutes (org.webpieces.router.impl.services.SvcProxyFixedRoutes)1