List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc, String msg) throws IOException;
Sends an error response to the client using the specified status and clears the buffer.
From source file:net.sylvek.sharemyposition.server.RetrievePositionServletImpl.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String uuid = request.getParameter(UpdatePositionServletImpl.PARAMETER_UUID); if (uuid == null || uuid.trim().equals("")) { response.sendError(HttpStatus.SC_BAD_REQUEST, "?uuid= mandatory"); }/*from w ww . j a va2 s .c o m*/ final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService(); syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO)); final Object inMemory = syncCache.get(uuid); if (inMemory == null) { response.sendError(HttpStatus.SC_NOT_FOUND, "element not found"); } final Cache cache = Cache.from(inMemory); response.getWriter().write(cache.toString()); }
From source file:com.netflix.genie.web.controllers.GenieExceptionMapper.java
/** * Handle MethodArgumentNotValid exceptions. * * @param response The HTTP response/* w w w . java 2s.c o m*/ * @param e The exception to handle * @throws IOException on error in sending error */ @ExceptionHandler(MethodArgumentNotValidException.class) public void handleMethodArgumentNotValidException(final HttpServletResponse response, final MethodArgumentNotValidException e) throws IOException { this.countException(e); log.error(e.getMessage(), e); response.sendError(HttpStatus.PRECONDITION_FAILED.value(), e.getMessage()); }
From source file:com.ecyrd.jspwiki.dav.WikiDavServlet.java
@Override public void doMkCol(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getContentLength() > 0) { response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Message may contain no body"); } else {//from www . java2 s . co m response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only."); } }
From source file:com.thoughtworks.go.server.controller.PropertiesController.java
@RequestMapping(value = "/repository/restful/properties/post", method = RequestMethod.POST) public void setProperty(@RequestParam("pipelineName") String pipelineName, @RequestParam("pipelineCounter") String pipelineCounter, @RequestParam("stageName") String stageName, @RequestParam("stageCounter") String stageCounter, @RequestParam("jobName") String buildName, @RequestParam("property") String property, @RequestParam("value") String value, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!headerConstraint.isSatisfied(request)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required header 'Confirm'"); return;/*from ww w.j a v a 2 s . c o m*/ } JobIdentifier jobIdentifier; try { jobIdentifier = restfulService.findJob(pipelineName, pipelineCounter, stageName, stageCounter, buildName); } catch (Exception e) { BasicRestfulAction.jobNotFound( new JobIdentifier(pipelineName, -1, pipelineCounter, stageName, stageCounter, buildName)) .respond(response); return; } Long id = jobIdentifier.getBuildId(); propertyService.addProperty(id, property, value).respond(response); }
From source file:com.sastix.cms.common.services.web.ExceptionHandlingController.java
@ExceptionHandler({ CommonException.class }) public void handleBadRequests(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException { LOG.error("Bad request: {} from {}, Exception: {} {}", request.getRequestURI(), request.getRemoteHost(), e.getStackTrace()[0].toString(), e.getLocalizedMessage()); response.sendError(HttpStatus.BAD_REQUEST.value(), e.getLocalizedMessage()); }
From source file:com.collective.celos.servlet.JSONWorkflowSlotsServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { String id = req.getParameter(CelosClient.ID_PARAM); try {/*from ww w .j av a 2 s . c om*/ if (id == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing."); return; } Scheduler scheduler = getOrCreateCachedScheduler(); Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id)); if (wf == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id); return; } ScheduledTime endTime = getTimeParam(req, CelosClient.END_TIME_PARAM, new ScheduledTime(DateTime.now(DateTimeZone.UTC))); ScheduledTime startTime = getTimeParam(req, CelosClient.START_TIME_PARAM, scheduler.getWorkflowStartTime(wf, endTime)); if (startTime.plusHours(scheduler.getSlidingWindowHours()).getDateTime() .isBefore(endTime.getDateTime())) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Time interval between start and end is limited to: " + scheduler.getSlidingWindowHours() + " hours"); return; } try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { List<SlotState> slotStates = scheduler.getSlotStates(wf, startTime, endTime, connection); List<JsonNode> objectNodes = Lists.newArrayList(); for (SlotState state : Lists.reverse(slotStates)) { objectNodes.add(state.toJSONNode()); } ObjectNode node = Util.MAPPER.createObjectNode(); node.put(CelosClient.INFO_NODE, (JsonNode) Util.MAPPER.valueToTree(wf.getWorkflowInfo())); node.put(CelosClient.PAUSE_NODE, connection.isPaused(wf.getID())); node.putArray(CelosClient.SLOTS_NODE).addAll(objectNodes); writer.writeValue(res.getOutputStream(), node); } } catch (Exception e) { throw new ServletException(e); } }
From source file:org.kurento.repository.RepositoryController.java
@RequestMapping(method = RequestMethod.GET, value = "/{itemId}/metadata") public Map<String, String> getRepositoryItemMetadata(@PathVariable("itemId") String itemId, HttpServletResponse response) { try {/*from w w w . ja v a 2s . c om*/ return repoService.getRepositoryItemMetadata(itemId); } catch (ItemNotFoundException e) { try { response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); throw new KurentoException(ioe); } return null; } }
From source file:gov.nih.nci.nbia.servlet.DownloadServletV2.java
private void sendAccessDenial(HttpServletResponse response) throws IOException { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied"); }
From source file:org.kurento.repository.RepositoryController.java
@RequestMapping(method = RequestMethod.PUT, value = "/{itemId}/metadata") public void setRepositoryItemMetadata(@RequestBody(required = true) Map<String, String> metadata, @PathVariable("itemId") String itemId, HttpServletResponse response) { try {/*from w ww. j av a 2 s . c om*/ repoService.setRepositoryItemMetadata(itemId, metadata); } catch (ItemNotFoundException e) { try { response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); throw new KurentoException(ioe); } } }
From source file:net.myrrix.web.servlets.RecommendToAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;//from w ww. ja va 2 s.c o m } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); Pair<long[], float[]> itemIDsAndValue; try { itemIDsAndValue = parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } long[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); MyrrixRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { IDRescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request)); Iterable<RecommendedItem> recommended = recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer); output(request, response, recommended); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }