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:eionet.cr.web.action.ExportTriplesActionBean.java
/** * Action event that exports properties of the given uri. * * @return rdf result./* w ww. j a v a2 s. c om*/ */ public Resolution exportProperties() { if (StringUtils.isBlank(uri)) { if (Util.isWebBrowser(getContext().getRequest())) { getContext().getRequest().setAttribute(StripesExceptionHandler.EXCEPTION_ATTR, new CRException("Graph URI not specified in the request!")); return new ForwardResolution(StripesExceptionHandler.ERROR_PAGE); } else { return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND); } } return (new StreamingResolution("application/rdf+xml") { public void stream(HttpServletResponse response) throws Exception { RDFGenerator.generateProperties(uri, response.getOutputStream()); } }); }
From source file:com.autentia.intra.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 www . j ava 2s.c o m OutputStream out = response.getOutputStream(); InputStream in = new FileInputStream(f); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } 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:ee.pri.rl.blog.web.servlet.FileDownloadServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); BlogService blogService = (BlogService) context.getBean("blogService"); String path = req.getRequestURI().substring(req.getContextPath().length()); log.debug("Requested file " + path); if (path.startsWith("/")) { path = path.substring(1);/* w w w.j a v a 2 s. com*/ } if (path.startsWith("files/")) { path = path.substring("files/".length()); } int slashIndex = path.indexOf('/'); if (slashIndex > 0) { String entryName = path.substring(0, slashIndex); log.debug("Entry name: " + entryName); boolean authenticated = Session.exists() && ((BlogSession) Session.get()).isAuthenticated(); if (blogService.isPrivateEntry(entryName) && !authenticated) { log.warn("Tried to access private files"); resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } File directory = new File(blogService.getSetting(SettingName.UPLOAD_PATH).getValue()); File file = new File(directory, path); if (!file.exists()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); log.warn("File " + file + " does not exist"); return; } // Check if the requested file is still inside the upload dir. if (!FileUtil.insideDirectory(file, directory)) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); log.warn("File " + file + " is not inside upload dir"); return; } try { String calculatedTag = blogService.getUploadedFileTag(path); String tag = req.getHeader("If-None-Match"); if (tag == null) { log.debug("Tag not found, sending file"); sendFile(path, calculatedTag, directory, resp); } else if (tag.equals(calculatedTag)) { log.debug("Tag matches, sending 304"); sendNotModified(calculatedTag, resp); } else { log.debug("Tag does not match, sending file"); sendFile(path, calculatedTag, directory, resp); } } catch (NoSuchFileException e) { log.warn("File " + file + " does not exist"); resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } }
From source file:com.cradiator.TeamCityStatusPlugin.BuildMonitorController.java
private ModelAndView showBuild(String buildTypeId, HttpServletResponse response) throws IOException { SBuildType buildType = projectManager.findBuildTypeById(buildTypeId); if (buildType == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "no buildType with id " + buildTypeId); return null; }// ww w .j a v a 2 s. c o m return modelWithView("build-status.jsp").addObject("build", new BuildTypeMonitorViewState(server, buildType)); }
From source file:com.google.api.server.spi.EndpointsServletTest.java
@Test public void notFound() throws IOException { req.setRequestURI("/_ah/api/notfound"); req.setMethod("GET"); servlet.service(req, resp);//from w ww. j a v a2 s. c om assertThat(resp.getStatus()).isEqualTo(HttpServletResponse.SC_NOT_FOUND); }
From source file:org.jboss.as.test.integration.web.response.DefaultResponseCodeTestCase.java
@Test public void testNormalOpMode() throws Exception { HttpGet httpget = new HttpGet(url.toString() + URL_PATTERN); HttpResponse response = this.httpclient.execute(httpget); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); httpget = new HttpGet(url.toString() + URL_PATTERN + "/xxx"); response = this.httpclient.execute(httpget); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode()); }
From source file:com.imaginary.home.cloud.api.call.LocationCall.java
@Override public void get(@Nonnull String requestId, @Nullable String userId, @Nonnull String[] path, @Nonnull HttpServletRequest req, @Nonnull HttpServletResponse resp, @Nonnull Map<String, Object> headers, @Nonnull Map<String, Object> parameters) throws RestException, IOException { try {/*from w w w . j av a 2s . c o m*/ String locationId = (path.length > 1 ? path[1] : null); if (locationId != null) { Location location = Location.getLocation(locationId); if (location == null) { throw new RestException(HttpServletResponse.SC_NOT_FOUND, RestException.NO_SUCH_OBJECT, "The location " + locationId + " does not exist."); } resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().println((new JSONObject(toJSON(location))).toString()); resp.getWriter().flush(); } else { Collection<Location> locations; if (userId == null) { String apiKey = (String) headers.get(RestApi.API_KEY); Location location = null; if (apiKey != null) { ControllerRelay relay = ControllerRelay.getRelay(apiKey); if (relay != null) { location = relay.getLocation(); } } if (location == null) { locations = Collections.emptyList(); } else { locations = Collections.singletonList(location); } } else { User user = User.getUserByUserId(userId); if (user == null) { locations = Collections.emptyList(); } else { locations = user.getLocations(); } } ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); for (Location l : locations) { list.add(toJSON(l)); } resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().println((new JSONArray(list)).toString()); resp.getWriter().flush(); } } catch (PersistenceException e) { throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, RestException.INTERNAL_ERROR, e.getMessage()); } }
From source file:org.myjerry.evenstar.web.feed.FeedController.java
public ModelAndView view(HttpServletRequest request, HttpServletResponse response) throws Exception { String uri = request.getRequestURI(); FeedFormat feedFormat = null;/* w ww. j a v a 2s . c o m*/ // strip off the 'feeds/' from the URI uri = uri.substring(7); int extIndex = uri.lastIndexOf("."); if (extIndex != -1) { String extension = uri.substring(extIndex + 1); uri = uri.substring(0, extIndex); feedFormat = FeedFormat.getFeedFormat(extension); } if (feedFormat == null) { // bad request response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; } Long blogID = this.blogService.getBlogIDForServerName(request.getServerName()); if (blogID == null) { // try and see if the URI contains the blog ID String alias = uri; int index = uri.indexOf("/"); if (index != -1) { alias = uri.substring(0, index); } Long id = this.blogService.getBlogIDForAlias(alias); if (id != null) { blogID = id; uri = uri.substring(index + 1); } else { // just can't do anything now // no feed found response.setStatus(HttpServletResponse.SC_NOT_FOUND); return null; } } // decipher the type of feed if ("posts/default".equals(uri)) { return blogPostsFeed(feedFormat, blogID); } else if ("comments/default".equals(uri)) { return blogCommentsFeed(feedFormat, blogID); } else if (uri.startsWith("posts/")) { // try and get the post ID from this uri = uri.substring(6); int index = uri.indexOf("/"); if (index != -1) { Long postID = StringUtils.getLong(uri.substring(0, index)); if (postID != null) { uri = uri.substring(index + 1); if ("default".equals(uri)) { return blogPostFeed(feedFormat, blogID, postID); } else if ("comments".equals(uri)) { return blogPostCommentFeed(feedFormat, blogID, postID); } } } } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; }
From source file:com.exxonmobile.ace.hybris.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); }/* w w w .ja v a2 s .co m*/ // 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:io.wcm.wcm.parsys.componentinfo.impl.ParsysComponentsServlet.java
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { if (!enabled) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*from w w w . j a v a2s . c om*/ } ResourceResolver resolver = request.getResourceResolver(); PageManager pageManager = AdaptTo.notNull(resolver, PageManager.class); Page currentPage = pageManager.getContainingPage(request.getResource()); if (currentPage == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } long startTime = 0; if (log.isDebugEnabled()) { startTime = System.currentTimeMillis(); } response.setContentType(ContentType.JSON); JSONArray allowedComponents = new JSONArray(); // get relative path in content page String relativePath = RequestParam.get(request, RP_PATH); String fullPath = null; if (StringUtils.isNotEmpty(relativePath)) { // get resource from paragraph system fullPath = currentPage.getPath() + "/" + relativePath; Set<String> allowed = allowedComponentsProvider.getAllowedComponents(fullPath, resolver); // create set with relative resource type paths Set<String> allowedComponentsRelative = new TreeSet<String>(); for (String resourceType : allowed) { allowedComponentsRelative.add(ResourceType.makeAbsolute(resourceType, resolver)); } allowedComponents = new JSONArray(allowedComponentsRelative); } response.getWriter().write(allowedComponents.toString()); // output profiling info in DEBUG mode if (log.isDebugEnabled()) { long endTime = System.currentTimeMillis(); long duration = endTime - startTime; log.debug("ParsysComponentsServlet for " + fullPath + " took " + duration + "ms"); } }