try {
if (page instanceof Class) page = componentClassResolver.resolvePageClassNameToPageName(((Class) page).getName());
Link link = page instanceof Link ? (Link) page : linkSource.createPageRenderLink(page.toString(), false, exceptionContext);
if (request.isXHR()) {
OutputStream os = response.getOutputStream("application/json;charset=UTF-8");
os.write(("{\"redirectURL\":\"" + link.toAbsoluteURI() + "\"}").getBytes());
os.close();
} else response.sendRedirect(link);
}
// The above could throw an exception if we are already on a render request, but it's
// user's responsibility not to abuse the mechanism