List of usage examples for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR
int SC_INTERNAL_SERVER_ERROR
To view the source code for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.
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 .j a v a 2 s.c o m 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:controller.MunicipiosRestController.java
/** * * @param id/*ww w .jav a2s. c om*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { MunicipiosDAO tabla = new MunicipiosDAO(); Gson JSON; Municipios elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:com.kdab.daytona.Logger.java
@Override public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (m_error) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); PrintWriter out = response.getWriter(); out.println("Daytona not operational. See server log for details."); out.flush();/*from www . j a va 2s.c o m*/ out.close(); return; } String format = request.getParameter("format"); if (format == null) format = "xml"; if (!m_queuesByFormat.containsKey(format)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter out = response.getWriter(); out.println(String.format("Unknown format \'%s\'.", format)); out.flush(); out.close(); return; } byte[] ba = IOUtils.toByteArray(request.getInputStream()); try { m_queuesByFormat.get(format).put(ba); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } PrintWriter out = response.getWriter(); out.println("Message received."); out.flush(); out.close(); }
From source file:controller.IndicadoresRestController.java
/** * * @param id/*from w w w . j a v a 2 s. c o m*/ * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) { IndicadoresDAO tabla = new IndicadoresDAO(); Gson JSON; Indicadores elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }
From source file:com.eureka.v1_0.account.information.api.AccountInformationController.java
@ResponseBody @RequestMapping(method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE, value = "/resettoken") public CreateResetPasswordTokenResponse createResetPasswordToken( @RequestBody CreateResetPasswordTokenRequest createResetPasswordTokenRequest, HttpServletRequest request, HttpServletResponse response) { if (createResetPasswordTokenRequest != null) { try {//from ww w. j a v a2s . c o m witLoggerService.debug(JaxbHandler.toXml(createResetPasswordTokenRequest)); CreateResetPasswordTokenResponse createResetPasswordTokenResponse = this.accountInformationApiService .createResetPasswordToken(createResetPasswordTokenRequest); if (createResetPasswordTokenResponse != null) { witLoggerService.debug(JaxbHandler.toXml(createResetPasswordTokenResponse)); response.setStatus(HttpServletResponse.SC_OK); return createResetPasswordTokenResponse; } else { response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); } } catch (Exception ex) { witLoggerService.warn(ex); ex.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; }
From source file:com.fpmislata.banco.presentation.controladores.SucursalBancariaController.java
@RequestMapping(value = { "/sucursalbancaria" }, method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public void insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody String jsonEntrada) { try {// w w w . j a v a 2s . c o m SucursalBancaria sucursalBancaria = (SucursalBancaria) jsonTransformer.fromJsonToObject(jsonEntrada, SucursalBancaria.class); sucursalBancariaService.insert(sucursalBancaria); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonTransformer.ObjectToJson(sucursalBancaria)); } catch (BusinessException ex) { List<BusinessMessage> bussinessMessage = ex.getBusinessMessages(); String jsonSalida = jsonTransformer.ObjectToJson(bussinessMessage); //System.out.println(jsonSalida); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); try { httpServletResponse.getWriter().println(jsonSalida); } catch (IOException ex1) { Logger.getLogger(SucursalBancariaController.class.getName()).log(Level.SEVERE, "Error devolviendo Lista de Mensajes", ex1); } } catch (Exception ex1) { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { ex1.printStackTrace(httpServletResponse.getWriter()); } catch (IOException ex2) { Logger.getLogger(SucursalBancariaController.class.getName()).log(Level.SEVERE, "Error devolviendo la traza", ex2); } } }
From source file:com.rsginer.spring.controllers.RestaurantesController.java
@RequestMapping(value = { "/random-restaurante" }, method = RequestMethod.GET, produces = "application/json") public void getRestauranteRandom(HttpServletRequest httpResquest, HttpServletResponse httpServletResponse) { try {/* w ww . ja v a 2 s . co m*/ Restaurante restaurante = restaurantesDAO.getRandom(); String jsonSalida = jsonTransformer.toJson(restaurante); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setContentType("application/json; charset=UTF-8"); httpServletResponse.getWriter().println(jsonSalida); } catch (BussinessException ex) { List<BussinessMessage> bussinessMessages = ex.getBussinessMessages(); String jsonSalida = jsonTransformer.toJson(bussinessMessages); httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); httpServletResponse.setContentType("application/json; charset=UTF-8"); try { httpServletResponse.getWriter().println(jsonSalida); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } catch (Exception ex) { httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); httpServletResponse.setContentType("text/plain; charset=UTF-8"); try { ex.printStackTrace(httpServletResponse.getWriter()); } catch (IOException ex1) { Logger.getLogger(RestaurantesController.class.getName()).log(Level.SEVERE, null, ex1); } } }
From source file:contestWebsite.Registration.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "html/pages, html/snippets"); ve.init();/*from w w w . j ava2 s . c om*/ VelocityContext context = new VelocityContext(); Pair<Entity, UserCookie> infoAndCookie = init(context, req); boolean loggedIn = (boolean) context.get("loggedIn"); if (loggedIn && !infoAndCookie.y.isAdmin()) { context.put("registrationError", "You are already registered."); } SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+6")); String endDateStr = dateFormat.format(new Date()); String startDateStr = dateFormat.format(new Date()); Entity contestInfo = infoAndCookie.x; if (contestInfo != null) { endDateStr = (String) contestInfo.getProperty("endDate"); startDateStr = (String) contestInfo.getProperty("startDate"); Date endDate = new Date(); Date startDate = new Date(); try { endDate = dateFormat.parse(endDateStr); startDate = dateFormat.parse(startDateStr); } catch (ParseException e) { e.printStackTrace(); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Incorrect date format"); } if (loggedIn && infoAndCookie.y.isAdmin()) { context.put("registrationError", ""); } else if (new Date().after(endDate) || new Date().before(startDate)) { context.put("registrationError", "Registration is closed, please try again next year."); } else { context.put("registrationError", ""); } context.put("price", contestInfo.getProperty("price")); context.put("classificationQuestion", contestInfo.getProperty("classificationQuestion")); context.put("publicKey", contestInfo.getProperty("publicKey")); } else { context.put("registrationError", "Registration is closed, please try again next year."); context.put("price", 5); } HttpSession sess = req.getSession(true); sess.setAttribute("nocaptcha", loggedIn && infoAndCookie.y.isAdmin()); context.put("nocaptcha", loggedIn && infoAndCookie.y.isAdmin()); String userError = req.getParameter("userError"); String passwordError = req.getParameter("passwordError"); String captchaError = req.getParameter("captchaError"); if (sess != null && (userError + passwordError + captchaError).contains("1")) { context.put("coach".equals(sess.getAttribute("registrationType")) ? "coach" : "student", true); context.put("account", "yes".equals(sess.getAttribute("account"))); String[] propNames = { "schoolName", "name", "email", "updated", "classification", "studentData", "schoolLevel" }; for (String propName : propNames) { context.put(propName, sess.getAttribute(propName)); } } else { context.put("account", true); context.put("schoolName", ""); context.put("name", ""); context.put("email", ""); context.put("studentData", "[]"); } if ("1".equals(req.getParameter("updated"))) { context.put("updated", true); if (sess != null) { Map<String, Object> props = (Map<String, Object>) sess.getAttribute("props"); if (props != null) { ArrayList<String> regData = new ArrayList<String>(); for (Entry<String, Object> prop : props.entrySet()) { String key = prop.getKey(); if (!key.equals("account") && PropNames.names.get(key) != null) { regData.add( "<dt>" + PropNames.names.get(key) + "</dt>\n<dd>" + prop.getValue() + "</dd>"); } } Collections.sort(regData); context.put("regData", regData); context.put("studentData", sess.getAttribute("studentData")); sess.invalidate(); } } } context.put("userError", userError); context.put("passwordError", passwordError); context.put("captchaError", captchaError); if (userError != null || passwordError != null || captchaError != null) { context.put("error", true); } context.put("Level", Level.class); close(context, ve.getTemplate("registration.html"), resp); }
From source file:net.triptech.buildulator.web.LibraryController.java
/** * Create a new material./*from w ww . j a va 2s.c om*/ * * @param name the name * @param unitOfMeasure the unit of measure * @param lifeYears the life years * @param carbonPerUnit the carbon per unit * @param energyPerUnit the energy per unit * @param wastagePercent the wastage percent * @param request the request * @param response the response * @return the string */ @RequestMapping(value = "/materials", method = RequestMethod.POST) @PreAuthorize("hasAnyRole('ROLE_EDITOR','ROLE_ADMIN')") public @ResponseBody String newMaterial(@RequestParam(value = "name", required = true) final String name, @RequestParam(value = "materialType", required = true) final String typeKey, @RequestParam(value = "unitOfMeasure", required = true) final String unitOfMeasure, @RequestParam(value = "lifeYears") final Integer lifeYearsVal, @RequestParam(value = "carbonPerUnit") final Double carbonPerUnitVal, @RequestParam(value = "energyPerUnit") final Double energyPerUnitVal, @RequestParam(value = "wastagePercent") final Double wastagePercentVal, final HttpServletRequest request, final HttpServletResponse response) { String returnMessage = ""; int lifeYears = 0; double carbonPerUnit = 0, energyPerUnit = 0, wastagePercent = 0; if (lifeYearsVal != null) { lifeYears = lifeYearsVal; } if (carbonPerUnitVal != null) { carbonPerUnit = carbonPerUnitVal; } if (energyPerUnitVal != null) { energyPerUnit = energyPerUnitVal; } if (wastagePercentVal != null) { wastagePercent = wastagePercentVal; } MaterialType materialType = MaterialDetail.getMaterialType(typeKey, getContext()); MaterialDetail material = new MaterialDetail(); material.setName(name); material.setMaterialType(materialType); material.setUnitOfMeasure(unitOfMeasure); material.setLifeYears(lifeYears); material.setCarbonPerUnit(carbonPerUnit); material.setEnergyPerUnit(energyPerUnit); material.setWastagePercent(wastagePercent); try { material.persist(); returnMessage = String.valueOf(material.getId()); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); returnMessage = this.getMessage("materials_library_add_error"); } return returnMessage; }
From source file:controller.TemasNivel2RestController.java
/** * * @param id//from ww w .j a va 2 s . c o m * @param request * @param response * @return JSON */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String getByIdJSON(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) { TemasNivel2DAO tabla = new TemasNivel2DAO(); Gson JSON; TemasNivel2 elemento; try { elemento = tabla.selectById(id); if (elemento == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); Error e = new Error(); e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id); JSON = new Gson(); return JSON.toJson(e); } } catch (HibernateException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Error e = new Error(); e.setTypeAndDescription("errorServerError", ex.getMessage()); JSON = new Gson(); return JSON.toJson(e); } JSON = new Gson(); response.setStatus(HttpServletResponse.SC_OK); return JSON.toJson(elemento); }