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:gov.nih.nci.cabig.ctms.lookandfeel.AssetServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getPathInfo().contains("..")) { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Illegal path"); return;/* w ww .ja v a 2 s . c om*/ } String resource = resourcePath(req.getPathInfo()); String mimeType = contentType(req.getPathInfo()); if (mimeType != null) { resp.setContentType(mimeType); } // TODO: this is primitive. Should add content-length at least InputStream resStream = getClass().getResourceAsStream(resource); if (resStream == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } else { IOUtils.copy(resStream, resp.getOutputStream()); } }
From source file:org.codehaus.groovy.grails.plugins.remoting.DummyHttpExporter.java
/** * Always returns a 404 HTTP status.//from w ww.java2 s.c o m */ public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); }
From source file:com.collective.celos.servlet.RegisterServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { try {//from w w w . j a va2 s .c o m BucketID bucket = getRequestBucketID(req); RegisterKey key = getRequestKey(req); try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { JsonNode value = connection.getRegister(bucket, key); if (value == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Register not found"); } else { writer.writeValue(res.getOutputStream(), value); } } } catch (Exception e) { throw new ServletException(e); } }
From source file:com.octo.captcha.module.web.image.ImageToJpegHelper.java
/** * retrieve a new ImageCaptcha using ImageCaptchaService and flush it to the response.<br/> Captcha are localized * using request locale.<br/>//from w w w. ja va 2 s.c om * <p/> * This method returns a 404 to the client instead of the image if the request isn't correct (missing parameters, * etc...)..<br/> The log may be null.<br/> * * @param theRequest the request * @param theResponse the response * @param log a commons logger * @param service an ImageCaptchaService instance * * @throws java.io.IOException if a problem occurs during the jpeg generation process */ public static void flushNewCaptchaToResponse(HttpServletRequest theRequest, HttpServletResponse theResponse, Log log, ImageCaptchaService service, String id, Locale locale) throws IOException { // call the ImageCaptchaService method to retrieve a captcha byte[] captchaChallengeAsJpeg = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { BufferedImage challenge = service.getImageChallengeForID(id, locale); // the output stream to render the captcha image as jpeg into ImageIO.write(challenge, "jpg", jpegOutputStream); } catch (IllegalArgumentException e) { // log a security warning and return a 404... if (log != null && log.isWarnEnabled()) { log.warn("There was a try from " + theRequest.getRemoteAddr() + " to render an captcha with invalid ID :'" + id + "' or with a too long one"); theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // render the captcha challenge as a JPEG image in the response theResponse.setHeader("Cache-Control", "no-store"); theResponse.setHeader("Pragma", "no-cache"); theResponse.setDateHeader("Expires", 0); theResponse.setContentType("image/jpeg"); ServletOutputStream responseOutputStream = theResponse.getOutputStream(); responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush(); responseOutputStream.close(); }
From source file:ru.mystamps.web.controller.ImageController.java
@GetMapping(Url.GET_IMAGE_PAGE) public void getImage(@PathVariable("id") Integer imageId, HttpServletResponse response) throws IOException { if (imageId == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*from ww w . j a v a 2s . co m*/ } ImageDto image = imageService.get(imageId); if (image == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // TODO: set content disposition response.setContentType("image/" + image.getType().toLowerCase()); response.setContentLength(image.getData().length); response.getOutputStream().write(image.getData()); }
From source file:org.dspace.app.webui.cris.servlet.ResearcherPictureServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { String idString = req.getPathInfo(); String[] pathInfo = idString.split("/", 2); String authorityKey = pathInfo[1]; Integer id = ResearcherPageUtils.getRealPersistentIdentifier(authorityKey, ResearcherPage.class); if (id == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w w w. j ava 2s. c o m } ResearcherPage rp = ResearcherPageUtils.getCrisObject(id, ResearcherPage.class); File file = new File(ConfigurationManager.getProperty(CrisConstants.CFG_MODULE, "researcherpage.file.path") + File.separatorChar + JDynATagLibraryFunctions.getFileFolder(rp.getPict().getValue()) + File.separatorChar + JDynATagLibraryFunctions.getFileName(rp.getPict().getValue())); InputStream is = null; try { is = new FileInputStream(file); response.setContentType(req.getSession().getServletContext().getMimeType(file.getName())); Long len = file.length(); response.setContentLength(len.intValue()); response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); FileCopyUtils.copy(is, response.getOutputStream()); response.getOutputStream().flush(); } finally { if (is != null) { IOUtils.closeQuietly(is); } } }
From source file:net.swigg.talo.admin.TestControllerImpl.java
@Override public String error(HttpServletResponse response) throws IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); return "error"; }
From source file:com.octo.captcha.module.web.sound.SoundToWavHelper.java
/** * retrieve a new SoundCaptcha using SoundCaptchaService and flush it to the response. <br/> Captcha are localized * using request locale. <br/>This method returns a 404 to the client instead of the image if the request isn't * correct (missing parameters, etc...).. <br/>The log may be null. <br/> * * @param theRequest the request//from ww w .java 2 s .c o m * @param theResponse the response * @param log a commons logger * @param service an SoundCaptchaService instance * * @throws java.io.IOException if a problem occurs during the jpeg generation process */ public static void flushNewCaptchaToResponse(HttpServletRequest theRequest, HttpServletResponse theResponse, Log log, SoundCaptchaService service, String id, Locale locale) throws IOException { // call the ImageCaptchaService method to retrieve a captcha byte[] captchaChallengeAsWav = null; ByteArrayOutputStream wavOutputStream = new ByteArrayOutputStream(); try { AudioInputStream stream = service.getSoundChallengeForID(id, locale); // call the ImageCaptchaService method to retrieve a captcha AudioSystem.write(stream, AudioFileFormat.Type.WAVE, wavOutputStream); //AudioSystem.(pAudioInputStream, AudioFileFormat.Type.WAVE, pFile); } catch (IllegalArgumentException e) { // log a security warning and return a 404... if (log != null && log.isWarnEnabled()) { log.warn("There was a try from " + theRequest.getRemoteAddr() + " to render an captcha with invalid ID :'" + id + "' or with a too long one"); theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } catch (CaptchaServiceException e) { // log and return a 404 instead of an image... if (log != null && log.isWarnEnabled()) { log.warn( "Error trying to generate a captcha and " + "render its challenge as JPEG", e); } theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } captchaChallengeAsWav = wavOutputStream.toByteArray(); // render the captcha challenge as a JPEG image in the response theResponse.setHeader("Cache-Control", "no-store"); theResponse.setHeader("Pragma", "no-cache"); theResponse.setDateHeader("Expires", 0); theResponse.setContentType("audio/x-wav"); ServletOutputStream responseOutputStream = theResponse.getOutputStream(); responseOutputStream.write(captchaChallengeAsWav); responseOutputStream.flush(); responseOutputStream.close(); }
From source file:uk.org.iay.mdq.server.ResultTextView.java
@Override public void render(final Map<String, ?> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { log.debug("rendering as {}", getContentType()); final Result result = (Result) model.get("result"); if (result.isNotFound()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w ww. j a va 2s. c om } OutputStream out = response.getOutputStream(); response.setContentType(new MediaType("text", "plain", Charset.forName("UTF-8")).toString()); final Writer w = new OutputStreamWriter(out, Charset.forName("UTF-8")); final Representation norm = result.getRepresentation(); final byte[] bytes = norm.getBytes(); w.write("Query result is:\n"); w.write(" " + bytes.length + " bytes\n"); w.write(" ETag is " + norm.getETag() + "\n"); w.write("\n"); w.write(new String(bytes, Charset.forName("UTF-8"))); }
From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try {//from w w w . j a va 2 s . co m String captchaId = request.getSession().getId(); createCheckCodeImage(captchaId, request.getLocale(), jpegOutputStream); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (CaptchaServiceException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } initResponseHeader(response); responseImage(response, jpegOutputStream.toByteArray()); jpegOutputStream.close(); }