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:org.codehaus.groovy.grails.plugins.springsecurity.IpAddressFilter.java
/** * {@inheritDoc}/*w w w . ja v a 2s .co m*/ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, * javax.servlet.FilterChain) */ public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request)) { // send 404 to hide the existence of the resource response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } chain.doFilter(request, response); }
From source file:com.collective.celos.servlet.JSONWorkflowSlotsServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { String id = req.getParameter(CelosClient.ID_PARAM); try {//w ww . j a v a2 s . co m if (id == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing."); return; } Scheduler scheduler = getOrCreateCachedScheduler(); Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id)); if (wf == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id); return; } ScheduledTime endTime = getTimeParam(req, CelosClient.END_TIME_PARAM, new ScheduledTime(DateTime.now(DateTimeZone.UTC))); ScheduledTime startTime = getTimeParam(req, CelosClient.START_TIME_PARAM, scheduler.getWorkflowStartTime(wf, endTime)); if (startTime.plusHours(scheduler.getSlidingWindowHours()).getDateTime() .isBefore(endTime.getDateTime())) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Time interval between start and end is limited to: " + scheduler.getSlidingWindowHours() + " hours"); return; } try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { List<SlotState> slotStates = scheduler.getSlotStates(wf, startTime, endTime, connection); List<JsonNode> objectNodes = Lists.newArrayList(); for (SlotState state : Lists.reverse(slotStates)) { objectNodes.add(state.toJSONNode()); } ObjectNode node = Util.MAPPER.createObjectNode(); node.put(CelosClient.INFO_NODE, (JsonNode) Util.MAPPER.valueToTree(wf.getWorkflowInfo())); node.put(CelosClient.PAUSE_NODE, connection.isPaused(wf.getID())); node.putArray(CelosClient.SLOTS_NODE).addAll(objectNodes); writer.writeValue(res.getOutputStream(), node); } } catch (Exception e) { throw new ServletException(e); } }
From source file:org.eclipse.virgo.apps.repository.web.RepositoryController.java
@RequestMapping(method = RequestMethod.GET, value = "/*") void getIndex(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = request.getRequestURI(); String repository = path.substring(path.lastIndexOf('/') + 1); RepositoryIndex index = this.repositoryManager.getIndex(repository); if (index != null) { String indexETag = index.getETag(); String eTagHeader = request.getHeader(IF_NONE_MATCH_HEADER_NAME); if (eTagHeader != null) { String[] eTags = eTagHeader.split(","); for (String eTag : eTags) { if (eTag.equals(indexETag)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; }// w ww. j a va 2s. co m } } response.setContentType(INDEX_CONTENT_TYPE); response.setContentLength(index.getLength()); response.addHeader(ETAG_HEADER_NAME, index.getETag()); FileCopyUtils.copy(index.getInputStream(), response.getOutputStream()); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }
From source file:com.autentia.tnt.servlet.DocServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getUploadPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }/*w w w .j a v a 2 s .c o m*/ OutputStream out = response.getOutputStream(); InputStream in = null; try { in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } } finally { if (in != null) { in.close(); } } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:biz.taoconsulting.dominodav.methods.COPY.java
/** * (non-Javadoc)/*from w w w . j av a 2s . c o m*/ * * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action() */ protected void action() { // TODO Needs fixing! String src = (String) this.getHeaderValues().get("path-info"); String uri = (String) this.getHeaderValues().get("uri"); String des = (String) this.getReq().getHeader("Destination"); des = des.replaceAll(this.getReq().getRequestURL().toString().replaceAll(src, ""), ""); try { this.resource = this.getRepository().getResource(uri, true); } catch (DAVNotFoundException e) { this.setErrorMessage("Not found: " + src, HttpServletResponse.SC_NOT_FOUND); return; } try { // FIXME: needs fixin this.destinationResource = this.getRepository().getResource(des, true); } catch (DAVNotFoundException e) { // TODO Very BAD, we didn't fix the URI! this.destinationResource = this.getRepository().createNewResource(des); } InputStream instream = this.resource.getStream(); OutputStream out = this.destinationResource.getOutputStream(); try { int read = 0; byte[] bytes = new byte[1024]; while ((read = instream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); instream.close(); out.close(); } catch (Exception ex) { LOGGER.error(ex); } }
From source file:com.epam.aem.training.core.servlets.RotatetdImageServlet.java
@Override protected void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws ServletException, IOException { Image image = this.resolveImage(req); if (image == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w ww . j a v a2s . c o m } if (!image.hasContent()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // get pure layer Layer layer = this.getLayer(image); if (layer == null) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } //rotating layer this.imageRotator.rotateUpDown(layer); try { final String mimeType = image.getMimeType(); layer.write(mimeType, 1, resp.getOutputStream()); } catch (RepositoryException ex) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } resp.flushBuffer(); }
From source file:com.autentia.tnt.servlet.DocRootServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.debug("doGet - uri='" + uri + "'"); int i = uri.indexOf(URL_PREFIX); if (i != -1) { String relPath = uri.substring(i + URL_PREFIX.length()); relPath = URLDecoder.decode(relPath, "UTF-8"); log.debug("doGet - relPath='" + relPath + "'"); File f = new File(ConfigurationUtil.getDefault().getDocumentRootPath() + relPath); if (f.exists()) { response.setContentLength((int) f.length()); String mime = request.getParameter(ARG_MIME); if (mime != null && !mime.equals("")) { response.setContentType(mime); }/*from w w w .ja va 2 s. c om*/ OutputStream out = response.getOutputStream(); InputStream in = null; try { in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } } finally { if (in != null) { in.close(); } } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad URL prefix for servlet: check your web.xml file"); } }
From source file:com.carolinarollergirls.scoreboard.jetty.LoadXmlScoreBoard.java
protected void handleDocument(HttpServletRequest request, HttpServletResponse response, Document doc) throws IOException { if (request.getPathInfo().equalsIgnoreCase("/load")) getXmlScoreBoard().loadDocument(doc); else if (request.getPathInfo().equalsIgnoreCase("/merge")) getXmlScoreBoard().mergeDocument(doc); else// ww w. j a v a 2s . co m response.sendError(HttpServletResponse.SC_NOT_FOUND, "Must specify to load or merge document"); response.setContentType("text/plain"); response.setStatus(HttpServletResponse.SC_OK); }
From source file:edu.northwestern.bioinformatics.studycalendar.web.template.ExportActivitiesController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String identifier = extractIdentifier(request.getPathInfo(), ID_PATTERN); String fullPath = request.getPathInfo(); String extension = fullPath.substring(fullPath.lastIndexOf(".") + 1).toLowerCase(); if (identifier == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not extract study identifier"); return null; }/* w w w.j av a2 s . co m*/ Source source = sourceDao.getByName(identifier); if (source == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } if (!(extension.equals("csv") || extension.equals("xls") || extension.equals("xml"))) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong extension type"); return null; } String elt; if (extension.equals("xml")) { response.setContentType("text/xml"); elt = activitySourceXmlSerializer.createDocumentString(source); } else { if (extension.equals("csv")) { response.setContentType("text/plain"); elt = sourceSerializer.createDocumentString(source, ','); } else { response.setContentType("text"); elt = sourceSerializer.createDocumentString(source, '\t'); } } byte[] content = elt.getBytes(); response.setContentLength(content.length); response.setHeader("Content-Disposition", "attachment"); FileCopyUtils.copy(content, response.getOutputStream()); return null; }