use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class BeansController method postArray.
public Redirect postArray(UserDto user, List<UserDto> users) {
lib1.validateUser(user);
Current.validation().addError("user.accounts[0].addresses[0].street", "This is too ugly a street name");
if (Current.validation().hasErrors()) {
RequestContext ctx = Current.getContext();
return Actions.redirectFlashAllSecure(BeansRouteId.ARRAY_FORM_ROUTE, ctx, "password");
}
return Actions.redirect(BeansRouteId.ARRAY_FORM_ROUTE);
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class BeansController method postUser.
public Redirect postUser(UserDto user, String password) {
// Validate any other stuff you need here adding errors and such
lib1.validateUser(user);
RequestContext ctx = Current.getContext();
if (Current.validation().hasErrors()) {
Current.flash().setMessage("Invalid values below");
return Actions.redirectFlashAllSecure(BeansRouteId.USER_FORM_ROUTE, ctx, "password");
}
lib.saveUser(user);
return Actions.redirect(BeansRouteId.LIST_USERS_ROUTE);
}
use of org.webpieces.ctx.api.RequestContext 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);
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class ResponseProcessorAppError method createRenderResponse.
public XFuture<Void> createRenderResponse(MethodMeta meta, RenderImpl controllerResponse, ProxyStreamHandle handle) {
LoadedController loadedController = meta.getLoadedController();
String controllerName = loadedController.getControllerInstance().getClass().getName();
String methodName = loadedController.getControllerMethod().getName();
String relativeOrAbsolutePath = controllerResponse.getRelativeOrAbsolutePath();
if (relativeOrAbsolutePath == null) {
relativeOrAbsolutePath = methodName + ".html";
}
Map<String, Object> pageArgs = controllerResponse.getPageArgs();
RequestContext ctx = meta.getCtx();
// Add context as a page arg:
pageArgs.put("_context", ctx);
pageArgs.put("_session", ctx.getSession());
pageArgs.put("_flash", ctx.getFlash());
pageArgs.put("_appContext", ctx.getApplicationContext());
View view = new View(controllerName, methodName, relativeOrAbsolutePath);
RenderResponse resp = new RenderResponse(view, pageArgs, RouteType.INTERNAL_SERVER_ERROR);
return handle.sendRenderHtml(resp);
}
use of org.webpieces.ctx.api.RequestContext in project webpieces by deanhiller.
the class ResponseProcessorHtml method createRawRedirect.
public XFuture<Void> createRawRedirect(MethodMeta meta, RawRedirect controllerResponse, ProxyStreamHandle handle) {
RequestContext ctx = meta.getCtx();
String url = controllerResponse.getUrl();
if (url.startsWith("http")) {
return handle.sendRedirect(new RedirectResponse(url));
}
RouterRequest request = ctx.getRequest();
RedirectResponse redirectResponse = new RedirectResponse(false, request.isHttps, request.domain, request.port, url);
return handle.sendRedirect(redirectResponse);
}
Aggregations