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:controller.TemasNivel1RestController.java
/** * * @param request// w w w .ja va 2s .c o m * @param response * @return XML */ @RequestMapping(method = RequestMethod.GET, produces = "application/xml") public String getXML(HttpServletRequest request, HttpServletResponse response) { TemasNivel1DAO tabla = new TemasNivel1DAO(); XStream XML; List<TemasNivel1> lista; try { lista = tabla.selectAll(); if (lista.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen elementos"); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } Datos<TemasNivel1> datos = new Datos<>(); datos.setDatos(lista); XML = new XStream(); XML.alias("Temas-Nivel-1", TemasNivel1.class); response.setStatus(HttpServletResponse.SC_OK); return XML.toXML(lista); }
From source file:controller.TemasNivel2RestController.java
/** * * @param request// ww w .jav a 2 s . c o m * @param response * @return XML */ @RequestMapping(method = RequestMethod.GET, produces = "application/xml") public String getXML(HttpServletRequest request, HttpServletResponse response) { TemasNivel2DAO tabla = new TemasNivel2DAO(); XStream XML; List<TemasNivel2> lista; try { lista = tabla.selectAll(); if (lista.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen elementos"); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } Datos<TemasNivel2> datos = new Datos<>(); datos.setDatos(lista); XML = new XStream(); XML.alias("tema-nivel-2", TemasNivel2.class); response.setStatus(HttpServletResponse.SC_OK); return XML.toXML(lista); }
From source file:net.longfalcon.web.WebExceptionHandlerResolver.java
private ModelAndView handleNoSuchResource(NoSuchResourceException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); _log.error(ex, ex);//from ww w . jav a2s .c o m return new ModelAndView(); }
From source file:controller.TemasNivel3RestController.java
/** * * @param request//from w ww .j a va2s . c om * @param response * @return XML */ @RequestMapping(method = RequestMethod.GET, produces = "application/xml") public String getXML(HttpServletRequest request, HttpServletResponse response) { TemasNivel3DAO tabla = new TemasNivel3DAO(); XStream XML; List<TemasNivel3> lista; try { lista = tabla.selectAll(); if (lista.isEmpty()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existen elementos"); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); XML = new XStream(); XML.alias("message", Error.class); return XML.toXML(e); } Datos<TemasNivel3> datos = new Datos<>(); datos.setDatos(lista); XML = new XStream(); XML.alias("tema-nivel-3", TemasNivel3.class); response.setStatus(HttpServletResponse.SC_OK); return XML.toXML(lista); }
From source file:com.baidu.jprotobuf.rpc.server.HttpRequestHandlerServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String context = request.getPathInfo(); if (context == null) { LOGGER.warn("invalid request path."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return;/* w ww .j ava2s.c o m*/ } else { if (context.startsWith("/")) { context = context.substring(1); } if (!serviceMap.containsKey(context)) { LOGGER.warn("invalid request path service name[" + context + "] not found."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } } try { ServiceExporter idlServiceExporter = serviceMap.get(context); //to check if a get idl request if (request.getParameter(ServiceExporter.INPUT_IDL_PARAMETER) != null) { String inputIDL = idlServiceExporter.getInputIDL(); if (inputIDL != null) { response.setContentLength(inputIDL.length()); response.getOutputStream().write(inputIDL.getBytes()); return; } } else if (request.getParameter(ServiceExporter.OUTPUT_IDL_PARAMETER) != null) { String outputIDL = idlServiceExporter.getOutputIDL(); if (outputIDL != null) { response.setContentLength(outputIDL.length()); response.getOutputStream().write(outputIDL.getBytes()); return; } } IDLProxyObject inputIDLProxyObject = idlServiceExporter.getInputProxyObject(); IDLProxyObject input = null; if (inputIDLProxyObject != null && request.getContentLength() > 0) { byte[] bytes = readStream(request.getInputStream(), request.getContentLength()); input = inputIDLProxyObject.decode(bytes); } IDLProxyObject result = idlServiceExporter.execute(input); if (result != null) { byte[] bytes = result.encode(); response.setContentLength(bytes.length); response.getOutputStream().write(bytes); } } catch (Exception ex) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); } finally { response.getOutputStream().flush(); response.getOutputStream().close(); } }
From source file:com.devnexus.ting.web.filter.LoggingFilter4Logback.java
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { final HttpServletResponse response; final HttpServletRequest request; if (res instanceof HttpServletResponse) { response = (HttpServletResponse) res; } else {/*from w ww. j ava 2s.c o m*/ throw new IllegalStateException("Cannot cast ServletResponse to HttpServletResponse."); } if (req instanceof HttpServletRequest) { request = (HttpServletRequest) req; } else { throw new IllegalStateException("Cannot cast ServletRequest to HttpServletRequest."); } final ErrorAwareHttpServletResponseWrapper errorAwareResponse = new ErrorAwareHttpServletResponseWrapper( response); final String username; if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { username = SecurityContextHolder.getContext().getAuthentication().getName(); } else { username = null; } final String sessionId = request.getSession().getId(); final String requestUrl = request.getRequestURL().toString(); MDC.put("username", username); MDC.put("sessionId", sessionId); MDC.put("requestUrl", requestUrl); try { chain.doFilter(request, errorAwareResponse); if (HttpServletResponse.SC_NOT_FOUND == errorAwareResponse.getErrorCode()) { LOGGER.error("Page '" + request.getServletPath() + "' was not found."); } } finally { MDC.remove("username"); MDC.remove("sessionId"); MDC.remove("requestUrl"); } }
From source file:com.springsource.greenhouse.home.GlobalExceptionResolver.java
private ModelAndView handleEmptyResultDataAccessException(EmptyResultDataAccessException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { response.sendError(HttpServletResponse.SC_NOT_FOUND); return new ModelAndView(); }
From source file:com.natpryce.piazza.BuildMonitorController.java
private ModelAndView showBuildType(String buildTypeId, HttpServletResponse response) throws IOException { SBuildType buildType = projectManager.findBuildTypeByExternalId(buildTypeId); if (buildType == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "no build type with id " + buildTypeId); return null; }/*from w w w . j a v a2 s . c o m*/ return modelWithView("piazza-build-type-monitor.jsp").addObject("build", new BuildTypeMonitorViewState(buildType, piazza.userGroup(), piazza.isShowOnFailureOnly())); }