Example usage for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR

List of usage examples for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.

Prototype

int SC_INTERNAL_SERVER_ERROR

To view the source code for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.

Click Source Link

Document

Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.

Usage

From source file:controller.TemasNivel2RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel2DAO tabla = new TemasNivel2DAO();
    Gson JSON;/*from  www  . j  a  v  a 2s  .c  om*/
    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");
            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:controller.TemasNivel3RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel3DAO tabla = new TemasNivel3DAO();
    Gson JSON;//from w  w w.ja v  a  2 s.  c  o m
    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");
            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:com.ningpai.common.util.CaptchaController.java

@RequestMapping("/captcha")
public void writeCaptcha(HttpServletRequest request, HttpServletResponse response) {
    byte[] captchaChallengeAsJpeg = null;
    // the output stream to render the captcha image as jpeg into
    ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
    try {/*from w  w w  .j a  v a  2s  .c o m*/
        // get the session id that will identify the generated captcha.
        // the same id must be used to validate the response, the session id is a good candidate!
        String captchaId = request.getSession().getId();
        BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, request.getLocale());
        try {
            ImageIO.write(challenge, CAPTCHA_IMAGE_FORMAT, jpegOutputStream);
        } catch (IOException e) {
        }
    } catch (IllegalArgumentException e) {
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (IOException e1) {
        }
        return;
    } catch (CaptchaServiceException e) {
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (IOException e1) {
        }
        return;
    }

    captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

    // flush it in the response
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/" + CAPTCHA_IMAGE_FORMAT);

    ServletOutputStream responseOutputStream;
    try {
        responseOutputStream = response.getOutputStream();
        responseOutputStream.write(captchaChallengeAsJpeg);
        responseOutputStream.flush();
        responseOutputStream.close();
    } catch (IOException e) {
    }

}

From source file:de.otto.mongodb.profiler.web.AbstractController.java

@ExceptionHandler(RuntimeException.class)
public void onRuntimeException(RuntimeException e, HttpServletResponse response) throws IOException {

    logger.error(e, "Unhandled exception caught.");

    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.BasicProfileController.java

@RequestMapping(method = RequestMethod.GET, value = "/basicprofile/all/{userId}")
public @ResponseBody BasicProfile getUser(HttpServletResponse response, @PathVariable("userId") String userId)
        throws IOException {
    try {/*from   w w  w . j  ava 2 s .  c  om*/
        return profileManager.getBasicProfileById(userId);
    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }

}

From source file:org.openmrs.module.openhmis.cashier.web.controller.ReceiptController.java

@RequestMapping(method = RequestMethod.GET)
public void get(@RequestParam(value = "billId", required = false) Integer billId, HttpServletResponse response)
        throws IOException {
    if (billId == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;// ww  w.ja v a 2  s .c  o m
    }

    IBillService service = Context.getService(IBillService.class);
    Bill bill = service.getById(billId);
    if (!validateBill(billId, bill, response)) {
        return;
    }

    JasperReport report = ModuleSettings.getReceiptReport();
    if (report == null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Configuration error: need to specify global " + "option for default report ID.");
        return;
    }

    if (generateReport(billId, response, bill, report)) {
        bill.setReceiptPrinted(true);
        service.save(bill);
    }
}

From source file:com.controlj.green.modstat.servlets.ModstatZipServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/zip");
    resp.setHeader("Content-disposition", "attachment;filename=modstat.zip");
    try {/* ww  w. j  a  v  a 2 s.co  m*/
        RunnableProgress work = (RunnableProgress) LongRunning.getWork(req);
        if (work == null || work.isAlive() || work.hasError()) {
            throw new Exception("Modstats not gathered yet");
        }

        InputStream in = work.getCache();
        IOUtils.copy(in, resp.getOutputStream());
        resp.getOutputStream().flush();
    } catch (Exception e) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        System.err.println("Add-On Error in " + AddOnInfo.getAddOnInfo().getName());
        e.printStackTrace(new PrintWriter(System.err));
    }
}

From source file:cz.muni.fi.pa165.deliverysystemweb.CourierActionBean.java

@DefaultHandler
public Resolution list() {
    try {/*from www.  j a  va2 s  .  c o  m*/
        courierDTOs = courierService.getAllCouriers(false);
    } catch (DataAccessException ex) {
        return new ErrorResolution(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return new ForwardResolution("/courier/list.jsp");
}

From source file:com.jaspersoft.jasperserver.war.control.interceptor.RenderViewExceptionInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    if (ex != null) {
        String message;/*from  w ww  .  ja  va2s.  c om*/

        Locale locale = LocaleContextHolder.getLocale();
        if (ex instanceof JSException) {
            JSException jsException = (JSException) ex;
            message = messageSource.getMessage(ex.getMessage(), jsException.getArgs(), locale);
        } else {
            message = messageSource.getMessage("error.500.message", null, locale);
        }

        log.error(message, ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
    }
}

From source file:de.hska.ld.core.config.security.AjaxAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    String userJson = null;//ww w .  j  a  v  a2s  . co m
    try {
        userJson = mapper.writeValueAsString(authentication.getPrincipal());
    } catch (JsonProcessingException e) {
        LOGGER.error(e.getMessage());
    }

    if (userJson != null) {
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(userJson);
        response.setStatus(HttpServletResponse.SC_OK);
    } else {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}