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.pymegest.applicationserver.api.PuestoController.java

@RequestMapping(value = { "/Puesto/{idsPuestos}" }, method = RequestMethod.GET)
public void read(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("idsPuestos") String idsPuestosStr) {

    try {//from  www  .j  ava 2  s. co m

        String[] idsPuestosArr = idsPuestosStr.split(",");
        List<Puesto> listaPuestos = new ArrayList();
        for (int i = 0; i < idsPuestosArr.length; i++) {
            listaPuestos.add(puestoDAO.read(Integer.parseInt(idsPuestosArr[i])));
        }

        if (listaPuestos.isEmpty() == false) {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json; chaset=UTF-8");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(listaPuestos);
            response.getWriter().println(json);

        } else {

            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.setContentType("application/json; chaset=UTF-8");

            BussinesMessage mensaje = new BussinesMessage();
            mensaje.setMensaje("La lista de puestos de trabajo esta vacia.");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(mensaje);
            response.getWriter().println(json);

        }

    } 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:eu.dasish.annotation.backend.rest.ResourceResource.java

/**
 * //  w  w w .ja va 2s.c  o  m
 * @return the internal database id of the logged in principal if the authentication went well,
 * otherwise sends a corresponding error message.
 * @throws IOException  if sending an error fails.
 */
public Number getPrincipalID() throws IOException {

    dbDispatcher.setResourcesPaths(this.getRelativeServiceURI());
    String remotePrincipal = httpServletRequest.getRemoteUser();
    if (remotePrincipal != null) {
        if (!remotePrincipal.equals(anonym)) {
            try {
                return dbDispatcher.getPrincipalInternalIDFromRemoteID(remotePrincipal);
            } catch (NotInDataBaseException e) {
                loggerServer.info(e.toString());
                loggerServer.info("The record for the user with the id " + remotePrincipal
                        + " will be generated now automatically.");
                try {
                    try {
                        Principal newPrincipal = Helpers.createPrincipalElement(remotePrincipal,
                                remotePrincipal);
                        return dbDispatcher.addPrincipal(newPrincipal, remotePrincipal);
                    } catch (PrincipalExists e2) {
                        loggerServer.info(e2.toString());
                        httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                                e2.toString());
                        return null;
                    }
                } catch (NotInDataBaseException e1) {
                    loggerServer.info(e1.toString());
                    httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
                    return null;
                }
            }
        } else {
            loggerServer.info("Shibboleth fall-back.  Logged in as 'anonymous' with no rights.");
            httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                    " Shibboleth fall-back.  Logged in as 'anonymous' with no rights.");
            return null;
        }
    } else {
        loggerServer.info("Null principal");
        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, " Null principal");
        return null;
    }
}

From source file:com.pymegest.applicationserver.api.FamiliaController.java

@RequestMapping(value = { "/Familia/{idsFamilias}" }, method = RequestMethod.GET)
public void read(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("idsFamilias") String idsFamiliasStr) {

    try {//from ww w.  jav a2 s .c  om

        String[] idsFamiliasArr = idsFamiliasStr.split(",");
        List<Familia> listaFamilias = new ArrayList();
        for (int i = 0; i < idsFamiliasArr.length; i++) {
            listaFamilias.add(familiaDAO.read(Integer.parseInt(idsFamiliasArr[i])));
        }
        if (listaFamilias.isEmpty() == false) {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json; chaset=UTF-8");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(listaFamilias);
            response.getWriter().println(json);

        } else {

            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.setContentType("application/json; chaset=UTF-8");

            BussinesMessage mensaje = new BussinesMessage();
            mensaje.setMensaje("La lista de puestos de trabajo esta vacia.");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(mensaje);
            response.getWriter().println(json);

        }

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

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    final ResourceResolver resolver = request.getResourceResolver();
    final String searchPath = request.getParameter("scriptPath");
    final Script script = scriptFinder.find(searchPath, resolver);
    if (script == null) {
        ServletUtils.writeMessage(response, "error", "Script not found: " + searchPath);
        return;/*from   w ww .j a  v a 2 s .  c o  m*/
    }
    final ModifiableScript modifiableScript = new ModifiableScriptWrapper(resolver, script);
    try {
        final String executionMode = request.getParameter("executionMode");
        if (executionMode != null) {
            modifiableScript.setExecutionMode(ExecutionMode.valueOf(executionMode.toUpperCase()));
        }

        final String executionEnabled = request.getParameter("executionEnabled");
        if (executionEnabled != null) {
            modifiableScript.setExecutionEnabled(BooleanUtils.toBoolean(executionEnabled));
        }

        ServletUtils.writeMessage(response, "success", "Script configuration updated");
    } catch (PersistenceException e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        ServletUtils.writeMessage(response, "error", "Cannot update script configuration: " + e.getMessage());
    }
}

From source file:com.pymegest.applicationserver.api.ProductoController.java

@RequestMapping(value = { "/Producto/{idsProductos}" }, method = RequestMethod.GET)
public void read(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("idsProductos") String idsProductosStr) {

    try {// w ww .  ja v a  2s .  c  om

        String[] idsProductosArr = idsProductosStr.split(",");
        List<Producto> listaProductos = new ArrayList();
        for (int i = 0; i < idsProductosArr.length; i++) {
            listaProductos.add(productoDAO.read(Integer.parseInt(idsProductosArr[i])));
        }

        if (listaProductos.isEmpty() == false) {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json; chaset=UTF-8");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(listaProductos);
            response.getWriter().println(json);

        } else {

            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.setContentType("application/json; chaset=UTF-8");

            BussinesMessage mensaje = new BussinesMessage();
            mensaje.setMensaje("La lista de productos esta vacia.");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(mensaje);
            response.getWriter().println(json);

        }

    } 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:com.pymegest.applicationserver.api.EmpleadoController.java

@RequestMapping(value = { "/Empleado/{idsEmpleados}" }, method = RequestMethod.GET)
public void read(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("idsEmpleados") String idsEmpleadosStr) {

    try {/*from   ww  w. ja va  2  s. com*/

        String[] idsEmpleadosArr = idsEmpleadosStr.split(",");
        List<Empleado> listaEmpleados = new ArrayList();
        for (int i = 0; i < idsEmpleadosArr.length; i++) {
            listaEmpleados.add(empleadoDAO.read(Integer.parseInt(idsEmpleadosArr[i])));
        }

        if (listaEmpleados.isEmpty() == false) {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json; chaset=UTF-8");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(listaEmpleados);
            response.getWriter().println(json);

        } else {

            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.setContentType("application/json; chaset=UTF-8");

            BussinesMessage mensaje = new BussinesMessage();
            mensaje.setMensaje("La lista de empleados esta vacia.");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(mensaje);
            response.getWriter().println(json);

        }

    } 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:com.pymegest.applicationserver.api.UsuarioController.java

@RequestMapping(value = { "/Usuario/{idsUsuarios}" }, method = RequestMethod.GET)
public void read(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("idsUsuarios") String idsUsuariosStr) {

    try {//w  w w.  ja v  a 2 s  .c  o m

        String[] idsUsuariosArr = idsUsuariosStr.split(",");
        List<Usuario> listaUsuarios = new ArrayList();
        for (int i = 0; i < idsUsuariosArr.length; i++) {
            listaUsuarios.add(usuarioDAO.read(Integer.parseInt(idsUsuariosArr[i])));
        }

        if (listaUsuarios.isEmpty() == false) {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json; chaset=UTF-8");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(listaUsuarios);
            response.getWriter().println(json);

        }

        else {

            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.setContentType("application/json; chaset=UTF-8");

            BussinesMessage mensaje = new BussinesMessage();
            mensaje.setMensaje("La lista de usuarios esta vacia.");

            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writeValueAsString(mensaje);
            response.getWriter().println(json);

        }

    } 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.geowebcache.rest.RESTDispatcher.java

protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp)
        throws Exception {

    try {/*from   w  w w. j a  v a2 s.c  o m*/
        myConverter.service(req, resp);
    } catch (Exception e) {
        RestletException re = null;
        if (e instanceof RestletException) {
            re = (RestletException) e;
        }
        if (re == null && e.getCause() instanceof RestletException) {
            re = (RestletException) e.getCause();
        }

        if (re != null) {
            resp.setStatus(re.getStatus().getCode());
            // This does not actually write anything?
            //re.getRepresentation().write(resp.getOutputStream());

            String reStr = re.getRepresentation().getText();
            resp.getOutputStream().write(reStr.getBytes());

            resp.getOutputStream().flush();
        } else {
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            new StringRepresentation(e.getMessage()).write(resp.getOutputStream());
            resp.getOutputStream().flush();
        }
    }

    return null;
}

From source file:com.assetmanager.controller.task.MailTask.java

/**
 * Sends the activation e-mail.// ww  w  .  java  2  s .  c o m
 *
 * @param username the username
 * @param locale the locale
 * @param response the servlet response
 */
@RequestMapping(value = "/activate", method = RequestMethod.POST)
public final void sendActivationMail(@RequestParam final String username, @RequestParam final String locale,
        final HttpServletResponse response) {
    final String logMessage = String.format("Activation e-mail sent for user: %s.", username);

    try {
        if (!userDetailsService.isActivationEmailSent(username)) {
            mailService.sendActivationEmail(userDetailsService.getUser(username), locale);
            userDetailsService.activationEmailSent(username);
            LOGGER.info(logMessage);
        }
    } catch (MessagingException e) {
        LOGGER.warn("Messaging exception in mail task.", e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.openxdata.server.servlet.ImportServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {// w  w  w  .  j a  va 2 s. c  om
        String importType = request.getParameter("type");
        String filecontents = null;

        CommonsMultipartResolver multipartResover = new CommonsMultipartResolver(/*this.getServletContext()*/);
        if (multipartResover.isMultipart(request)) {
            MultipartHttpServletRequest multipartRequest = multipartResover.resolveMultipart(request);
            MultipartFile uploadedFile = multipartRequest.getFile("filecontents");
            if (uploadedFile != null && !uploadedFile.isEmpty()) {
                filecontents = IOUtils.toString(uploadedFile.getInputStream());
            }
        }

        if (filecontents != null) {
            log.info("Starting import of type: " + importType);

            if (importType.equals("user")) {
                String errors = userService.importUsers(filecontents);
                if (errors != null) {
                    writeErrorsToResponse(errors, response);
                }
            } else {
                log.warn("Unknown import type: " + importType);
            }
        }
    } catch (Exception ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        response.getOutputStream().print(ex.getMessage());
    }
}