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:com.jaspersoft.jasperserver.remote.services.impl.ResourcesManagementRemoteServiceImpl.java
/** * Find a resource from an uri. This method is exensively used by the services to * manage the repository./* w ww . j a v a 2 s . c om*/ * * @param uri * @return * @throws ServiceException */ public Resource locateResource(String uri, ExecutionContext context) throws ServiceException { try { Resource res = null; String folderName; int sep = uri.lastIndexOf(Folder.SEPARATOR); if (sep >= 0) { folderName = uri.substring(0, sep); } else { // No separator: error throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "jsexception.invalid.uri", new Object[] { uri }); } // Check if the folder is a RU first... if (folderName.endsWith("_files")) { String parentUri = folderName.substring(0, folderName.length() - "_files".length()); if (log.isWarnEnabled()) { log.warn("Loading uri: " + parentUri); } Resource parentRes = repository.getResource(context, parentUri); if (parentRes != null) { // The parent folder is a RU... // Get the resource (quick way to check accessibility....) Resource folderResource = locateResource(folderName); ResourceDescriptor ruRd = createResourceDescriptor(folderResource); if (log.isWarnEnabled()) { log.warn("Loaded RU " + res); } if (ruRd == null) { // The user can not access to this RU... return null; } res = repository.getResource(context, uri); if (log.isWarnEnabled()) { log.warn("Loaded resource " + uri + " " + res); } } } if (res == null) { if (folderName.length() == 0) { folderName = "/"; } res = repository.getResource(context, uri); } if (res == null) // try to look for a folder... { Folder folder = repository.getFolder(context, uri); if (folder != null) { res = folder; } else { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "Could not locate resource: " + uri); } } return res; } catch (ServiceException ex) { throw ex; } catch (Exception ex) { if (ex instanceof AccessDeniedException) { throw new ServiceException(ServiceException.FORBIDDEN, ex.getLocalizedMessage()); } throw new ServiceException(ex); } }
From source file:edu.utsa.sifter.IndexResource.java
@Path("index") @DELETE// w w w .ja v a 2s . c o m @Consumes({ MediaType.APPLICATION_JSON }) public void deleteIndex(IndexInfo idx) { if (idx.Id != null) { IndexReader rdr = State.Indices.remove(idx.Id); if (rdr != null) { return; } } HttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); }
From source file:net.bhira.sample.api.controller.EmployeeController.java
/** * Fetch the instance of {@link net.bhira.sample.model.Employee} represented by given employeeId * and return it as JSON object.// w ww. ja v a 2 s.c o m * * @param employeeId * the ID for {@link net.bhira.sample.model.Employee}. * @param response * the http response to which the results will be written. * @return an instance of {@link net.bhira.sample.model.Employee} as JSON. */ @RequestMapping(value = "/employee/{employeeId}", method = RequestMethod.GET) @ResponseBody public Callable<String> getEmployee(@PathVariable long employeeId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { String body = ""; try { LOG.debug("servicing GET employee/{}", employeeId); Employee employee = employeeService.load(employeeId); LOG.debug("GET employee/{}, found = {}", employeeId, employee != null); if (employee == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { body = JsonUtil.createGson().toJson(employee); } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error loading employee/{}. {}", employeeId, body); LOG.debug("Load error stacktrace: ", ex); } return body; } }; }
From source file:jp.terasoluna.fw.web.struts.actions.ForwardAction.java
/** * parameter??J?/* w ww. j av a 2 s .c o m*/ * ANVtH??[hZbg?B * parameter?????A * J?_?tH??[h"success" * ANVtH??[h?B * ????A?i404?jG?[?B * * @param mapping ANV}bsO * @param form ANVtH?[ * @param req HTTPNGXg * @param res HTTPX|X * @return J?ANVtH??[h */ @SuppressWarnings("deprecation") @Override public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { if (log.isDebugEnabled()) { log.debug("doExecute() called."); } // parameter??itH??[h??j String path = mapping.getParameter(); // ANVtH??[h?? ActionForward retVal = null; if (path == null) { // ActionMappingActionForward retVal = mapping.findForward(FORWARD_SUCCESS); // ActionFoward??? if (retVal == null) { // parameter??Aforwardvf????A // ?i404?jG?[p try { res.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (IOException e) { log.error("Error page(404) forwarding failed."); throw new SystemException(e, FORWARD_ERRORPAGE_ERROR); } return null; } return retVal; } retVal = new ActionForward(path); // contextRelative?l String contextRelativeStr = PropertyUtil.getProperty(FORWARD_ACTION_CONTEXT_RELATIVE_KEY, Boolean.FALSE.toString()); Boolean contextRelative = new Boolean(contextRelativeStr); // ActionForwardcontextRelativel? retVal.setContextRelative(contextRelative); if (log.isDebugEnabled()) { StringBuilder debugLog = new StringBuilder(); debugLog.append("contextRelative:"); debugLog.append(contextRelative); log.debug(debugLog.toString()); } return retVal; }
From source file:com.sun.faban.harness.webclient.CLIServlet.java
private void sendStatus(String[] reqC, HttpServletResponse response) throws IOException { if (reqC.length < 2) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing RunId."); return;/*ww w . j a v a 2 s . c om*/ } String runId = reqC[1]; String status = RunResult.getStatus(new RunId(runId)); if (status == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No such runId: " + runId); } else { Writer w = response.getWriter(); w.write(status + '\n'); w.flush(); w.close(); } }
From source file:it.cnr.icar.eric.server.interfaces.rest.RestServlet.java
/** Handles the HTTP <code>GET</code> method. * @param request servlet request// w w w .j a va 2 s . co m * @param response servlet response */ @SuppressWarnings("static-access") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String interfase = request.getParameter("interface"); try { if ((interfase == null) || interfase.equals("")) { //First check if it is a user defined URL since that is less expensive to match UserDefinedURLHandler udefURLHandler = new UserDefinedURLHandler(request, response); try { udefURLHandler.processGetRequest(); response.setStatus(response.SC_OK); } catch (ObjectNotFoundException e) { FilePathURLHandler filePathURLHandler = new FilePathURLHandler(request, response); filePathURLHandler.processGetRequest(); response.setStatus(response.SC_OK); } } else if (interfase.equalsIgnoreCase("QueryManager")) { QueryManagerURLHandler qmURLHandler = new QueryManagerURLHandler(request, response); qmURLHandler.processGetRequest(); response.setStatus(response.SC_OK); } else if (interfase.equalsIgnoreCase("LifeCycleManager")) { LifeCycleManagerURLHandler lcmURLHandler = new LifeCycleManagerURLHandler(request, response); lcmURLHandler.processGetRequest(); response.setStatus(response.SC_OK); } else if (extendedInterfaces.containsKey(interfase)) { String className = extendedInterfaces.get(interfase).toString(); URLHandler handler = createURLHandlerInstance(className, request, response); if (handler != null) { handler.processGetRequest(); response.setStatus(response.SC_OK); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request. Unknown interface: " + interfase); } } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request. Unknown interface: " + interfase); } } catch (ObjectNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } catch (InvalidRequestException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } catch (UnimplementedException e) { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, e.getMessage()); } catch (RegistryException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:controller.TemasNivel2RestController.java
/** * * @param id/*from w w w. ja v a 2s. c o m*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}/temasnivel3", method = RequestMethod.GET, produces = "application/json") public String getMunicipiosJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel2DAO tabla = new TemasNivel2DAO(); Gson JSON; List<TemasNivel3> lista; try { lista = tabla.selectAllTemasNivel3(id); 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<TemasNivel3> datos = new Datos<>(); datos.setDatos(lista); JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(datos); }
From source file:controller.TemasNivel1RestController.java
/** * * @param id/* w w w . j av a 2 s. co m*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}/temasnivel2", method = RequestMethod.GET, produces = "application/json") public String getMunicipiosJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel1DAO tabla = new TemasNivel1DAO(); Gson JSON; List<TemasNivel2> lista; try { lista = tabla.selectAllTemasNivel2(id); 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<TemasNivel2> datos = new Datos<>(); datos.setDatos(lista); JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(datos); }
From source file:com.novartis.pcs.ontology.rest.servlet.SynonymsServlet.java
private void serialize(String datasourceAcronym, String vocabRefId, boolean pending, HttpServletResponse response) {/*from w ww . ja v a 2 s .c om*/ try { List<SynonymDTO> dtos = new ArrayList<SynonymDTO>(1024); Datasource datasource = datasourceDAO.loadByAcronym(datasourceAcronym); if (datasource != null) { Collection<Synonym> synonyms = vocabRefId != null ? synonymDAO.loadByCtrldVocabRefId(datasource, vocabRefId) : synonymDAO.loadByDatasource(datasource); EnumSet<Status> statusSet = pending ? EnumSet.of(Status.PENDING, Status.APPROVED) : EnumSet.of(Status.APPROVED); for (Synonym synonym : synonyms) { if (statusSet.contains(synonym.getStatus())) { dtos.add(new SynonymDTO(synonym)); } } } if (!dtos.isEmpty()) { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Access-Control-Allow-Origin", "*"); response.setContentType(MEDIA_TYPE_JSON + ";charset=utf-8"); response.setHeader("Cache-Control", "public, max-age=0"); // As per jackson javadocs - Encoding will be UTF-8 mapper.writeValue(response.getOutputStream(), dtos); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); } } catch (Exception e) { log("Failed to serialize synonyms to JSON", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentLength(0); } }