Search in sources :

Example 6 with NotFoundException

use of org.webpieces.http.exception.NotFoundException in project webpieces by deanhiller.

the class DScopedRouter method invokeRouteCatchNotFound.

/**
 * NOTE: We have to catch any exception from the method processNotFound so we can't catch and call internalServerError in this
 * method without nesting even more!!! UGH, more nesting sucks
 */
private RouterStreamRef invokeRouteCatchNotFound(RequestContext ctx, ProxyStreamHandle handler, String subPath) {
    RouterStreamRef streamRef = super.invokeRoute(ctx, handler, subPath);
    XFuture<StreamWriter> writer = streamRef.getWriter().handle((r, t) -> {
        if (t == null)
            return XFuture.completedFuture(r);
        if (t instanceof NotFoundException)
            return notFound((NotFoundException) t, ctx, handler);
        return futureUtil.failedFuture(t);
    }).thenCompose(Function.identity());
    return new RouterStreamRef("DScopedNotFoundCheck", writer, streamRef);
}
Also used : Logger(org.slf4j.Logger) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) RouterFutureUtil(org.webpieces.router.impl.RouterFutureUtil) LoggerFactory(org.slf4j.LoggerFactory) SpecificRouterInvokeException(org.webpieces.router.api.exceptions.SpecificRouterInvokeException) Function(java.util.function.Function) InternalErrorRouteFailedException(org.webpieces.router.api.exceptions.InternalErrorRouteFailedException) FutureHelper(org.webpieces.util.futures.FutureHelper) NotFoundException(org.webpieces.http.exception.NotFoundException) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) List(java.util.List) XFuture(org.webpieces.util.futures.XFuture) RequestContext(org.webpieces.ctx.api.RequestContext) Http2ErrorCode(com.webpieces.http2.api.dto.lowlevel.lib.Http2ErrorCode) Map(java.util.Map) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouterInfo(org.webpieces.router.impl.model.RouterInfo) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef) SupressedExceptionLog(org.webpieces.logging.SupressedExceptionLog) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) NotFoundException(org.webpieces.http.exception.NotFoundException) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Example 7 with NotFoundException

use of org.webpieces.http.exception.NotFoundException 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 8 with NotFoundException

use of org.webpieces.http.exception.NotFoundException in project webpieces by deanhiller.

the class InstallSslCertController method renderToken.

public XFuture<Render> renderToken(String token) {
    Current.getContext().addModifyResponse((http2Response) -> modifyResponse(http2Response));
    XFuture<Map<String, String>> future = storage.read(InstallSslCertPlugin.PLUGIN_PROPERTIES_KEY);
    return future.thenApply((props) -> {
        String result = props.get(token);
        log.info("token=" + token + " value=" + result);
        if (result == null)
            throw new NotFoundException();
        int index = result.indexOf("---");
        String authContent = result.substring(0, index);
        // check token exists in database
        return Actions.renderThis("authContent", authContent);
    });
}
Also used : NotFoundException(org.webpieces.http.exception.NotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with NotFoundException

use of org.webpieces.http.exception.NotFoundException in project webpieces by deanhiller.

the class BeanMetaData method getBeanMeta.

public BeanMeta getBeanMeta(String category, String name) {
    Map<String, BeanMeta> map = meta.get(category);
    if (map == null)
        throw new NotFoundException("Category=" + category + " not found");
    BeanMeta beanMeta = map.get(name);
    if (beanMeta == null)
        throw new NotFoundException("Bean=" + name + " not found");
    return beanMeta;
}
Also used : NotFoundException(org.webpieces.http.exception.NotFoundException) ManagedBeanMeta(org.webpieces.router.impl.mgmt.ManagedBeanMeta)

Aggregations

NotFoundException (org.webpieces.http.exception.NotFoundException)9 XFuture (org.webpieces.util.futures.XFuture)5 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)3 ProxyStreamHandle (org.webpieces.router.impl.proxyout.ProxyStreamHandle)3 Map (java.util.Map)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)2 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)2 RouterStreamRef (org.webpieces.router.impl.routeinvoker.RouterStreamRef)2 FutureHelper (org.webpieces.util.futures.FutureHelper)2 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)2 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)2 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)2 Injector (com.google.inject.Injector)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)1 RstStreamFrame (com.webpieces.http2.api.dto.lowlevel.RstStreamFrame)1 Http2ErrorCode (com.webpieces.http2.api.dto.lowlevel.lib.Http2ErrorCode)1