List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for javax.servlet.http HttpServletResponse SC_NOT_FOUND.
Click Source Link
From source file:com.formtek.dashlets.sitetaskmgr.SiteEndTask.java
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {/*from w w w . ja va2 s . c o m*/ Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting workflow instance id from request parameters String taskId = getTaskId(req); logger.debug("Task Instance: " + taskId); // get the name of the site the workflow should be associated with String site = getSite(req); logger.debug("Workflow should be associated with site: " + site); // get the requested transition id for the workflow String transition = getTransition(req); logger.debug("Workflow requested to transition to state: " + transition); // get the WorkflowPath from the Workflow Instance ID WorkflowTask wfTask = workflowService.getTaskById(taskId); if (wfTask == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Failed to find workflow task id: " + taskId); } logger.debug("Retrieved the workflow task"); // get the WorkflowPath from the Workflow Instance ID WorkflowPath wfPath = wfTask.getPath(); if (wfPath == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Failed to find workflow path for task id: " + taskId); } if (SiteWFUtil.canUserChangeWorkflow(wfPath, site, workflowService, nodeService, authenticationService, authorityService)) { logger.debug("User authenticated and workflow to be transitioned."); // check the requested transition WorkflowTransition[] wfTransitions = wfPath.getNode().getTransitions(); logger.debug("Identified " + wfTransitions.length + " transitions."); // Identify the transition name as valid, by checking list of available transitions int i = 0; WorkflowTransition wfTransition = null; for (i = 0; i < wfTransitions.length; i++) { logger.debug("Checking Transition: " + wfTransitions[i].getTitle() + " and id: " + wfTransitions[i].getId()); if (wfTransitions[i].getId().equals(transition)) { logger.debug("Found the transition: " + wfTransitions[i].getTitle()); wfTransition = wfTransitions[i]; } } if (wfTransition == null) { logger.debug("No matching transition found"); throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find a transition that matches the name: " + transition); } // Do the transition logger.debug("Performing the transition to: " + transition); workflowService.endTask(taskId, wfTransition.getId()); // return an empty model return new HashMap<String, Object>(); } else { throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Failed to transition for task id: " + taskId); } }
From source file:com.fluidops.iwb.server.AbstractFileServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { File downloadFile = getDownloadFile(req); ////////////////// SECURITY CHECK if (!EndpointImpl.api().getUserManager().hasFileAccess(downloadFile.getAbsolutePath(), null, true)) { logger.debug("Access to " + downloadFile + " denied due to ACL rule."); // to hide information to hackers, we send 404 instead of access forbidden resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*from w w w.j a v a 2s .c o m*/ } setContentType(req, resp, downloadFile); sendFile(downloadFile, resp.getOutputStream()); }
From source file:de.elomagic.mag.ServletMock.java
@Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getRequestURI().endsWith("TestFile.pdf")) { response.setStatus(HttpServletResponse.SC_OK); } else {//from w w w.ja v a 2 s . c o m response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }
From source file:org.shredzone.cilla.view.MediaView.java
/** * Streams a medium of the given page.// w w w. j a v a 2s . c o m */ @View(pattern = "/page/${page.id}/${#type}/${#name}", signature = { "page", "#type", "#name" }) @View(pattern = "/page/${page.id}/${#name}", signature = { "page", "#name" }) public void mediumView(@PathPart("page.id") Page page, @Optional @PathPart("#type") String type, @PathPart("#name") String name, HttpServletRequest req, HttpServletResponse resp) throws ViewException, CillaServiceException { if (!pageService.isVisible(page)) { throw new ErrorResponseException(HttpServletResponse.SC_FORBIDDEN); } Medium media = mediaDao.fetchByName(page, name); if (media == null) { throw new PageNotFoundException(); } ImageProcessing ip = null; if (type != null) { ip = imageProcessingManager.createImageProcessing(type); if (ip == null) { throw new ErrorResponseException(HttpServletResponse.SC_NOT_FOUND); } } ResourceDataSource ds = pageService.getMediumImage(media, ip); streamDataSource(ds, req, resp); }
From source file:com.formtek.dashlets.sitetaskmgr.SiteTaskInstancePut.java
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {//w ww .j a v a2s. c o m Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting task id from request parameters String wfId = getWorkflowId(req); logger.debug("Processing workflowId: " + wfId); String site = getSite(req); logger.debug("Workflow should be associated with site: " + site); logger.debug("Workflow type: " + workflowService.getWorkflowById(wfId).getDefinition().getName()); if (wfId == null || site == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Can't set task properties because workflow Id or site name are not defined correctly."); } JSONObject json = null; try { // read request json containing properties to write json = new JSONObject(new JSONTokener(req.getContent().getContent())); logger.debug(json.toString()); // get the workflow path from the incoming workflow Id // for site task manager workflows, there will be a single path WorkflowPath wfPath = SiteWFUtil.getWorkflowPath(wfId, workflowService); // If User is not authorized to change this workflow, exit if (!SiteWFUtil.canUserChangeWorkflow(wfPath, site, workflowService, nodeService, authenticationService, authorityService)) { throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "User is not authorized to change workflows for this site: " + site); } // Retrieve the current task. For the site task workfklow, there should be a single current task WorkflowTask workflowTask = SiteWFUtil.getWorkflowTask(wfPath, workflowService); String taskId = workflowTask.getId(); logger.debug("Processing taskId: " + taskId); // update task properties workflowTask = workflowService.updateTask(taskId, parseTaskProperties(json, workflowTask), null, null); // task was not found -> return 404 if (workflowTask == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Failed to find workflow task with id: " + taskId); } // build the model for ftl Map<String, Object> model = new HashMap<String, Object>(); model.put("workflowTask", modelBuilder.buildDetailed(workflowTask)); return model; } catch (IOException iox) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox); } catch (JSONException je) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je); } }
From source file:org.magnum.mobilecloud.video.MainController_HW_2.java
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "{/id}", method = RequestMethod.GET) public @ResponseBody Video getVideo(@PathVariable("id") long id, HttpServletResponse response) { Video v = videos.findOne(id);// w w w . java 2s . com if (v == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } return v; }
From source file:com.acc.storefront.controllers.pages.DefaultPageController.java
@RequestMapping(method = RequestMethod.GET) public String get(final Model model, final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException { // Check for CMS Page where label or id is like /page final ContentPageModel pageForRequest = getContentPageForRequest(request); if (pageForRequest != null) { storeCmsPageInModel(model, pageForRequest); setUpMetaDataForContentPage(model, pageForRequest); model.addAttribute(WebConstants.BREADCRUMBS_KEY, contentPageBreadcrumbBuilder.getBreadcrumbs(pageForRequest)); return getViewForPage(pageForRequest); }//from w ww. jav a 2 s. com // No page found - display the notFound page with error from controller storeCmsPageInModel(model, getContentPageForLabelOrId(ERROR_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ERROR_CMS_PAGE)); model.addAttribute(WebConstants.MODEL_KEY_ADDITIONAL_BREADCRUMB, resourceBreadcrumbBuilder.getBreadcrumbs("breadcrumb.not.found")); GlobalMessages.addErrorMessage(model, "system.error.page.not.found"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return ControllerConstants.Views.Pages.Error.ErrorNotFoundPage; }
From source file:com.cloud.servlet.StaticResourceServletTest.java
@Test public void testNoSuchFile() throws ServletException, IOException { final StaticResourceServlet servlet = Mockito.mock(StaticResourceServlet.class); Mockito.doCallRealMethod().when(servlet).doGet(Matchers.any(HttpServletRequest.class), Matchers.any(HttpServletResponse.class)); final ServletContext servletContext = Mockito.mock(ServletContext.class); Mockito.when(servletContext.getRealPath("notexisting.css")) .thenReturn(new File(rootDirectory, "notexisting.css").getAbsolutePath()); Mockito.when(servlet.getServletContext()).thenReturn(servletContext); final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getServletPath()).thenReturn("notexisting.css"); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); servlet.doGet(request, response);//from www .j a v a2s. c o m Mockito.verify(response).setStatus(HttpServletResponse.SC_NOT_FOUND); }
From source file:org.magnum.mobilecloud.video.VideoLikeController.java
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST) public void unlikeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse resp) { Video v = videos.findOne(id);/* w w w.j av a 2 s .c o m*/ if (v == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { Set<String> likedUsernames = v.getLikedUsernames(); String username = p.getName(); if (!likedUsernames.contains(username)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { likedUsernames.remove(username); v.setLikedUsernames(likedUsernames); v.setLikes(likedUsernames.size()); videos.save(v); } } }
From source file:jipdbs.web.processors.PlayerPenaltyProcessor.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a 2 s . c o m public String doProcess(ResolverContext ctx) throws ProcessorException { IDDBService app = (IDDBService) ctx.getServletContext().getAttribute("jipdbs"); HttpServletRequest req = ctx.getRequest(); String playerId = ctx.getRequest().getParameter("k"); String type = ctx.getParameter("type"); String reason = ctx.getRequest().getParameter("reason"); String duration = ctx.getRequest().getParameter("duration"); //String durationType = ctx.getRequest().getParameter("dt"); String durationType = "w"; String rm = ctx.getParameter("rm"); UrlReverse reverse = new UrlReverse(ctx.getServletContext()); String redirect; try { redirect = reverse.resolve("playerinfo", new Entry[] { new SimpleEntry("key", playerId) }); } catch (Exception e) { log.error(e.getMessage()); throw new ProcessorException(e); } Player player = null; try { player = app.getPlayer(playerId); } catch (EntityDoesNotExistsException e) { log.error(e.getMessage()); throw new HttpError(HttpServletResponse.SC_NOT_FOUND); } Server server; try { server = app.getServer(player.getServer(), true); } catch (EntityDoesNotExistsException e) { log.error(e.getMessage()); throw new ProcessorException(e); } catch (ApplicationError e) { log.error(e.getMessage()); throw new ProcessorException(e); } if (!UserServiceFactory.getUserService().hasPermission(server.getKey(), server.getAdminLevel())) { Flash.error(req, MessageResource.getMessage("forbidden")); log.debug("Forbidden"); throw new HttpError(HttpServletResponse.SC_FORBIDDEN); } Player currentPlayer = UserServiceFactory.getUserService().getSubjectPlayer(player.getServer()); if (currentPlayer == null) { log.error("No player for current user"); throw new HttpError(HttpServletResponse.SC_FORBIDDEN); } if (currentPlayer.getLevel() <= player.getLevel()) { Flash.error(req, MessageResource.getMessage("low_level_admin")); return redirect; } Integer funcId; Penalty penalty = null; if ("true".equals(rm)) { funcId = PenaltyHistory.FUNC_ID_RM; String penaltyId = ctx.getParameter("key"); try { penalty = app.getPenalty(Long.parseLong(penaltyId)); } catch (NumberFormatException e) { log.debug("Invalid penalty id"); Flash.error(req, MessageResource.getMessage("forbidden")); throw new HttpError(HttpServletResponse.SC_FORBIDDEN); } catch (EntityDoesNotExistsException e) { log.debug("Invalid penalty id"); throw new HttpError(HttpServletResponse.SC_NOT_FOUND); } String res = removePenalty(req, redirect, player, server, penalty); if (res != null) return res; } else { if (StringUtils.isEmpty(reason)) { Flash.error(req, MessageResource.getMessage("reason_field_required")); return redirect; } funcId = PenaltyHistory.FUNC_ID_ADD; penalty = new Penalty(); String res = createPenalty(req, penalty, type, reason, duration, durationType, redirect, player, server, currentPlayer); if (res != null) return res; } try { app.updatePenalty(penalty, UserServiceFactory.getUserService().getCurrentUser().getKey(), funcId); } catch (Exception e) { log.error(e.getMessage()); Flash.error(req, e.getMessage()); } return redirect; }