List of usage examples for org.springframework.web.servlet.view RedirectView RedirectView
public RedirectView()
From source file:org.impalaframework.extension.mvc.util.RequestModelHelperTest.java
public void testIsRedirect() throws Exception { assertTrue(RequestModelHelper.isRedirect(new ModelAndView(new RedirectView()))); assertTrue(RequestModelHelper.isRedirect(new ModelAndView("redirect:view"))); assertFalse(RequestModelHelper.isRedirect(new ModelAndView("view"))); }
From source file:org.shareok.data.webserv.ServerController.java
@RequestMapping("/server/update") public ModelAndView serverUpdate(RedirectAttributes redirectAttrs, HttpServletRequest request, @ModelAttribute("SpringWeb") RepoServer server) { ModelAndView model = new ModelAndView(); RedirectView view = new RedirectView(); view.setContextRelative(true);// w w w . jav a2 s .c o m RepoServer existingServer = null; /** * Some server side validation code: */ boolean hasError = false; String serverId = (String) request.getParameter("serverId"); if (null == server) { redirectAttrs.addFlashAttribute("errorMessage", "The server information is empty"); hasError = true; } String serverName = server.getServerName(); if (null == serverName || "".equals(serverName)) { redirectAttrs.addFlashAttribute("errorMessage", "TThe server name is empty"); hasError = true; } if (null == serverId) { redirectAttrs.addFlashAttribute("errorMessage", "The server ID is empty"); hasError = true; } else if (serverId.equals("-1")) { existingServer = serverService.findServerByName(serverName); if (null != existingServer) { redirectAttrs.addFlashAttribute("errorMessage", "The server name has been used"); hasError = true; } } if (hasError == true) { view.setUrl("serverError.jsp"); model.setView(view); return model; } if (null != serverId && serverId.equals("-1")) { RepoServer newServer = serverService.addServer(server); Map<String, String> repoTypeServerFieldInfo = getRepoTypeServerFieldInfo(request, serverService.getRepoTypeServerFields(newServer.getRepoType())); serverService.updateRepoTypeServerFieldInfo(repoTypeServerFieldInfo, newServer); view.setUrl("/server/config"); redirectAttrs.addFlashAttribute("message", "The new server \"" + newServer.getServerName() + "\" has been added successfully!"); model.setView(view); } else if (null != serverId && !serverId.equals("-1")) { existingServer = serverService.updateServer(server); Map<String, String> repoTypeServerFieldInfo = getRepoTypeServerFieldInfo(request, serverService.getRepoTypeServerFields(existingServer.getRepoType())); serverService.updateRepoTypeServerFieldInfo(repoTypeServerFieldInfo, server); view.setUrl("/server/config"); model.setView(view); redirectAttrs.addFlashAttribute("message", "The server \"" + existingServer.getServerName() + "\" has been updated successfully!"); return model; } return model; }
From source file:org.unidle.web.BuildTimestampInterceptorTest.java
@Test public void testPostHandleWithRedirectView() throws Exception { modelAndView.setView(new RedirectView()); subject.postHandle(null, null, null, modelAndView); assertThat(modelAndView.getModel()).isEmpty(); }
From source file:ru.mystamps.web.controller.AccountController.java
@GetMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY) public View showActivationFormWithKey(@PathVariable("key") String activationKey, RedirectAttributes redirectAttributes) { redirectAttributes.addAttribute("key", activationKey); RedirectView view = new RedirectView(); view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); view.setUrl(Url.ACTIVATE_ACCOUNT_PAGE); return view;/*www . j a v a 2 s . c om*/ }
From source file:ru.mystamps.web.controller.CollectionController.java
@GetMapping(Url.INFO_COLLECTION_BY_ID_PAGE) public View showInfoById(@PathVariable("slug") String slug, HttpServletResponse response) throws IOException { if (slug == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; }/*from w ww .j av a2 s. c o m*/ CollectionInfoDto collection = collectionService.findBySlug(slug); if (collection == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } RedirectView view = new RedirectView(); view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); view.setUrl(Url.INFO_COLLECTION_PAGE); return view; }
From source file:org.zilverline.web.CacheController.java
/** * Handles form submission by extracting the corresponding archive. * /*from ww w .j av a 2 s . co m*/ * @param command the DocumentFromCacheForm, containing document information. * * @return ModelAndView the view with updated model * * @throws ServletException on error */ public ModelAndView onSubmit(Object command) throws ServletException { DocumentFromCacheForm df = (DocumentFromCacheForm) command; String colName = df.getCollection(); log.debug("CacheController for " + colName); FileSystemCollection thisCollection = (FileSystemCollection) collectionManager.getCollectionByName(colName); boolean canForward = false; try { if (thisCollection != null) { if (!thisCollection.getArchiveCache().contains(df.getArchive())) { // not already in cache for this collection log.debug("CacheController cache miss for " + colName); // but the file might be there from a previous time, before // possible restart File f = new File(thisCollection.getCacheDirWithManagerDefaults(), df.getFile()); if (f.exists()) { log.debug("CacheController cache from previous life for " + f); canForward = true; // the file must be from archive, add the zip to the // cache, without having extracted it. // this is a risk, since the some files from the archive // in cache may have been deleted thisCollection.getArchiveCache().add(df.getArchive()); } else { File zipFile = new File(thisCollection.getContentDir(), df.getArchive()); if (collectionManager.expandArchive(thisCollection, zipFile)) { thisCollection.getArchiveCache().add(df.getArchive()); canForward = true; } else { log.debug("CacheController can't get file from archive for: " + zipFile); } } } else { log.debug("CacheController cache hit for " + colName); canForward = true; } } else { log.error("no valid collection"); } } catch (IndexException e) { throw new ServletException(e); } if (canForward) { // the archive has been extracted, redirect to file log.debug("redirecting from CacheController to: " + thisCollection.getCacheUrlWithManagerDefaults() + df.getFile()); RedirectView v = new RedirectView(); v.setUrl(thisCollection.getCacheUrlWithManagerDefaults() + df.getFile()); return new ModelAndView(v); } log.debug("returning from CacheController to view: " + getSuccessView() + " with " + colName); return new ModelAndView(getSuccessView(), "document", df); }
From source file:ru.mystamps.web.controller.CategoryController.java
@GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE) public View showInfoById(@Category @PathVariable("slug") LinkEntityDto country, HttpServletResponse response) throws IOException { if (country == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; }/* w w w. j a v a 2 s. c o m*/ RedirectView view = new RedirectView(); view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); view.setUrl(Url.INFO_CATEGORY_PAGE); return view; }
From source file:ru.mystamps.web.controller.CountryController.java
/** * @author Aleksander Parkhomenko// w ww .ja va 2 s .c o m */ @GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE) public View showInfoById(@Country @PathVariable("slug") LinkEntityDto country, HttpServletResponse response) throws IOException { if (country == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } RedirectView view = new RedirectView(); view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); view.setUrl(Url.INFO_COUNTRY_PAGE); return view; }
From source file:ru.mystamps.web.controller.SeriesController.java
@GetMapping(Url.ADD_SERIES_WITH_CATEGORY_PAGE) public View showFormWithCategory(@PathVariable("slug") String category, RedirectAttributes redirectAttributes) { redirectAttributes.addAttribute("category", category); RedirectView view = new RedirectView(); view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); view.setUrl(Url.ADD_SERIES_PAGE);/*from w ww .j a v a 2 s . c om*/ return view; }
From source file:org.shareok.data.webserv.RestDspaceDataController.java
@RequestMapping(value = "/rest/{repoTypeStr}/{jobType}", method = RequestMethod.POST) public ModelAndView sshDspaceSaFImporter(HttpServletRequest request, RedirectAttributes redirectAttrs, @PathVariable("repoTypeStr") String repoTypeStr, @RequestParam(value = "localFile", required = false) MultipartFile file, @PathVariable("jobType") String jobType, @ModelAttribute("SpringWeb") DspaceApiJob job) { ModelAndView model = new ModelAndView(); String filePath = ""; logger.debug("Start to process the DSpace Rest API request..."); try {/*w w w . java2 s. c om*/ if (null == file || file.isEmpty()) { String localFile = (String) request.getParameter("localFile"); if (!DocumentProcessorUtil.isEmptyString(localFile)) { filePath = localFile; String safDir = (String) request.getParameter("localSafDir"); if (!DocumentProcessorUtil.isEmptyString(safDir)) { filePath = safDir + File.separator + filePath; } String folder = (String) request.getParameter("localFolder"); if (!DocumentProcessorUtil.isEmptyString(folder)) { filePath = folder + File.separator + filePath; } String journalSearch = (String) request.getParameter("journalSearch"); if (null != journalSearch && journalSearch.equals("1")) { filePath = ShareokdataManager.getDspaceUploadPath() + File.separator + filePath; } else { filePath = ShareokdataManager.getOuhistoryUploadPath() + File.separator + filePath; } } else { filePath = (String) request.getParameter("remoteFileUri"); } } else { filePath = ServiceUtil.saveUploadedFile(file, ShareokdataManager.getDspaceRestImportPath(jobType + "-" + repoTypeStr)); } } catch (Exception ex) { logger.error("Cannot upload the file for DSpace import using REST API.", ex); model.addObject("errorMessage", "Cannot get the server list"); model.setViewName("serverError"); return model; } DspaceRepoServer server = (DspaceRepoServer) serverService.findServerById(job.getServerId()); String userId = String.valueOf(request.getSession().getAttribute("userId")); job.setUserId(Long.valueOf(userId)); job.setCollectionId(server.getPrefix() + "/" + job.getCollectionId()); job.setRepoType(DataUtil.getRepoTypeIndex(repoTypeStr)); job.setType(DataUtil.getJobTypeIndex(jobType, repoTypeStr)); job.setStatus(Arrays.asList(RedisUtil.REDIS_JOB_STATUS).indexOf("created")); job.setFilePath(filePath); job.setStartTime(new Date()); job.setEndTime(null); try { RedisJob returnedJob = taskManager.execute(job); if (null == returnedJob) { throw new JobProcessingException("Null job object returned after processing!"); } int statusIndex = job.getStatus(); String isFinished = (statusIndex == 2 || statusIndex == 6) ? "true" : "false"; RedirectView view = new RedirectView(); view.setContextRelative(true); view.setUrl("/report/job/" + String.valueOf(returnedJob.getJobId())); model.setView(view); redirectAttrs.addFlashAttribute("host", serverService.findServerById(returnedJob.getServerId()).getHost()); redirectAttrs.addFlashAttribute("collection", DspaceDataUtil.DSPACE_REPOSITORY_HANDLER_ID_PREFIX + job.getCollectionId()); redirectAttrs.addFlashAttribute("isFinished", isFinished); redirectAttrs.addFlashAttribute("reportPath", DataHandlersUtil .getJobReportFilePath(DataUtil.JOB_TYPES[returnedJob.getType()], returnedJob.getJobId())); WebUtil.outputJobInfoToModel(redirectAttrs, returnedJob); } catch (Exception ex) { logger.error("Cannot process the job of DSpace import using REST API.", ex); model.addObject("errorMessage", "Cannot process the job of DSpace import using REST API."); model.setViewName("serverError"); } return model; }