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.europeana.core.util.web.ExceptionResolver.java
private ModelAndView ajaxFailure(HttpServletRequest request, HttpServletResponse response, Exception e) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); ModelAndView page = ThemeFilter.createThemedModelAndViewPage("xml/ajax"); page.addObject("success", false); page.addObject("exception", getStackTrace(e)); clickStreamLogger.logUserAction(request, ClickStreamLogger.UserAction.AJAX_ERROR); log.warn("Problem handling AJAX request", e); return page;/*from w ww. j a v a 2s . c o m*/ }
From source file:io.wcm.caravan.io.http.impl.ResilientHttpImplTest.java
@Test public void testHttp404() { Observable<Response> observable = underTest.execute(SERVICE_NAME, new RequestTemplate().append(HTTP_404_URI).request()); Response response = observable.toBlocking().single(); assertEquals(HttpServletResponse.SC_NOT_FOUND, response.status()); }
From source file:de.unirostock.sems.cbarchive.web.servlet.DownloadServlet.java
private void downloadArchive(HttpServletRequest request, HttpServletResponse response, UserManager user, String archive) throws IOException { // filters for omex extension // ( is just there for the browser to name the downloaded file correctly) if (archive.endsWith("." + COMBINEARCHIVE_FILE_EXT)) // just removes the file extension -> we get the archiveId archive = archive.substring(0, archive.length() - (COMBINEARCHIVE_FILE_EXT.length() + 1)); File archiveFile = null;//w w w . ja va2 s .c om String archiveName = null; try { archiveFile = user.getArchiveFile(archive); archiveName = user.getArchive(archive, false).getName(); } catch (FileNotFoundException | CombineArchiveWebException e) { LOGGER.warn(e, MessageFormat.format( "FileNotFound Exception, while handling donwload request for Archive {1} in Workspace {0}", user.getWorkingDir(), archive)); response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); return; } // set MIME-Type to something downloadable response.setContentType("application/octet-stream"); // set Content-Length response.setContentLength((int) archiveFile.length()); // set the filename of the downloaded file response.addHeader("Content-Disposition", MessageFormat.format("inline; filename=\"{0}.{1}\"", archiveName, COMBINEARCHIVE_FILE_EXT)); // print the file to the output stream try { OutputStream output = response.getOutputStream(); InputStream input = new FileInputStream(archiveFile); // copy the streams IOUtils.copy(input, output); // flush'n'close output.flush(); output.close(); input.close(); response.flushBuffer(); } catch (IOException e) { LOGGER.error(e, MessageFormat.format( "IOException, while copying streams by handling donwload request for Archive {1} in Workspace {0}", user.getWorkingDir(), archive)); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "IOException while sending the file."); } }
From source file:com.xpn.xwiki.web.sx.AbstractSxAction.java
/** * {@inheritDoc}/* w ww. j a va 2 s.c o m*/ * * @see XWikiAction#render(XWikiContext) */ @Override public String render(XWikiContext context) throws XWikiException { SxSource sxSource; if (context.getRequest().getParameter(JAR_RESOURCE_REQUEST_PARAMETER) != null) { sxSource = new SxResourceSource(context.getRequest().getParameter(JAR_RESOURCE_REQUEST_PARAMETER)); } else { if (context.getDoc().isNew()) { context.getResponse().setStatus(HttpServletResponse.SC_NOT_FOUND); return "docdoesnotexist"; } sxSource = new SxDocumentSource(context, getExtensionType()); } try { renderExtension(sxSource, getExtensionType(), context); } catch (IllegalArgumentException e) { // Simply set a 404 status code and return null, so that no unneeded bytes are transfered context.getResponse().setStatus(HttpServletResponse.SC_NOT_FOUND); } return null; }
From source file:es.tid.cep.esperanza.Rules.java
/** * Handles the HTTP <code>DELETE</code> method. * * @param request servlet request//from w w w . j a v a 2s .c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("application/json;charset=UTF-8"); try { String ruleName = request.getPathInfo(); ruleName = ruleName == null ? "" : ruleName.substring(1); logger.debug("rule asked for " + ruleName); EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); out.printf("{\"error\":\"%s not found\"}\n", ruleName); } else { st.destroy(); out.println(Utils.Statement2JSONObject(st)); } } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); out.println("{\"error\":\"not rule specified for deleting\"}"); } } catch (EPException epe) { logger.error("deleting statement", epe); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.printf("{\"error\":%s}\n", JSONObject.valueToString(epe.getMessage())); } finally { out.close(); } }
From source file:com.wavemaker.runtime.module.ModuleController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String requestURI = request.getRequestURI(); final String moduleURI = "/" + MODULES_PREFIX; final String moduleURIAbs = moduleURI + "/"; final String moduleJsURI = moduleURIAbs + MODULES_JS; final String epURI = moduleURIAbs + EXTENSION_PATH; final String epURIAbs = epURI + "/"; final String idURI = moduleURIAbs + ID_PATH; final String idURIAbs = idURI + "/"; // trim off the servlet name requestURI = requestURI.substring(requestURI.indexOf('/', 1)); if (moduleURI.equals(requestURI) || moduleURIAbs.equals(requestURI)) { } else if (epURI.equals(requestURI) || epURIAbs.equals(requestURI)) { Set<String> names = this.moduleManager.listExtensionPoints(); response.setContentType("text/html"); Writer writer = response.getWriter(); writer.write("<html><body>\n"); for (String ext : names) { writer.write(ext + "<br />\n"); }// ww w .ja v a 2 s. co m writer.write("</body></html>\n"); writer.close(); } else if (idURI.equals(requestURI) || idURIAbs.equals(requestURI)) { Set<String> names = this.moduleManager.listModules(); response.setContentType("text/html"); Writer writer = response.getWriter(); writer.write("<html><body>\n"); for (String ext : names) { writer.write(ext + "<br />\n"); } writer.write("</body></html>\n"); writer.close(); } else if (moduleJsURI.equals(requestURI)) { Set<String> extensions = this.moduleManager.listExtensionPoints(); JSONObject jo = new JSONObject(); JSONObject extJO = new JSONObject(); for (String extension : extensions) { JSONArray ja = new JSONArray(); List<ModuleWire> wires = this.moduleManager.getModules(extension); for (ModuleWire wire : wires) { ja.add(wire.getName()); } extJO.put(extension, ja); } jo.put("extensionPoints", extJO); response.setContentType(ServerConstants.JSON_CONTENT_TYPE); Writer writer = response.getWriter(); writer.write(jo.toString()); writer.close(); } else { Tuple.Two<ModuleWire, String> tuple = parseRequestPath(requestURI); if (tuple.v1 == null) { String message = MessageResource.NO_MODULE_RESOURCE.getMessage(requestURI, tuple.v2); this.logger.error(message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); Writer outputWriter = response.getWriter(); outputWriter.write(message); return null; } URL url = this.moduleManager.getModuleResource(tuple.v1, tuple.v2); URLConnection conn = url.openConnection(); if (SystemUtils.IS_OS_WINDOWS) { conn.setDefaultUseCaches(false); } response.setContentType(conn.getContentType()); OutputStream os = null; InputStream is = null; try { os = response.getOutputStream(); is = conn.getInputStream(); IOUtils.copy(conn.getInputStream(), os); } finally { if (os != null) { os.close(); } if (is != null) { is.close(); } } } return null; }
From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { WSRole role = restUtils.populateServiceObject(req.getPathInfo(), req.getParameterMap(), WSRole.class); WSRoleSearchCriteria criteria = restUtils.populateServiceObject(req.getPathInfo(), req.getParameterMap(), WSRoleSearchCriteria.class); WSRole[] roles = null;//from w w w. j a va2 s .c o m try { roles = userAndRoleManagementService.findRoles(criteria); if (roles != null && roles.length != 0) { userAndRoleManagementService.deleteRole(role); if (log.isDebugEnabled()) { log.debug(role + " role were deleted"); } } else { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "role: " + role + " was not found"); } } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, axisFault.getLocalizedMessage()); } restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTReport.java
/** * The get method get resources of a produced report * Urls in this case look like /reports/samples/myreport;uniqueidentifier?file=filename */// ww w . ja va2 s . co m @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Get the uri of the resource String uuid = restUtils.extractRepositoryUri(req.getPathInfo()); if (uuid.startsWith("/")) uuid = uuid.substring(1); // Add all the options... Map<String, String> options = new HashMap<String, String>(); // Add as option all the GET parameters... Enumeration en = req.getParameterNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); options.put(key, req.getParameter(key)); } // Find the report in session... HttpSession session = req.getSession(); Report report = (Report) session.getAttribute(uuid); if (report == null) { restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp, "Report not found (uuid not found in session)"); return; } JasperPrint jp = report.getJasperPrint(); // highcharts report for REST v1 is by default noninteractive. if (!options.containsKey(Argument.PARAM_INTERACTIVE)) { options.put(Argument.PARAM_INTERACTIVE, Boolean.FALSE.toString()); } OperationResult or = runReportService.exportReport(report.getOriginalUri(), jp, options, report.getAttachments()); if (or.getReturnCode() != 0) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, or.getMessage()); return; } else { // If the jasperprint is present as attribute, it means it has been modified // in some way (i.e. using a RUN_TRANSFORMER_KEY). if (runReportService.getAttributes().get("jasperPrint") != null) { jp = (JasperPrint) runReportService.getAttributes().get("jasperPrint"); report.setJasperPrint(jp); } // Send out the xml... resp.setContentType("text/xml; charset=UTF-8"); restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, report.toXml()); } }
From source file:net.riezebos.thoth.servlets.ThothServlet.java
@Override protected void handleRequest(HttpServletRequest request, HttpServletResponse response, CommandOperation operation) throws ServletException, IOException, ContentManagerException { try {//w w w .ja v a 2 s . c o m if (!handleCommand(request, response, operation)) { String context = getContext(request); String path = getPath(request); if (("/" + context).equalsIgnoreCase(ContentManager.NATIVERESOURCES)) streamClassPathResource(path, request, response); else if (StringUtils.isBlank(context) && StringUtils.isBlank(path)) handleMainIndex(request, response, operation); else if (StringUtils.isBlank(path)) executeCommand(contextIndexCommand, request, response, operation); else { if (!renderDocument(request, response)) streamResource(request, response); } } } catch (ContextNotFoundException e) { LOG.info("404 on request " + request.getRequestURI()); response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:gr.cti.android.experimentation.controller.PluginController.java
/** * Get an existing plugin./*ww w .j a va 2 s . co m*/ * * @param response the HTTP response object. * @param pluginId the id of the plugin to update. */ @ResponseBody @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET, produces = "application/json") public Object getPlugin(HttpServletResponse response, @PathVariable("pluginId") final long pluginId) throws IOException { final ApiResponse apiResponse = new ApiResponse(); final Plugin storedPlugin = pluginRepository.findById((int) pluginId); if (storedPlugin != null) { LOGGER.info("getPlugin: " + storedPlugin); apiResponse.setStatus(HttpServletResponse.SC_OK); apiResponse.setMessage("ok"); apiResponse.setValue(storedPlugin); return apiResponse; } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "no plugin found with the given id"); } return null; }