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:guru.nidi.ramlproxy.core.MockServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { final String pathInfo = req.getPathInfo(); final int pos = pathInfo.lastIndexOf('/'); final String path = pathInfo.substring(1, pos + 1); final String name = pathInfo.substring(pos + 1); final ServletOutputStream out = res.getOutputStream(); final File targetDir = new File(mockDir, path); final File file = findFileOrParent(targetDir, name, req.getMethod()); CommandDecorators.ALLOW_ORIGIN.set(req, res); if (file == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "No or multiple file '" + name + "' found in directory '" + targetDir.getAbsolutePath() + "'"); return;/*w w w .j a v a 2s .c om*/ } handleMeta(req, res, file.getParentFile(), file.getName()); res.setContentLength((int) file.length()); res.setContentType(mineType(file)); try (final InputStream in = new FileInputStream(file)) { copy(in, out); } catch (IOException e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem delivering file '" + file.getAbsolutePath() + "': " + e); } out.flush(); }
From source file:com.alvexcore.repo.web.scripts.workflow.TaskInstanceGet.java
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {/*from w ww .j a v a 2s . com*/ String requesterUserName = AuthenticationUtil.getFullyAuthenticatedUser(); Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting task id from request parameters String taskId = params.get("task_instance_id"); // searching for task in repository WorkflowTask workflowTask = workflowService.getTaskById(taskId); // task was not found -> return 404 if (workflowTask == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow task with id: " + taskId); } Map<String, Object> model = new HashMap<String, Object>(); // build the model for ftl Map<String, Object> taskProps = modelBuilder.buildDetailed(workflowTask); taskProps.put(WorkflowModelBuilder.TASK_IS_REASSIGNABLE, alvexWorkflowService.isTaskReassignable(workflowTask, requesterUserName)); taskProps.put(WorkflowModelBuilder.TASK_IS_EDITABLE, alvexWorkflowService.isTaskEditable(workflowTask, requesterUserName)); model.put("workflowTask", taskProps); return model; }
From source file:net.duckling.ddl.web.api.rest.TeamController.java
@RequestMapping("/{teamCode}") @ResponseBody//from w ww. j a v a 2 s. c om public Team getByName(@PathVariable String teamCode, HttpServletResponse response) { Team team = teamService.getTeamByName(teamCode); if (team == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); JsonUtil.write(response, ErrorMsg.URI_NOT_FOUND); } return team; }
From source file:org.magnum.mobilecloud.video.VideoSvcCtrl.java
@PreAuthorize("hasRole(USER)") @RequestMapping(method = RequestMethod.GET, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}") public @ResponseBody Video getVideoById(@PathVariable("id") long id, HttpServletResponse response) { Video ret = videoRepo.findOne(id);//from w w w . j av a 2 s . co m if (ret == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND); else response.setStatus(HttpServletResponse.SC_OK); return ret; }
From source file:com.music.web.util.RequestBlockingFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String uri = request.getRequestURI(); for (String ignored : IGNORED_RESOURCES) { if (uri.contains(ignored)) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; }/*from ww w . j a va 2 s. c om*/ } String userAgent = request.getHeader("User-Agent"); // allow no user agent set, for restful calls if (!StringUtils.isEmpty(userAgent) && blockedAgents.contains(userAgent)) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } chain.doFilter(request, response); }
From source file:com.themodernway.server.core.servlet.ContentUploadServlet.java
@Override public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { try {/*from w ww. j av a 2 s .c o m*/ final IFolderItem fold = getRoot(); if (null == fold) { if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "Can't find storage root."); } sendErrorCode(request, response, HttpServletResponse.SC_NOT_FOUND); return; } if (false == fold.isWritable()) { if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "Can't write storage root."); } sendErrorCode(request, response, HttpServletResponse.SC_NOT_FOUND); return; } final String path = getPathNormalized(toTrimOrElse(request.getPathInfo(), FileUtils.SINGLE_SLASH)); if (null == path) { if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "Can't find path info."); } sendErrorCode(request, response, HttpServletResponse.SC_NOT_FOUND); return; } final ServletFileUpload upload = new ServletFileUpload(getDiskFileItemFactory()); upload.setSizeMax(getFileSizeLimit()); final List<FileItem> items = upload.parseRequest(request); for (final FileItem item : items) { if (false == item.isFormField()) { if (item.getSize() > fold.getFileSizeLimit()) { item.delete(); if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "File size exceeds limit."); } sendErrorCode(request, response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE); return; } final IFileItem file = fold.file(FileUtils.concat(path, item.getName())); if (null != file) { try (InputStream read = item.getInputStream()) { fold.create(file.getPath(), read); } catch (final IOException e) { item.delete(); final IServletExceptionHandler handler = getServletExceptionHandler(); if ((null == handler) || (false == handler.handle(request, response, getServletResponseErrorCodeManagerOrDefault(), e))) { if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "Can't write file.", e); } sendErrorCode(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return; } } else { item.delete(); if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "Can't find file."); } sendErrorCode(request, response, HttpServletResponse.SC_NOT_FOUND); return; } } item.delete(); } } catch (IOException | FileUploadException e) { final IServletExceptionHandler handler = getServletExceptionHandler(); if ((null == handler) || (false == handler.handle(request, response, getServletResponseErrorCodeManagerOrDefault(), e))) { if (logger().isErrorEnabled()) { logger().error(LoggingOps.THE_MODERN_WAY_MARKER, "captured overall exception for security.", e); } sendErrorCode(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } }
From source file:org.shredzone.bullshitcharts.servlet.ChartServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String pathInfo = req.getPathInfo(); PlotGenerator generator = null;/*from ww w. j a v a2 s . c o m*/ if ("/pie.png".equals(pathInfo)) { generator = new ChoicePieGenerator(); } else if ("/agree.png".equals(pathInfo)) { generator = new AgreementPieGenerator(); } else if ("/line.png".equals(pathInfo)) { generator = new LineChartGenerator(); } else if ("/bar.png".equals(pathInfo)) { generator = new BarChartGenerator(); } else { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } generator.configure(req); Plot plot = generator.generate(); // Generate the chart JFreeChart chart = new JFreeChart(plot); chart.setAntiAlias(true); chart.setTextAntiAlias(true); chart.setBorderVisible(false); chart.removeLegend(); String title = req.getParameter("title"); if (title != null) { chart.setTitle(title); } // Write the chart to a byte array. It is small enough so it won't load the // server's memory too much. try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ChartUtilities.writeChartAsPNG(baos, chart, IMAGE_WIDTH, IMAGE_HEIGHT); byte[] data = baos.toByteArray(); // Stream the chart resp.setContentType("image/png"); resp.setContentLength(data.length); resp.setHeader("Cache-Control", "no-cache, must-revalidate"); resp.setHeader("Expires", "Sat, 01 Jan 2000 00:00:00 GMT"); resp.getOutputStream().write(data); } }
From source file:io.wcm.samples.handler.controller.http.Redirect.java
@PostConstruct protected void activate() throws IOException { // resolve link of redirect page String redirectUrl = linkHandler.get(resource).buildUrl(); // in preview/publish mode redirect to target if ((wcmMode == WCMMode.DISABLED || wcmMode == WCMMode.PREVIEW) && StringUtils.isNotEmpty(redirectUrl)) { if (StringUtils.equals(redirectStatus, "301")) { response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location", redirectUrl); } else {//from w ww. ja v a 2 s .c o m response.sendRedirect(redirectUrl); } renderPage = false; } else if (wcmMode == WCMMode.DISABLED) { response.sendError(HttpServletResponse.SC_NOT_FOUND); renderPage = false; } }
From source file:jp.co.opentone.bsol.linkbinder.view.servlet.WebResourceServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo(); if (isJavascript(path)) { serveResource(req, resp, javascript, path); } else if (isStylesheet(path)) { serveResource(req, resp, stylesheet, path); } else {// ww w. j a v a 2 s .c o m resp.sendError(HttpServletResponse.SC_NOT_FOUND); } }