use of org.springframework.web.servlet.view.RedirectView in project spring-framework by spring-projects.
the class ViewMethodReturnValueHandlerTests method returnViewRedirect.
@Test
public void returnViewRedirect() throws Exception {
RedirectView redirectView = new RedirectView("testView");
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
MethodParameter param = createReturnValueParam("view");
this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest);
assertSame(redirectView, this.mavContainer.getView());
assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
}
use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.
the class SigninController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse resp) throws Exception {
logger.info("receive url path: " + request.getContextPath() + "," + request.getRequestURI() + ", " + request.getServletPath() + ", parameters: " + request.getQueryString());
boolean failed = false;
String message = null;
String username = request.getParameter("name");
if (username != null) {
username = username.trim().toLowerCase();
//find the user from the system cache
AppUser appUser = this.frameworkContext.getAuth().findUserByName(username);
//sign in process
boolean authed = this.frameworkContext.getAuth().login(appUser, request);
if (//display
authed) {
String view = getLoginSuccessView();
//if admin user, and setup not done yet, send to setup.
if (appUser.isAdminUser() && !frameworkContext.getMyperfConfig().isConfigured())
view = this.getSetupView();
else if (!appUser.isAdminUser() && !appUser.isVerified()) {
failed = true;
message = "Your signup has not been confirmed by any administrator user yet.";
}
if (!failed) {
logger.info(appUser.getName() + " login, redirect to " + view);
return new ModelAndView(new RedirectView(view));
}
} else //if(appUser!=null && appUser.match(request.getParameter("pd"))
{
failed = true;
message = DEFAULT_ERROR;
}
}
//if(username!=null)
//not authenticated? Try again
//TODO add retry count
long server_ts = System.currentTimeMillis();
int seed = (int) (Math.random() * Integer.MAX_VALUE);
ModelAndView mv = new ModelAndView(getLoginFormView());
mv.addObject("name", username);
if (failed)
mv.addObject("message", message);
mv.addObject("help_key", "start");
mv.addObject("server_ts", server_ts);
//ars: authentication random seed
mv.addObject("ars", seed);
mv.addObject("setup", this.frameworkContext.getMyperfConfig().isConfigured() ? 1 : 0);
//add store them in session
request.getSession(true).setAttribute(AppUser.SERVER_TS, new Long(server_ts));
request.getSession().setAttribute(AppUser.RANDOM_SEED, new Integer(seed));
return mv;
}
use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.
the class MyPerfBaseController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
setupDebug(req);
boolean debug = this.isDebug(req);
if (debug)
logger.info("receive url path: " + req.getContextPath() + "," + req.getRequestURI() + ", " + req.getServletPath() + ", parameters: " + req.getQueryString());
AppUser user = retrieveAppUser(req);
if (//check if user valid when require login
this.requireLogin && user == null) {
if (this.nosessView != null)
return new ModelAndView(new RedirectView(nosessView));
return respondFailure("Session expired. Please relogin and try again.", req);
} else if (this.requireLogin && !user.isVerified()) {
//TODO use a message view
return this.respondFailure("New user request has not been verified by administrator yet. Please contact administrator by email " + this.frameworkContext.getMyperfConfig().getAdminEmail() + ".", req);
}
return handleRequestImpl(req, resp);
}
use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.
the class PerfController method handleRequestImpl.
//private MyPerfContext frameworkContext;
@Override
protected ModelAndView handleRequestImpl(HttpServletRequest request, HttpServletResponse response) throws Exception {
String pg = request.getParameter("pg");
String tgtPage = pg;
if (tgtPage != null)
tgtPage = tgtPage.trim().toLowerCase();
if (tgtPage == null || tgtPage.isEmpty() || (!pageMap.containsKey(tgtPage) && !noSessionPageMap.containsKey(tgtPage)))
tgtPage = this.defaultView;
else if (pageMap.containsKey(tgtPage) && !WebAppUtil.hasValidSession(request)) {
return new ModelAndView(new RedirectView(this.getNosessView()));
} else if (pageMap.containsKey(tgtPage)) {
tgtPage = pageMap.get(tgtPage);
} else
tgtPage = noSessionPageMap.get(tgtPage);
ModelAndView mv = new ModelAndView(tgtPage);
if (WebAppUtil.hasValidSession(request)) {
mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().listDbsByUserInfo(WebAppUtil.findUserFromRequest(request), retrieveAppUser(request).isRestrictedUser()));
mv.addObject("mydbSize", this.frameworkContext.getDbInfoManager().getMyDatabases(WebAppUtil.findUserFromRequest(request), retrieveAppUser(request).isRestrictedUser()).size());
} else {
mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().getClusters().keySet());
mv.addObject("mydbSize", 0);
}
mv.addObject("hours", HOURS);
mv.addObject("dbMap", this.frameworkContext.getDbInfoManager().getClusters());
mv.addObject("help_key", pg);
mv.addObject("config", this.frameworkContext.getMyperfConfig());
mv.addObject("scanner_running", this.frameworkContext.getAutoScanner().isRunning());
mv.addObject("setup", this.frameworkContext.getMyperfConfig().isConfigured() ? 1 : 0);
if ("sp".equals(pg) || "scatterplot".equals(pg) || "m".equals(pg) || "metrics".equalsIgnoreCase(pg))
mv.addObject("udms", this.frameworkContext.getMetricsList());
return mv;
}
use of org.springframework.web.servlet.view.RedirectView in project opennms by OpenNMS.
the class AlarmDetailController method removeJournalMemo.
public ModelAndView removeJournalMemo(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
int alarmId;
String alarmIdString = "";
// Try to parse alarm ID from string to integer
try {
alarmIdString = httpServletRequest.getParameter("alarmId");
alarmId = Integer.parseInt(alarmIdString);
m_webAlarmRepository.removeReductionKeyMemo(alarmId);
return new ModelAndView(new RedirectView("detail.htm", true), "id", alarmId);
} catch (NumberFormatException e) {
logger.error("Could not parse alarm ID '{}' to integer.", httpServletRequest.getParameter("alarmId"));
throw new ServletException("Could not parse alarm ID " + httpServletRequest.getParameter("alarmId") + " to integer.");
}
}
Aggregations