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:de.micromata.genome.gwiki.web.StaticFileServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getPathInfo(); String servletp = req.getServletPath(); String respath = servletp + uri; if (uri == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;/* w w w.j a va 2s . co m*/ } InputStream is = getServletContext().getResourceAsStream(respath); if (is == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } long nt = new Date().getTime() + TimeInMillis.DAY; String mime = MimeUtils.getMimeTypeFromFile(respath); if (StringUtils.equals(mime, "application/x-shockwave-flash")) { resp.setHeader("Cache-Control", "cache, must-revalidate"); resp.setHeader("Pragma", "public"); } resp.setDateHeader("Expires", nt); resp.setHeader("Cache-Control", "max-age=86400, public"); if (mime != null) { resp.setContentType(mime); } byte[] data = IOUtils.toByteArray(is); IOUtils.closeQuietly(is); resp.setContentLength(data.length); IOUtils.write(data, resp.getOutputStream()); }
From source file:com.collective.celos.servlet.JSONSlotStateServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { String id = req.getParameter(CelosClient.ID_PARAM); try {//from w w w. j av a 2 s . c o m if (id == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing."); return; } SlotID slotID = new SlotID(new WorkflowID(id), getRequestTime(req)); try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { SlotState slotState = connection.getSlotState(slotID); if (slotState == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Slot not found: " + id); } else { ObjectNode object = slotState.toJSONNode(); writer.writeValue(res.getOutputStream(), object); } } } catch (Exception e) { throw new ServletException(e); } }
From source file:com.thinkberg.moxo.dav.GetHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); if (object.exists()) { if (FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; }//from w w w. j a v a2 s. c o m setHeader(response, object.getContent()); InputStream is = object.getContent().getInputStream(); OutputStream os = response.getOutputStream(); Util.copyStream(is, os); is.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:org.openmrs.module.metadatasharing.web.controller.ExceptionResolver.java
/** * @see org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception) */// ww w . j a v a 2 s. c o m @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { if (exception instanceof PackageNotFoundException) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return new ModelAndView("/module/metadatasharing/packageNotFound"); } return null; }
From source file:com.thinkberg.webdav.GetHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); if (object.exists()) { if (FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; }//from w ww. ja v a 2 s. c o m setHeader(response, object.getContent()); InputStream is = object.getContent().getInputStream(); OutputStream os = response.getOutputStream(); Util.copyStream(is, os); is.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:de.highbyte_le.weberknecht.request.error.DefaultErrorHandler.java
@Override public boolean handleException(Exception exception, HttpServletRequest request, RoutingTarget routingTarget) { if (exception instanceof ActionNotFoundException) { log.warn(/*from ww w . j a va2 s .c o m*/ "action not found: " + exception.getMessage() + "; request URI was " + request.getRequestURI()); this.statusCode = HttpServletResponse.SC_NOT_FOUND; //throw 404, if action doesn't exist } else if (exception instanceof ContentProcessingException) { log.error("doGet() - " + exception.getClass().getSimpleName() + ": " + exception.getMessage(), //$NON-NLS-1$ exception); this.statusCode = ((ContentProcessingException) exception).getHttpStatusCode(); //TODO error page with error message or set request attribute to be able to write it on standard error pages } else if (exception instanceof ActionInstantiationException) { log.warn("action could not be instantiated: " + exception.getMessage(), exception); this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500, if action could not instantiated } else if (exception instanceof ProcessingException) { log.error("doGet() - PreProcessingException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else if (exception instanceof DBConnectionException) { log.error("doGet() - DBConnectionException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else if (exception instanceof ActionExecutionException) { log.error("doGet() - ActionExecutionException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else { log.error("doGet() - " + exception.getClass().getSimpleName() + ": " + exception.getMessage(), //$NON-NLS-1$ exception); this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } return true; }
From source file:com.thoughtworks.go.domain.ChecksumFileHandler.java
public boolean handleResult(int returncode, GoPublisher goPublisher) { if (returncode == HttpServletResponse.SC_NOT_FOUND) { deleteQuietly(checksumFile);/*from w w w .j a va 2s. c o m*/ goPublisher.taggedConsumeLineWithPrefix(GoPublisher.ERR, "[WARN] The md5checksum property file was not found on the server. Hence, Go can not verify the integrity of the artifacts."); return true; } if (returncode == HttpServletResponse.SC_NOT_MODIFIED) { LOG.info("[Agent Fetch Artifact] Not downloading checksum file as it has not changed"); return true; } if (returncode == HttpServletResponse.SC_OK) { LOG.info("[Agent Fetch Artifact] Saved checksum property file [{}]", checksumFile); return true; } return returncode < HttpServletResponse.SC_BAD_REQUEST; }
From source file:dtu.ds.warnme.ws.rest.json.HelloWorldRestService.java
@ExceptionHandler(Exception.class) public @ResponseBody String handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader("Content-Type", "application/json"); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return ex.getMessage(); }
From source file:controller.MunicipiosRestController.java
/** * * @param request//from ww w.ja v a2 s . c o m * @param response * @return JSON */ @RequestMapping(method = RequestMethod.GET, produces = "application/json") public String getsJSON(HttpServletRequest request, HttpServletResponse response) { MunicipiosDAO tabla = new MunicipiosDAO(); Gson JSON; List<Municipios> lista; try { lista = tabla.selectAll(); if (lista.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen elementos"); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServer", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } Datos<Municipios> datos = new Datos<>(); datos.setDatos(lista); JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(datos); }
From source file:controller.IndicadoresRestController.java
/** * * @param request// w w w . jav a 2s . c o m * @param response * @return JSON */ @RequestMapping(method = RequestMethod.GET, produces = "application/json") public String getJSON(HttpServletRequest request, HttpServletResponse response) { IndicadoresDAO tabla = new IndicadoresDAO(); Gson JSON; List<Indicadores> lista; try { lista = tabla.selectAll(); if (lista.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen elementos"); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServer", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } Datos<Indicadores> datos = new Datos<>(); datos.setDatos(lista); JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(datos); }