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:org.tec.webapp.web.view.JSONView.java

/**
 * {@inheritDoc}//from  www .ja v a 2 s . c  o m
 */
@Override()
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {
        JSONSerializable json = (JSONSerializable) model.get(JSONModelAndView.ERROR_KEY);

        if (json != null) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
        } else {
            json = (JSONSerializable) model.get(JSONModelAndView.JSON_KEY);

            if (json != null) {
                if (mLogger.isDebugEnabled()) {
                    mLogger.debug("JSON Response\n" + json.toJSON());
                }
                response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE);
                PrintWriter pw = response.getWriter();
                pw.write(json.toJSON());
                pw.flush();
            } else // null json for controllers that usurp the response or didn't intend to
            {
                mLogger.warn("null json object");
            }
        }
    } catch (Exception e) {
        mLogger.error("error", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
    }
}

From source file:com.kixeye.chassis.transport.http.HttpExceptionHandler.java

@ExceptionHandler(Exception.class)
@ResponseBody/*from   w  ww. j a va  2 s . c  o m*/
public ServiceError defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception ex)
        throws Exception {
    ServiceError error = ExceptionServiceErrorMapper.mapException(ex);

    switch (error.code) {
    case ExceptionServiceErrorMapper.UNKNOWN_ERROR_CODE:
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        logger.error("Unexpected error", ex);
        break;
    case ExceptionServiceErrorMapper.VALIDATION_ERROR_CODE:
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

        if (logger.isDebugEnabled()) {
            logger.debug("Validation exception", ex);
        }
        break;
    case ExceptionServiceErrorMapper.SECURITY_ERROR_CODE:
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        if (logger.isDebugEnabled()) {
            logger.debug("Security exception", ex);
        }
        break;
    default:
        if (ex instanceof HttpServiceException) {
            HttpServiceException httpEx = (HttpServiceException) ex;

            response.setStatus(httpEx.httpResponseCode);
        }

        logger.warn("Service exception", ex);
        break;
    }

    return error;
}

From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
    try {/*from w  ww.j  av  a 2  s .  com*/
        String captchaId = request.getSession().getId();
        createCheckCodeImage(captchaId, request.getLocale(), jpegOutputStream);
    } catch (IllegalArgumentException e) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    } catch (CaptchaServiceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }

    initResponseHeader(response);
    responseImage(response, jpegOutputStream.toByteArray());
    jpegOutputStream.close();
}

From source file:com.tasktop.c2c.server.web.proxy.AjpProxy.java

@Override
protected void proxy(String targetUrl, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    Matcher matcher = targetUrlPattern.matcher(targetUrl);
    if (!matcher.matches()) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        throw new IllegalStateException();
    }/*  w  w  w. jav  a2  s .  c o  m*/
    String uri = matcher.group(3);
    int query = uri.indexOf('?');
    if (query != -1) {
        uri = uri.substring(0, query);
    }
    final String requestUri = uri;
    request = new HttpServletRequestWrapper(request) {
        public String getRequestURI() {
            return requestUri;
        }
    };

    AjpProtocol ajpProtocol = new AjpProtocol();
    ajpProtocol.setSocketPool(socketPool);
    ajpProtocol.setProxyHost(matcher.group(1));
    String portPart = matcher.group(2);
    ajpProtocol.setProxyPort(portPart == null ? 8009 : Integer.parseInt(portPart));
    ajpProtocol.setHeaderFilter(headerFilter);

    ajpProtocol.forward(request, response);
}

From source file:com.ar.dev.tierra.hasar.api.config.security.CustomLogoutSuccessHandler.java

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

    String token = request.getHeader(HEADER_AUTHORIZATION);
    if (token != null && token.startsWith(BEARER_AUTHENTICATION)) {
        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token.split(" ")[1]);
        if (oAuth2AccessToken != null) {
            tokenStore.removeAccessToken(oAuth2AccessToken);
            response.setStatus(HttpServletResponse.SC_OK);
        } else {//from   www . ja  v a2s  . c o m
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:es.logongas.encuestas.presentacion.controller.BorrarDatosController.java

@RequestMapping(value = { "/Encuesta" }, method = RequestMethod.DELETE)
public void delete(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse) {
    try {//from ww w . j  av a2  s .  c  o  m
        EncuestaDAO encuestaDAO = (EncuestaDAO) daoFactory.getDAO(Encuesta.class);

        encuestaDAO.deleteAllData();

        noCache(httpServletResponse);
        httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } catch (Exception ex) {
        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        httpServletResponse.setContentType("text/plain");
        try {
            ex.printStackTrace(httpServletResponse.getWriter());
        } catch (Exception ex2) {
            log.error("Fall al imprimir la traza", ex2);
        }
    }
}

From source file:com.music.web.util.ExceptionResolver.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {//  w w w .  java 2  s  . c  om

    // the stacktrace will be printed by spring's DispatcherServlet
    // we are only logging the request url and headeres here
    logger.warn("An exception occurred when invoking the following URL: " + request.getRequestURL()
            + " . Requester IP is " + request.getRemoteAddr() + ", User-Agent: "
            + request.getHeader("User-Agent") + "; Message=" + ex.getMessage() + ": "
            + ex.getStackTrace()[0].getMethodName());

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return null;
}

From source file:org.tec.security.spring.AuthenticationFailure.java

/**
 * {@inheritDoc}/*from ww  w.  j  a va  2  s  .co m*/
 */
@Override()
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    if (mLogger.isDebugEnabled()) {
        mLogger.debug("failed login for " + request.getParameter("j_username"));
    }

    Writer out = response.getWriter();
    try {
        out.write("{success:false}");
    } catch (IOException e) {
        mLogger.error("failed to write to response", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "processing failed");
    } finally {
        out.close();
    }
}

From source file:org.easyj.rest.exceptions.UncaughtExceptionHandler.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {//from w w  w  . j a  va  2 s  . co m
    ModelAndView mav = new ModelAndView();

    String exception = "";
    Exception ex2 = ex;
    while (ex2 != null) {
        exception += "\n" + ex2.getClass().getSimpleName() + " - " + ex2.getMessage();
        ex2 = (Exception) ex2.getCause();
    }

    mav.setViewName(viewName);
    mav.addObject("status", UncaughtExceptionHandler.ERROR_STATUS);
    mav.addObject("exception", exception);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    logger.error("Uncaught Exception Error", ex);

    return mav;
}

From source file:com.linuxbox.enkive.web.search.CancelSearchWebScript.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {

    String searchId = "";
    try {/*from   ww  w .  jav a2  s . c  o m*/
        searchId = WebScriptUtils.cleanGetParameter(req, "searchid");
        MessageSearchService searchService = getMessageSearchService();
        searchService.cancelAsyncSearch(searchId);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("cancelled search with id " + searchId);
    } catch (Exception e) {
        respondError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, res);
        throw new IOException("Could not cancel search with UUID " + searchId);
    }
}