List of usage examples for javax.servlet.http HttpServletResponse SC_NO_CONTENT
int SC_NO_CONTENT
To view the source code for javax.servlet.http HttpServletResponse SC_NO_CONTENT.
Click Source Link
From source file:com.fpmislata.banco.presentacion.CreditoController.java
@RequestMapping(value = { "/Credito/{idCuentaBancaria}" }, method = RequestMethod.POST) public void insert(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse, @PathVariable("idCuentaBancaria") int idCuentaBancaria, @RequestBody String json) throws JsonProcessingException { try {/*from w w w. ja va 2s .c om*/ ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); Credito credito = (Credito) objectMapper.readValue(json, Credito.class); CuentaBancaria cuentaBancaria = cuentaBancariaDAO.read(idCuentaBancaria); credito.setCuentaBancaria(cuentaBancaria); credito.setFecha(new Date()); boolean ok = creditoDAO.comprobarCredito(credito.getCuentaBancaria().getUsuario()); if (ok) { // ======================= Credito ============================= // creditoDAO.insert(credito); // ======================= Movimiento ============================= // MovimientoBancario movimientoBancario = new MovimientoBancario(); movimientoBancario.setConcepto("Credito Bitbank"); movimientoBancario.setFecha(new Date()); movimientoBancario.setImporte(credito.getImporte()); movimientoBancario.setTipoMovimientoBancario(TipoMovimientoBancario.Haber); movimientoBancario.setCuentaBancaria(credito.getCuentaBancaria()); movimientoBancarioDAO.insert(movimientoBancario); noCache(httpServletResponse); httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { noCache(httpServletResponse); httpServletResponse.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); } } catch (ConstraintViolationException cve) { List<BussinesMessage> errorList = new ArrayList(); ObjectMapper jackson = new ObjectMapper(); System.out.println("No se ha podido insertar la Cuenta Bancaria debido a los siguientes errores:"); for (ConstraintViolation constraintViolation : cve.getConstraintViolations()) { String datos = constraintViolation.getPropertyPath().toString(); String mensage = constraintViolation.getMessage(); BussinesMessage bussinesMessage = new BussinesMessage(datos, mensage); errorList.add(bussinesMessage); } String jsonInsert = jackson.writeValueAsString(errorList); noCache(httpServletResponse); httpServletResponse.setStatus(httpServletResponse.SC_BAD_REQUEST); } catch (Exception ex) { noCache(httpServletResponse); httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { noCache(httpServletResponse); ex.printStackTrace(httpServletResponse.getWriter()); } catch (Exception ex1) { noCache(httpServletResponse); } } }
From source file:org.nuxeo.ecm.platform.ui.web.download.BlobDownloadServlet.java
private boolean isBlobFound(Blob blob, HttpServletResponse resp) throws ServletException { if (blob == null) { try {//www . j av a 2s. c o m resp.sendError(HttpServletResponse.SC_NO_CONTENT, "No Blob found"); return false; } catch (IOException e) { throw new ServletException(e); } } else if (BLOB_NOT_FOUND.equals(blob)) { try { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No Blob found"); return false; } catch (IOException e) { throw new ServletException(e); } } return true; }
From source file:org.alfresco.module.vti.web.fp.DeleteMethod.java
@Override protected void executeImpl() throws WebDAVServerException, Exception { try {/*from ww w . j a v a2s . c o m*/ super.executeImpl(); m_response.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (WebDAVServerException e) { if (e.getHttpStatusCode() == WebDAV.WEBDAV_SC_LOCKED) { // SharePoint requires a special response for the case of // trying to delete a locked document m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); m_response.setContentType(WebDAV.XML_CONTENT_TYPE); m_response.addHeader(HEADER_X_MSDAVEXT_ERROR, "589838"); // TODO Don't hard code this constant XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(namespaceMap); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE, getDAVHelper().getNullAttributes()); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(m_request.getRequestURL().toString()); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, getDAVHelper().getNullAttributes()); xml.write(WebDAV.HTTP1_1 + " " + WebDAV.WEBDAV_SC_LOCKED + " " + SC_LOCKED_DESC); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data flushXML(xml); } else { throw e; } } }
From source file:com.google.api.server.spi.response.ServletResponseResultWriter.java
@Override public void write(Object response) throws IOException { if (response == null) { write(HttpServletResponse.SC_NO_CONTENT, null, null); } else {/*from ww w .j a v a 2 s .c o m*/ write(HttpServletResponse.SC_OK, null, writeValueAsString(ResponseUtil.wrapCollection(response))); } }
From source file:byps.http.HActiveMessages.java
/** * This function is called when a new message arrives in onPost * @param header/*from www . j a va 2s .c om*/ * @param rctxt * @param workerThread * @throws BException */ public void addMessage(final BMessageHeader header, final HRequestContext rctxt, final Thread workerThread) throws BException { if (log.isDebugEnabled()) log.debug("addMessage(" + header + ", rctxt=" + rctxt); HActiveMessage msg = getOrCreateActiveMessage(header.messageId); msg.setSessionid(header.sessionId); HAsyncErrorListener alsn = new HAsyncErrorListener() { @Override public void onTimeout(AsyncEvent arg0) throws IOException { HRequestContext rctxt = getAndRemoveRequestContext(header.messageId); if (rctxt == null) return; HttpServletResponse resp = (HttpServletResponse) arg0.getSuppliedResponse(); boolean isLongPoll = (header.flags & BMessageHeader.FLAG_LONGPOLL) != 0; int status = isLongPoll ? HttpServletResponse.SC_NO_CONTENT : HttpServletResponse.SC_REQUEST_TIMEOUT; resp.setStatus(status); resp.getOutputStream().close(); if (log.isDebugEnabled()) log.debug("AsyncErrorListener.onTimeout(" + arg0 + ") status=" + status); } @Override public void onError(AsyncEvent arg0) throws IOException { if (log.isDebugEnabled()) log.debug("AsyncErrorListener.onError(" + arg0 + ")"); getAndRemoveRequestContext(header.messageId); } }; rctxt.addListener(alsn); msg.setRequestContext(rctxt, workerThread); if (log.isDebugEnabled()) log.debug(")addMessage"); }
From source file:org.gooru.insights.api.spring.exception.InsightsExceptionResolver.java
public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {/*from www . jav a2 s . co m*/ ResponseParamDTO<Map<Object, Object>> responseDTO = new ResponseParamDTO<Map<Object, Object>>(); Map<Object, Object> errorMap = new HashMap<Object, Object>(); Integer statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String traceId = request.getAttribute("traceId") != null ? request.getAttribute("traceId").toString() : DEFAULT_TRACEID; if (ex instanceof BadRequestException) { statusCode = HttpServletResponse.SC_BAD_REQUEST; } else if (ex instanceof AccessDeniedException) { statusCode = HttpServletResponse.SC_FORBIDDEN; } else if (ex instanceof NotFoundException) { statusCode = HttpServletResponse.SC_NOT_FOUND; } else { statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } if (statusCode.toString().startsWith(Numbers.FOUR.getNumber())) { InsightsLogger.debug(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, ex.getMessage()); } else if (statusCode.toString().startsWith(Numbers.FIVE.getNumber())) { InsightsLogger.error(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, DEFAULT_ERROR); } else if (statusCode.equals(HttpServletResponse.SC_NO_CONTENT)) { InsightsLogger.error(traceId, ex); errorMap.put(DEVELOPER_MESSAGE, CONTENT_UNAVAILABLE); } errorMap.put(STATUS_CODE, statusCode); errorMap.put(MAIL_To, SUPPORT_EMAIL_ID); response.setStatus(statusCode); responseDTO.setMessage(errorMap); return new ModelAndView(modelAttributes.VIEW_NAME.getAttribute(), modelAttributes.RETURN_NAME.getAttribute(), new JSONSerializer().exclude(ApiConstants.EXCLUDE_CLASSES).deepSerialize(responseDTO)); }
From source file:org.nema.medical.mint.server.controller.ChangeLogController.java
@RequestMapping("/changelog") public void changelogXML(@RequestParam(value = "since", required = false) final String since, @RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "consolidate", required = false, defaultValue = "true") boolean consolidate, final HttpServletResponse res) throws IOException, JiBXException { final List<org.nema.medical.mint.changelog.Change> changes = new ArrayList<org.nema.medical.mint.changelog.Change>(); // TODO read limit from a config file if (limit == null) { limit = 50;/*www .j a v a 2s . c o m*/ } if (offset == null) { offset = 0; } final int firstIndex = offset * limit; final List<Change> changesFound; if (consolidate) { //only get a list of most recent changes for each study changesFound = changeDAO.findLastChanges(); } else { if (since != null) { final Date date; try { final ISO8601DateUtils dateUtil = new org.nema.medical.mint.utils.JodaDateUtils(); date = dateUtil.parseISO8601Basic(since); } catch (final DateTimeParseException e) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid date: " + since); return; } if (date.getTime() > System.currentTimeMillis()) { LOG.warn(String.format("Changelog requested with invalid future start date %s", DateFormat.getDateTimeInstance().format(date))); res.setStatus(HttpServletResponse.SC_NO_CONTENT); return; } changesFound = changeDAO.findChanges(date, firstIndex, limit); } else { changesFound = changeDAO.findChanges(firstIndex, limit); } } if (changesFound != null) { for (final Change change : changesFound) { changes.add(new org.nema.medical.mint.changelog.Change(change.getStudyUUID(), change.getIndex(), change.getType(), change.getDateTime(), change.getRemoteHost(), change.getRemoteUser(), change.getOperation())); } } res.setBufferSize(fileResponseBufferSize); final ChangeSet changeSet = new ChangeSet(changes); final IBindingFactory bfact = BindingDirectory.getFactory("serverChangelog", ChangeSet.class); final IMarshallingContext mctx = bfact.createMarshallingContext(); mctx.setIndent(2); mctx.startDocument("UTF-8", null, res.getOutputStream()); mctx.getXmlWriter().writePI("xml-stylesheet", xmlStylesheet); mctx.marshalDocument(changeSet); mctx.endDocument(); }
From source file:com.pymegest.applicationserver.api.PuestoController.java
@RequestMapping(value = { "/Puesto/{idsPuestos}" }, method = RequestMethod.DELETE) public void delete(HttpServletRequest request, HttpServletResponse response, @PathVariable("idsPuestos") String idsPuestosStr) { try {/*w w w .ja v a 2 s. c om*/ String[] idsPuestosArr = idsPuestosStr.split(","); for (int i = 0; i < idsPuestosArr.length; i++) { puestoDAO.delete(Integer.parseInt(idsPuestosArr[i])); } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/plain; charset=UTF-8"); try { ex.printStackTrace(response.getWriter()); } catch (IOException ex1) { } } }
From source file:org.wiredwidgets.cow.server.web.ProcessDefinitionsController.java
/** * DELETE method for URL /processDefinitions?key={key} * Deletes all deployments for the specified key. No executions of this process can be running. * @param key the process definition key *//*from w w w.j a va2 s . co m*/ @RequestMapping(method = RequestMethod.DELETE, params = { "key", "!versions" }) public void deleteProcessDef(@RequestParam("key") String key, HttpServletResponse response) { if (processDefsService.deleteProcessDefinitionsByKey(key)) { response.setStatus(HttpServletResponse.SC_NO_CONTENT); // 204 } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); // 404 } }
From source file:de.mpg.escidoc.services.pidcache.web.MainServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("POST request"); if (req.getParameter("url") == null) { logger.warn("URL parameter failed."); resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed."); }/* ww w .j av a 2 s . co m*/ try { if (!authenticate(req, resp)) { logger.warn("Unauthorized request from " + req.getRemoteHost()); return; } PidCacheService cacheService = new PidCacheService(); String xmlOutput = null; if (logger.isDebugEnabled()) { logger.info("request pathInfo <" + req.getPathInfo() + ">"); } if (GwdgPidService.GWDG_PIDSERVICE_CREATE.equals(req.getPathInfo())) { xmlOutput = cacheService.create(req.getParameter("url")); } else if (GwdgPidService.GWDG_PIDSERVICE_EDIT.equals(req.getPathInfo())) { if (req.getParameter("pid") == null) { resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed."); } xmlOutput = cacheService.update(req.getParameter("pid"), req.getParameter("url")); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo()); } resp.encodeRedirectURL(cacheService.getLocation()); resp.addHeader("Location", cacheService.getLocation()); resp.getWriter().append(xmlOutput); } catch (Exception e) { throw new ServletException("Error processing request", e); } }