Search in sources :

Example 1 with Messages

use of org.webpieces.ctx.api.Messages 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 2 with Messages

use of org.webpieces.ctx.api.Messages in project webpieces by deanhiller.

the class ServiceInvoker method invokeSvc.

public XFuture<Void> invokeSvc(MethodMeta meta, String i18nBundleName, Endpoint service, Processor processor, ProxyStreamHandle handle) {
    if (processor == null || meta == null || service == null || handle == null)
        throw new IllegalArgumentException("nothing can be null into this metehod");
    handle.initJustBeforeInvoke(reverseRoutes, meta);
    RequestContext requestCtx = meta.getCtx();
    LoadedController loadedController = meta.getLoadedController();
    Messages messages = new Messages(i18nBundleName, "webpieces");
    requestCtx.setMessages(messages);
    XFuture<Action> response = futureUtil.catchBlockWrap(() -> invokeService(service, meta), (t) -> convert(loadedController, t));
    return response.thenCompose(resp -> continueProcessing(handle, meta, resp, processor));
}
Also used : Action(org.webpieces.router.api.controller.actions.Action) Messages(org.webpieces.ctx.api.Messages) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 3 with Messages

use of org.webpieces.ctx.api.Messages 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)

Aggregations

Messages (org.webpieces.ctx.api.Messages)3 RequestContext (org.webpieces.ctx.api.RequestContext)2 LoadedController (org.webpieces.router.impl.loader.LoadedController)2 Method (java.lang.reflect.Method)1 Action (org.webpieces.router.api.actions.Action)1 Action (org.webpieces.router.api.controller.actions.Action)1 RenderStaticResponse (org.webpieces.router.api.dto.RenderStaticResponse)1 MethodMeta (org.webpieces.router.api.routes.MethodMeta)1 ResponseProcessor (org.webpieces.router.impl.ctx.ResponseProcessor)1