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());
}
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));
}
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;
}
Aggregations