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:de.knowwe.revisions.manager.action.DownloadRevisionZip.java

@Override
public void execute(UserActionContext context) throws IOException {
    if (context.getParameters().containsKey("date")) {
        String dateParam = context.getParameter("date");
        Date date;//from  ww  w  .  j a  v a 2  s.co  m
        try {
            date = new Date(Long.parseLong(dateParam));

            String filename = "revision-" + DATE_FORMAT.format(date) + ".zip";
            context.setContentType("application/force-download");
            context.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
            OutputStream outs = context.getOutputStream();
            ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(outs));
            zipRev(date, zos, context);
            outs.flush();
            outs.close();
        } catch (Exception e) {
            context.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, String.valueOf(e));
            e.printStackTrace();
        }

    }
}

From source file:info.magnolia.cms.servlets.Spool.java

/**
 * All static resource requests are handled here.
 *
 * @param request  HttpServletRequest//w w  w . ja va  2 s.co  m
 * @param response HttpServletResponse
 * @throws IOException for error in accessing the resource or the servlet output stream
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    File resource = new File(getServletContext().getRealPath(Path.getURI(request)));
    if (!resource.exists() || resource.isDirectory()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    this.setResponseHeaders(resource, response);
    boolean success = this.spool(resource, response);
    if (!success && !response.isCommitted()) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.mypackage.spring.controllers.ContactsSpringController.java

@RequestMapping(value = "/contacts", method = RequestMethod.GET)
public ModelAndView getAllContacts() {
    ModelAndView modelAndView = new ModelAndView();
    try {/*from ww w  .  j av a  2  s. c  om*/
        List<Contact> list = contactsController.retrieveAllContacts();
        modelAndView.addObject("contactsList", list);
        modelAndView.setViewName("/contacts.jsp");
    } catch (DalException ex) {
        logger.error("A database error occured.", ex);
        modelAndView.addObject("errorCode", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        modelAndView.addObject("errorMessage", "There was a an internal database error.");
        modelAndView.setViewName("/errorPage.jsp");
    }
    return modelAndView;
}

From source file:de.highbyte_le.weberknecht.Controller.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (log.isDebugEnabled())
        log.debug("service() - start");

    long start = System.currentTimeMillis();

    DbConnectionHolder conHolder = new DbConnectionHolder(core.getDbConnectionProvider());
    try {//from  w  w w  .  j a v  a  2  s .  c  o  m
        Router router = core.createRouter(conHolder); //choose router depending on config
        RoutingTarget routingTarget = router.routeUri(request);

        core.executeAction(request, response, conHolder, routingTarget);
    } catch (Exception e1) {
        try {
            log.error("service() - exception while error handler instantiation: " + e1.getMessage(), e1); //$NON-NLS-1$
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); //call error page 500
        } catch (IOException e) {
            log.error("service() - IOException: " + e.getMessage(), e); //$NON-NLS-1$
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); //just return 500
        }
    } finally {
        try {
            conHolder.close();
        } catch (SQLException e) {
            log.error("service() - SQLException while closing db connection: " + e.getMessage()); //$NON-NLS-1$
        }
    }

    long finish = System.currentTimeMillis();
    if (log.isInfoEnabled()) {
        log.info("service() - page delivery took " + (finish - start) + " ms");
    }
}

From source file:photogift.server.filter.AuthenticatedFilter.java

private void filter(FilterChain chain, HttpServletRequest request, HttpServletResponse response) {
    try {//www.j a  v a  2 s.c o  m
        chain.doFilter(request, response);
    } catch (IOException e) {
        // Likely a temporary network error
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (ServletException e) {
        // Something went wrong with Jetty serving requests.
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.ar.dev.tierra.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) {
            Calendar cal = Calendar.getInstance();
            Date date = cal.getTime();
            Map<String, Object> map = oAuth2AccessToken.getAdditionalInformation();
            OAuth2Authentication auth = tokenStore.readAuthentication(oAuth2AccessToken);
            User user = (User) auth.getPrincipal();
            Usuarios u = usuariosDAO.findUsuarioByUsername(user.getUsername());
            u.setUltimaConexion(date);//w  w  w .j av  a2 s .co  m
            usuariosDAO.updateUsuario(u);
            tokenStore.removeAccessToken(oAuth2AccessToken);
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:com.webpagebytes.cms.utility.HttpServletToolbox.java

public void writeBodyResponseAsJson(HttpServletResponse response, String data, Map<String, String> errors) {

    try {//from w w  w.j a v a2  s  .  co  m
        org.json.JSONObject jsonResponse = new org.json.JSONObject();
        org.json.JSONObject jsonErrors = new org.json.JSONObject();
        if (errors == null || errors.keySet().size() == 0) {
            jsonResponse.put("status", "OK");
        } else {
            jsonResponse.put("status", "FAIL");
            for (String key : errors.keySet()) {
                jsonErrors.put(key, errors.get(key));
            }
        }
        jsonResponse.put("errors", jsonErrors);
        jsonResponse.put("payload", data);
        String jsonString = jsonResponse.toString();
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        ServletOutputStream writer = response.getOutputStream();
        byte[] utf8bytes = jsonString.getBytes("UTF-8");
        writer.write(utf8bytes);
        response.setContentLength(utf8bytes.length);
        writer.flush();

    } catch (Exception e) {
        try {
            String errorResponse = "{\"status\":\"FAIL\",\"payload\":\"{}\",\"errors\":{\"reason\":\"WB_UNKNOWN_ERROR\"}}";
            ServletOutputStream writer = response.getOutputStream();
            response.setContentType("application/json");
            byte[] utf8bytes = errorResponse.getBytes("UTF-8");
            response.setContentLength(utf8bytes.length);
            writer.write(utf8bytes);
            writer.flush();
        } catch (IOException ioe) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }

}

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

@RequestMapping(method = RequestMethod.GET, value = "/basicprofile/social/{socialId}")
public @ResponseBody BasicProfile getUserBySocialId(HttpServletResponse response,
        @PathVariable("socialId") String socialId) throws IOException {
    try {//from w  w  w. j  ava 2 s  .  co  m
        return profileManager.getBasicProfileBySocialId(socialId);
    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }

}

From source file:se.acrend.christopher.server.web.control.BillingController.java

@RequestMapping(value = "/billing/getMarketLicenseKey")
public void getMarketLicenseKey(final HttpServletResponse response) throws IOException {
    try {// w  w  w  .  j a v a  2  s .  co m
        PrepareBillingInfo result = billingService.getMarketLicenseKey();

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        Gson gson = ParserFactory.createParser();
        gson.toJson(result, response.getWriter());
    } catch (Exception e) {
        log.error("Kunde inte hmta prenumeration.", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:eu.trentorise.smartcampus.unidataservice.controller.rest.CanteenController.java

/**
 * /*from  w  ww .  ja v  a2s .  c o m*/
 * @param request
 * @param response
 * @param from start date in format yyyy-mm-dd
 * @param to end date in format yyyy-mm-dd
 * @return
 * @throws InvocationException
 */
@RequestMapping(method = RequestMethod.GET, value = "/data/getmenu/{from}/{to}")
public @ResponseBody List<Menu> getMenu(HttpServletRequest request, HttpServletResponse response,
        @PathVariable String from, @PathVariable String to) throws InvocationException {
    try {
        Criteria criteria = new Criteria("date").gte(from).lte(to);
        Query query = new Query(criteria);

        List<Menu> result = mongoTemplate.find(query, Menu.class, "menu");

        return result;
    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return null;
}