Search in sources :

Example 1 with ResponseProcessor

use of org.webpieces.router.impl.ctx.ResponseProcessor in project webpieces by deanhiller.

the class RouteInvoker method invokeImpl.

public CompletableFuture<Void> invokeImpl(MatchResult result, Service<MethodMeta, Action> service, RequestContext requestCtx, ResponseStreamer responseCb) {
    RouteMeta meta = result.getMeta();
    ResponseProcessor processor = new ResponseProcessor(requestCtx, reverseRoutes, reverseTranslator, meta, responseCb);
    if (meta.getRoute().getRouteType() == RouteType.STATIC) {
        StaticRoute route = (StaticRoute) meta.getRoute();
        boolean isOnClassPath = route.getIsOnClassPath();
        RenderStaticResponse resp = new RenderStaticResponse(route.getTargetCacheLocation(), isOnClassPath);
        if (route.isFile()) {
            resp.setFilePath(route.getFileSystemPath());
        } else {
            String relativeUrl = result.getPathParams().get("resource");
            resp.setRelativeFile(route.getFileSystemPath(), relativeUrl);
        }
        return processor.renderStaticResponse(resp);
    }
    Object obj = meta.getControllerInstance();
    if (obj == null)
        throw new IllegalStateException("Someone screwed up, as controllerInstance should not be null at this point, bug");
    Method method = meta.getMethod();
    if (service == null)
        throw new IllegalStateException("Bug, service should never be null at this point");
    Messages messages = new Messages(meta.getI18nBundleName(), "webpieces");
    requestCtx.setMessages(messages);
    RequestLocalCtx.set(processor);
    Current.setContext(requestCtx);
    CompletableFuture<Action> response;
    try {
        response = invokeMethod(service, obj, method, meta);
    } finally {
        RequestLocalCtx.set(null);
        Current.setContext(null);
    }
    CompletableFuture<Void> future = response.thenCompose(resp -> continueProcessing(processor, resp, responseCb));
    return future;
}
Also used : Action(org.webpieces.router.api.actions.Action) Messages(org.webpieces.ctx.api.Messages) ResponseProcessor(org.webpieces.router.impl.ctx.ResponseProcessor) Method(java.lang.reflect.Method) RenderStaticResponse(org.webpieces.router.api.dto.RenderStaticResponse)

Example 2 with ResponseProcessor

use of org.webpieces.router.impl.ctx.ResponseProcessor in project webpieces by deanhiller.

the class RouteInvoker method finalFailure.

public Void finalFailure(ResponseStreamer responseCb, Throwable e, RequestContext requestCtx) {
    log.error("This is a final(secondary failure) trying to render the Internal Server Error Route", e);
    ResponseProcessor processor = new ResponseProcessor(requestCtx, reverseRoutes, reverseTranslator, null, responseCb);
    processor.failureRenderingInternalServerErrorPage(e);
    return null;
}
Also used : ResponseProcessor(org.webpieces.router.impl.ctx.ResponseProcessor)

Aggregations

ResponseProcessor (org.webpieces.router.impl.ctx.ResponseProcessor)2 Method (java.lang.reflect.Method)1 Messages (org.webpieces.ctx.api.Messages)1 Action (org.webpieces.router.api.actions.Action)1 RenderStaticResponse (org.webpieces.router.api.dto.RenderStaticResponse)1