use of org.webpieces.router.api.dto.RedirectResponse in project webpieces by deanhiller.
the class ResponseProcessor method createRawRedirect.
public CompletableFuture<Void> createRawRedirect(RawRedirect controllerResponse) {
String url = controllerResponse.getUrl();
if (url.startsWith("http")) {
return wrapFunctionInContext(() -> responseCb.sendRedirect(new RedirectResponse(url)));
}
RouterRequest request = ctx.getRequest();
RedirectResponse redirectResponse = new RedirectResponse(false, request.isHttps, request.domain, request.port, url);
return wrapFunctionInContext(() -> responseCb.sendRedirect(redirectResponse));
}
use of org.webpieces.router.api.dto.RedirectResponse in project webpieces by deanhiller.
the class ResponseProcessor method createRedirect.
private CompletableFuture<Void> createRedirect(RouteId id, Map<String, Object> args, boolean isAjaxRedirect) {
if (responseSent)
throw new IllegalStateException("You already sent a response. do not call Actions.redirect or Actions.render more than once");
responseSent = true;
RouterRequest request = ctx.getRequest();
Method method = matchedMeta.getMethod();
RouteMeta nextRequestMeta = reverseRoutes.get(id);
if (nextRequestMeta == null)
throw new IllegalReturnValueException("Route=" + id + " returned from method='" + method + "' was not added in the RouterModules");
else if (!nextRequestMeta.getRoute().matchesMethod(HttpMethod.GET))
throw new IllegalReturnValueException("method='" + method + "' is trying to redirect to routeid=" + id + " but that route is not a GET method route and must be");
Route route = nextRequestMeta.getRoute();
Map<String, String> keysToValues = reverseTranslator.formMap(method, route.getPathParamNames(), args);
Set<String> keySet = keysToValues.keySet();
List<String> argNames = route.getPathParamNames();
if (keySet.size() != argNames.size()) {
throw new IllegalReturnValueException("Method='" + method + "' returns a Redirect action with wrong number of arguments. args=" + keySet.size() + " when it should be size=" + argNames.size());
}
String path = route.getFullPath();
for (String name : argNames) {
String value = keysToValues.get(name);
if (value == null)
throw new IllegalArgumentException("Method='" + method + "' returns a Redirect that is missing argument key=" + name + " to form the url on the redirect");
path = path.replace("{" + name + "}", value);
}
RedirectResponse redirectResponse = new RedirectResponse(isAjaxRedirect, request.isHttps, request.domain, request.port, path);
return wrapFunctionInContext(() -> responseCb.sendRedirect(redirectResponse));
}
use of org.webpieces.router.api.dto.RedirectResponse in project webpieces by deanhiller.
the class ProxyResponse method sendRedirectAndClearCookie.
public void sendRedirectAndClearCookie(RouterRequest req, String badCookieName) {
RedirectResponse httpResponse = new RedirectResponse(false, req.isHttps, req.domain, req.port, req.relativePath);
Http2Response response = createRedirect(httpResponse);
responseCreator.addDeleteCookie(response, badCookieName);
log.info("sending REDIRECT(due to bad cookie) response responseSender=" + stream);
stream.sendResponse(response);
channelCloser.closeIfNeeded(request, stream);
}
Aggregations