use of org.webpieces.router.impl.proxyout.ProxyStreamHandle in project webpieces by deanhiller.
the class EchoStreamingClient method stream.
public StreamRef stream(ResponseStreamHandle handle) {
ProxyStreamHandle h = (ProxyStreamHandle) handle;
Http2Request req = Current.request().originalRequest;
Http2Response response = h.createBaseResponse(req, "application/ndjson", 200, "OK");
try {
StreamWriter writer = h.process(response).get();
return new ProxyStreamRef(new EchoWriter(writer));
} catch (InterruptedException | ExecutionException e) {
throw SneakyThrow.sneak(e);
}
}
use of org.webpieces.router.impl.proxyout.ProxyStreamHandle in project webpieces by deanhiller.
the class AbstractRouteInvoker method invokeSvc.
private XFuture<Void> invokeSvc(InvokeInfo invokeInfo, Endpoint dynamicInfo, RouteData data, Processor processor) {
LoadedController loadedController = invokeInfo.getLoadedController();
ProxyStreamHandle handle = invokeInfo.getHandler();
RequestContext requestCtx = invokeInfo.getRequestCtx();
MethodMeta methodMeta = new MethodMeta(loadedController, requestCtx, invokeInfo.getRouteType(), data);
String i18nBundleName = "";
return serviceInvoker.invokeSvc(methodMeta, i18nBundleName, dynamicInfo, processor, handle);
}
use of org.webpieces.router.impl.proxyout.ProxyStreamHandle in project webpieces by deanhiller.
the class DevRouteInvoker method invokeDevelopmentErrorPage.
private XFuture<Void> invokeDevelopmentErrorPage(InvokeInfo invokeInfo, RouteInfoForInternalError data) {
RequestContext requestCtx = invokeInfo.getRequestCtx();
ProxyStreamHandle handler = invokeInfo.getHandler();
RouterRequest req = requestCtx.getRequest();
Throwable exception = data.getException();
Injector webAppInjector = webInjector.getCurrentInjector();
RouteInfo routeInfo = new RouteInfo(new RouteModuleInfo("", null), "/org/webpieces/devrouter/impl/DevelopmentController.internalError");
SvcProxyFixedRoutes svcProxy = new SvcProxyFixedRoutes(serviceInvoker, futureUtil);
LoadedController newLoadedController = controllerFinder.loadGenericController(webAppInjector, routeInfo).getLoadedController();
Endpoint newInfo = new Endpoint(svcProxy);
RouterRequest newRequest = new RouterRequest();
newRequest.putMultipart("url", req.relativePath);
newRequest.isHttps = req.isHttps;
newRequest.isBackendRequest = req.isBackendRequest;
newRequest.originalRequest = req.originalRequest;
newRequest.requestState.put(DevelopmentController.ORIGINAL_REQUEST, req);
newRequest.requestState.put(DevelopmentController.EXCEPTION, exception);
newRequest.requestState.put(DevRouteInvoker.ERROR_KEY, req.requestState.get(DevRouteInvoker.ERROR_KEY));
ApplicationContext ctx = webInjector.getAppContext();
RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), newRequest, ctx);
InvokeInfo newInvokeInfo = new InvokeInfo(overridenCtx, handler, RouteType.INTERNAL_SERVER_ERROR, newLoadedController, null);
RequestContext oldContext = Current.getContext();
Current.setContext(overridenCtx);
try {
return super.invokeErrorController(newInvokeInfo, newInfo, data);
} finally {
Current.setContext(oldContext);
}
}
use of org.webpieces.router.impl.proxyout.ProxyStreamHandle in project webpieces by deanhiller.
the class EScopedRouter method invokeRouter.
private RouterStreamRef invokeRouter(AbstractRouter router, RequestContext ctx, ProxyStreamHandle handler, boolean isCorsRequest) {
RouterStreamRef streamRef = invokeWithProtection(router, ctx, handler, isCorsRequest);
XFuture<StreamWriter> writer = streamRef.getWriter().handle((r, t) -> {
if (t == null)
return XFuture.completedFuture(r);
XFuture<StreamWriter> fut = new XFuture<>();
Throwable exc = convert(router.getMatchInfo(), t);
fut.completeExceptionally(exc);
return fut;
}).thenCompose(Function.identity());
return new RouterStreamRef("eScoped2", writer, streamRef);
}
use of org.webpieces.router.impl.proxyout.ProxyStreamHandle in project webpieces by deanhiller.
the class StreamProxy method openStream.
@Override
public RouterStreamRef openStream(MethodMeta meta, ProxyStreamHandle handle) {
RequestContext requestCtx = meta.getCtx();
LoadedController loadedController = meta.getLoadedController();
Object instance = loadedController.getControllerInstance();
Method controllerMethod = loadedController.getControllerMethod();
Parameter[] parameters = loadedController.getParameters();
if (parameters.length != 1)
throw new IllegalArgumentException("Your method='" + controllerMethod + "' MUST one parameter and does not. It needs to take a RouterStreamHandler");
else if (!ResponseStreamHandle.class.equals(parameters[0].getType()))
throw new IllegalArgumentException("The single parameter must be RouterStreamHandle and was not for this method='" + controllerMethod + "'");
else if (!StreamRef.class.equals(controllerMethod.getReturnType()))
throw new IllegalArgumentException("The return value must be a subclass of StreamRef and was not for this method='" + controllerMethod + "'");
StreamRef streamRef = invokeStream(meta, controllerMethod, instance, requestCtx, handle);
XFuture<StreamWriter> writer = streamRef.getWriter();
XFuture<StreamWriter> newFuture = futureUtil.catchBlockWrap(() -> writer, (t) -> convert(loadedController, t));
Function<CancelReason, XFuture<Void>> cancelFunc = (reason) -> streamRef.cancel(reason);
return new RouterStreamRef("streamProxy", newFuture, cancelFunc);
}
Aggregations