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:com.cognifide.cq.cqsm.core.servlets.ScriptValidationServlet.java

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    final String content = request.getParameter("content");
    if (StringUtils.isEmpty(content)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        ServletUtils.writeMessage(response, "error", "Script content is required");
        return;//from ww w  .j  av  a  2 s.c  o m
    }

    try {
        final Progress progress = scriptManager.evaluate(content, Mode.VALIDATION,
                request.getResourceResolver());
        if (progress.isSuccess()) {
            ServletUtils.writeMessage(response, "success", "Script passes validation");
        } else {
            final String message = progress.getLastError().getLastMessageText();
            final Map<String, Object> context = new HashMap<>();

            if (message != null) {
                context.put("error", message);
            }

            ServletUtils.writeMessage(response, "error", "Script does not pass validation", context);
        }
    } catch (RepositoryException e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        ServletUtils.writeMessage(response, "error", String
                .format("Script' cannot be validated because of " + "repository error: %s", e.getMessage()));
    }
}

From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //create a fake site
    final Site fakeSite = new Site(new FakeContainer());

    //make sure that the requested user exists
    final String userName = getUserNameFromPath(req, resp);
    if (userName == null) {
        return;/*from w  ww  .  jav  a2s.  c o m*/
    }

    final List<Module> modules;
    //catch any possible errors
    try {
        modules = moduleFactory.createModules(userName, fakeSite);
    } catch (Exception ex) {
        error("Error in determining modules for user " + userName, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                resp);
        log.error(ex.getMessage(), ex);
        return;
    }

    try {
        //respond with the modules that the requested user has access to
        ok(serializeModules(modules), resp);
    } catch (JSONException e) {
        //if anything goes wrong just 'throw'
        error("Error in creating content", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, resp);
        log.error(e.getMessage(), e);
    }
}

From source file:de.afbb.bibo.servlet.server.servlet.MainServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) {
    try {//  w  w w . j  a v  a 2 s.  com
        processRequest(request, response);
    } catch (final NumberFormatException | IOException e) {
        log.debug(e.getMessage());
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.tec.webapp.web.ErrorServlet.java

/**
 * process the error//from   w ww  . ja  va2 s .  c om
 * @param request the request instance
 * @param response the response instance
 * @throws IOException if processing fails
 */
protected void processError(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Throwable throwable = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
    Integer statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
    String requestUri = (String) request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);

    LOGGER.error("failed to process " + requestUri + " error code: " + statusCode);

    WebError we;
    if (throwable != null) {
        LOGGER.error("error", throwable);
        we = new WebError(throwable.getMessage(), ErrorCodes.UNRESOLVEABLE_ERROR);
    } else {
        we = new WebError("error", ErrorCodes.UNRESOLVEABLE_ERROR);
    }

    PrintWriter pw = null;
    try {
        response.setStatus(statusCode != null ? statusCode : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE);
        pw = response.getWriter();
        pw.write(we.toJSON());
        pw.flush();
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}

From source file:controller.MunicipiosRestController.java

/**
 *
 * @param request/*  ww  w.  j a va  2 s .  c om*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    MunicipiosDAO tabla = new MunicipiosDAO();
    XStream XML;
    List<Municipios> lista;

    try {
        lista = tabla.selectAll();

        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<Municipios> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("municipio", Municipios.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}

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

public Resolution view() {
    String id = getContext().getRequest().getParameter("id");

    Long l_id;/*from   w w w  .  j  a  v a  2s.  co m*/
    try {
        l_id = Long.valueOf(id);
    } catch (NumberFormatException ex) {
        return new ErrorResolution(HttpServletResponse.SC_BAD_REQUEST);
    }

    try {
        courierDTO = courierService.findCourier(l_id);
    } catch (DataAccessException ex) {
        return new ErrorResolution(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    if (courierDTO == null) {
        return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND);
    }
    return new ForwardResolution("/courier/view.jsp");
}

From source file:controller.IndicadoresRestController.java

/**
 *
 * @param request/*from w w w .java 2  s. c o m*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    IndicadoresDAO tabla = new IndicadoresDAO();
    XStream XML;
    List<Indicadores> lista;

    try {
        lista = tabla.selectAll();

        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<Indicadores> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("indicador", Indicadores.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}

From source file:com.beetle.framework.web.controller.UploadController.java

private void serviceInject(IUpload upload) throws ControllerException {
    // ?/*from   w  ww  . j av a 2s  . c om*/
    if (!this.injectFlag) {
        this.injectFlag = true;// ??
        Field[] fields = upload.getClass().getDeclaredFields();
        if (fields != null && fields.length > 0) {
            for (Field f : fields) {
                if (f.isAnnotationPresent(ServiceField.class)) {
                    try {
                        ObjectUtil.setFieldValue(upload, f.getName(), this.serviceLookup(f.getType()));
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw new ControllerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                                AppLogger.getErrStackTraceInfo(e));
                    }
                } else if (f.isAnnotationPresent(DaoField.class)) {
                    throw new ControllerException("The [" + upload.getClass().getName()
                            + "] cannot use daoField annotation, do not conform to the programming paradigm!");
                }
            }
        }
    }
    //
}

From source file:controller.TemasNivel1RestController.java

/**
 *
 * @param request/* w ww  .  j  a  va 2  s .  c o  m*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel1DAO tabla = new TemasNivel1DAO();
    XStream XML;
    List<TemasNivel1> lista;

    try {
        lista = tabla.selectAll();

        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<TemasNivel1> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("Temas-Nivel-1", TemasNivel1.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}

From source file:controller.TemasNivel2RestController.java

/**
 *
 * @param request/*  w  w w  . j a  v  a 2s . c  o m*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel2DAO tabla = new TemasNivel2DAO();
    XStream XML;
    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");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<TemasNivel2> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("tema-nivel-2", TemasNivel2.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}