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:eu.dasish.annotation.backend.rest.CachedRepresentationResource.java
/** * //from w ww . j a v a 2s .com * @param externalId the external UUID of a cached representation. * @return the image-blob if the cached-representation's blob is an image file. * @throws IOException if logging an error fails (should be changed to sending httpResponse error message). */ @GET @Produces({ "image/jpeg", "image/png" }) @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/content") @Transactional(readOnly = true) public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws IOException { Map params = new HashMap(); try { InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, Access.READ, externalId); if (result != null) { ImageIO.setUseCache(false); try { BufferedImage retVal = ImageIO.read(result); return retVal; } catch (IOException e1) { loggerServer.info(e1.toString()); return null; } } else { loggerServer.info(" The cached representation with the id " + externalId + " has null blob."); return null; } } catch (NotInDataBaseException e1) { httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage()); return null; } catch (ForbiddenException e2) { httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage()); return null; } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTJob.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { try {/*from w w w . jav a 2 s . co m*/ long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo())); Job job = restUtils.unmarshal(Job.class, req.getInputStream()); if (job.getId() != jobId) { if (log.isDebugEnabled()) { log.debug("job descriptor id " + job.getId() + " and request id " + jobId + "do not match. assigning the request id to as the job id"); } job.setId(jobId); } if (job.getVersion() == DISREGARD_VERSION && reportSchedulerService.getJob(jobId) != null) { Job oldJob = reportSchedulerService.getJob(jobId); job.setVersion(oldJob.getVersion()); } reportSchedulerService.updateJob(job); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage()); } catch (IOException e) { throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, e.getMessage()); } catch (JAXBException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "please check the request job descriptor"); } }
From source file:info.magnolia.cms.servlets.EntryServlet.java
/** * All HTTP/s requests are handled here. * @param req HttpServletRequest//from w w w .j a v a 2 s .c o m * @param res HttpServletResponse * @throws IOException can be thrown when the servlet is unable to write to the response stream * @throws ServletException */ public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { // Initialize magnolia context super.doGet(req, res); if (ConfigLoader.isBootstrapping()) { // @todo a nice page, with the log content... res.getWriter().write("Magnolia bootstrapping has failed, check bootstrap.log in magnolia/logs"); //$NON-NLS-1$ return; } if (ModuleRegistration.getInstance().isRestartNeeded()) { res.sendRedirect(req.getContextPath() + "/.magnolia/pages/restart.html"); } try { if (isAuthorized(req, res)) { if (redirect(req, res)) { return; } intercept(req, res); // aggregate content boolean success = Aggregator.collect(req); if (success) { Template template = (Template) req.getAttribute(Aggregator.TEMPLATE); if (template != null) { try { String type = template.getType(); TemplateRenderer renderer = TemplateRendererManager.getInstance().getRenderer(type); if (renderer == null) { throw new RuntimeException("No renderer found for type " + type); } renderer.renderTemplate(template, req, res); } catch (Exception e) { // @todo better handling of rendering exception log.error(e.getMessage(), e); if (!res.isCommitted()) { res.reset(); res.setContentType("text/html"); } throw new NestableRuntimeException(e); } } else { // direct request req.getRequestDispatcher(DIRECT_REQUEST_RECEIVER).forward(req, res); } } else { if (log.isDebugEnabled()) { log.debug("Resource not found, redirecting request for [{}] to 404 URI", //$NON-NLS-1$ req.getRequestURI()); } if (!res.isCommitted()) { res.sendError(HttpServletResponse.SC_NOT_FOUND); } else { log.info("Unable to redirect to 404 page, response is already committed. URI was {}", //$NON-NLS-1$ req.getRequestURI()); } } } } catch (AccessDeniedException e) { // don't log AccessDenied as errors, it can happen... log.warn(e.getMessage()); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new ServletException(e.getMessage(), e); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw new ServletException(e.getMessage(), e); } }
From source file:edu.utsa.sifter.IndexResource.java
@Path("index") @POST//from w w w. j av a2s . c o m @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public IndexInfo openIndex(IndexInfo idx) { if (idx.Id == null) { idx.Id = new String(Hex.encodeHex(Hasher.digest(idx.Path.getBytes()))); } idx.Id = idx.Id.toLowerCase(); IndexReader rdr = State.Indices.get(idx.Id); if (rdr == null) { try { final File evPath = new File(idx.Path); final File primaryIdx = new File(evPath, "primary-idx"); final File somIdx = new File(evPath, "som-idx"); DirectoryReader parallel[] = new DirectoryReader[2]; parallel[0] = DirectoryReader.open(FSDirectory.open(primaryIdx)); parallel[1] = DirectoryReader.open(FSDirectory.open(somIdx)); rdr = new ParallelCompositeReader(parallel); } catch (IOException ex) { HttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); } } if (rdr != null) { idx.NumDocs = rdr.numDocs(); State.Indices.put(idx.Id, rdr); State.IndexLocations.put(idx.Id, idx); } return idx; }
From source file:org.shredzone.cilla.view.GalleryView.java
/** * Streams the picture of a gallery./*from w ww . ja v a 2 s . co m*/ */ @View(pattern = "/picture/${picture.id}-${#type}.${#suffix(picture.image.contentType)}", signature = { "picture", "#type" }) @View(pattern = "/picture/${picture.id}.${#suffix(picture.image.contentType)}", signature = { "picture" }) public void pictureView(@PathPart("picture.id") Picture picture, @Optional @PathPart("#type") String type, HttpServletRequest req, HttpServletResponse resp) throws ViewException, CillaServiceException { // Take measures against deep linking of the pictures. No need to check page // permissions, as the picture is not unlocked if the visitor had no access // to the page. if (!unlockService.isUnlocked(req.getSession(), picture)) { throw new ErrorResponseException(HttpServletResponse.SC_FORBIDDEN); } ImageProcessing ip = null; if (type != null) { ip = imageProcessingManager.createImageProcessing(type); if (ip == null) { throw new ErrorResponseException(HttpServletResponse.SC_NOT_FOUND); } } ResourceDataSource ds = pictureService.getImage(picture, ip); streamDataSource(ds, req, resp); }
From source file:fi.hoski.web.forms.RaceEntryServlet.java
/** * Handles the HTTP//from ww w . j a va 2 s . c o m * <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setHeader("Cache-Control", "private"); JSONObject json = null; String ratingSystem = request.getParameter(RaceFleet.RatingSystem); if (ratingSystem != null) { String classOptions = request.getParameter(CLASSOPTIONS); if (classOptions != null) { printClassOptions(response, boatInfoFactory.getBoatInfoService(ratingSystem)); return; } json = new JSONObject(); Map<String, Object> biMap = boatInfoFactory.getMap(request.getParameterMap()); log(biMap.toString()); if (biMap != null && !biMap.isEmpty()) { for (Entry<String, Object> e : biMap.entrySet()) { json.put(e.getKey(), e.getValue()); } } } else { json = fromCookie(request); Entity rcEntity = getAncestor(request); if (rcEntity != null) { json.put(RaceEntry.FLEET, rcEntity.getProperty(RaceFleet.Fleet)); String boatClass = (String) rcEntity.getProperty(RaceFleet.Class); if (boatClass != null) { json.put(RaceEntry.CLASS, boatClass); } } ratingSystem = json.optString(BoatInfo.FLEET, null); String nat = json.optString(BoatInfo.NAT, null); String sailNo = json.optString(BoatInfo.SAILNO, null); String boatType = json.optString(BoatInfo.CLASS, null); Map<String, Object> biMap = boatInfoFactory.getMap(ratingSystem, nat, sailNo, boatType); if (biMap != null && !biMap.isEmpty()) { for (Entry<String, Object> e : biMap.entrySet()) { json.put(e.getKey(), e.getValue()); } } } response.setContentType("application/json"); PrintWriter out = response.getWriter(); json.write(out); out.close(); log(json.toString()); String refresh = request.getParameter("refresh"); if (refresh != null) { boatInfoFactory.refresh(refresh); } } catch (JSONException ex) { log(ex.getMessage(), ex); throw new ServletException(ex); } catch (EntityNotFoundException ex) { log(ex.getMessage(), ex); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }
From source file:eu.dasish.annotation.backend.rest.NotebookResource.java
/** * // w w w . jav a 2 s . co m * @param externalIdentifier the external UUID identifier of a notebook. * @param accessMode the access mode on which principals must be filtered; * can be "none", "read", "write", "all". * @return a {@link ReferenceList} element representing the list of h-references of the * principals that have access "accessMode". * @throws IOException if sending an error fails. */ @GET @Produces(MediaType.APPLICATION_XML) @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}/{access}") @Transactional(readOnly = true) public JAXBElement<ReferenceList> getPrincipals(@PathParam("notebookid") String externalIdentifier, @PathParam("access") String accessMode) throws IOException { Number remotePrincipalID = this.getPrincipalID(); if (remotePrincipalID == null) { return new ObjectFactory().createReferenceList(new ReferenceList()); } try { Number notebookID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK); if (dbDispatcher.hasAccess(notebookID, remotePrincipalID, Access.fromValue("read"))) { ReferenceList principals = dbDispatcher.getPrincipals(notebookID, accessMode); return new ObjectFactory().createReferenceList(principals); } else { httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); return new ObjectFactory().createReferenceList(new ReferenceList()); } } catch (NotInDataBaseException e) { loggerServer.debug(e.toString()); ; httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString()); return new ObjectFactory().createReferenceList(new ReferenceList()); } }
From source file:net.triptech.buildulator.web.ProjectController.java
/** * Returns the project if the user has the rights to view it. * Otherwise a 404 error is returned.//from w w w. j a va 2 s . c om * * @param id the id * @param uiModel the ui model * @param request the request * @param response the response * @return the string */ @RequestMapping(value = "/{id}", method = RequestMethod.GET) public String show(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request, final HttpServletResponse response) { String page = "projects/show"; Project project = Project.findProject(id); if (checkProjectPermission(project, request)) { boolean noOperatingEnergyData = false; boolean noBOMData = false; if (testIfEmptyJson(project.getDataField(Project.OPERATING_ENERGY))) { noOperatingEnergyData = true; } if (testIfEmptyJson(project.getDataField(Project.CONSTRUCTION))) { noBOMData = true; } uiModel.addAttribute("project", project); uiModel.addAttribute("noOperatingEnergyData", noOperatingEnergyData); uiModel.addAttribute("noBOMData", noBOMData); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); page = "resourceNotFound"; } return page; }
From source file:pt.webdetails.cpf.SimpleContentGenerator.java
@Override public void createContent() throws Exception { IParameterProvider pathParams = getPathParameters();// parameterProviders.get("path"); try {/*w ww .j a v a 2 s. c o m*/ String path = pathParams.getStringParameter("path", null); String[] pathSections = StringUtils.split(path, "/"); if (pathSections == null || pathSections.length == 0) { String method = getDefaultPath(path); if (!StringUtils.isEmpty(method)) { logger.warn("No method supplied, redirecting."); redirect(method); } else { logger.error("No method supplied."); } } else { final String methodName = pathSections[0]; try { final Method method = getMethod(methodName); invokeMethod(methodName, method); } catch (NoSuchMethodException e) { String msg = "couldn't locate method: " + methodName; logger.warn(msg); getResponse().sendError(HttpServletResponse.SC_NOT_FOUND, msg); } catch (InvocationTargetException e) { // get to the cause and log properly Throwable cause = e.getCause(); if (cause == null) cause = e; handleError(methodName, cause); } catch (Exception e) { handleError(methodName, e); } } } catch (SecurityException e) { logger.warn(e.toString()); } }
From source file:com.haulmont.cuba.web.controllers.StaticContentController.java
protected LookupResult lookupNoCache(HttpServletRequest req) { final String path = getPath(req); if (isForbidden(path)) return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); ServletContext context = req.getSession().getServletContext(); final URL url; try {/*ww w . ja v a 2s.c o m*/ url = context.getResource(path); } catch (MalformedURLException e) { return new Error(HttpServletResponse.SC_BAD_REQUEST, "Malformed path"); } if (url == null) return new Error(HttpServletResponse.SC_NOT_FOUND, "Not found"); final String mimeType = getMimeType(path); final String realpath = context.getRealPath(path); if (realpath != null) { // Try as an ordinary file File f = new File(realpath); if (!f.isFile()) return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); else { return createLookupResult(req, f.lastModified(), mimeType, (int) f.length(), acceptsDeflate(req), url); } } else { try { // Try as a JAR Entry final ZipEntry ze = ((JarURLConnection) url.openConnection()).getJarEntry(); if (ze != null) { if (ze.isDirectory()) return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); else return createLookupResult(req, ze.getTime(), mimeType, (int) ze.getSize(), acceptsDeflate(req), url); } else // Unexpected? return new StaticFile(-1, mimeType, -1, acceptsDeflate(req), url); } catch (ClassCastException e) { // Unknown resource type return createLookupResult(req, -1, mimeType, -1, acceptsDeflate(req), url); } catch (IOException e) { return new Error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); } } }