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:eu.trentorise.smartcampus.unidataservice.controller.rest.CanteenController.java

@RequestMapping(method = RequestMethod.GET, value = "/data/getopening")
public @ResponseBody List<CanteenOpening> getMenu(HttpServletRequest request, HttpServletResponse response)
        throws InvocationException {
    try {//from   www. ja  v a2 s  .c  o m
        List<CanteenOpening> result = mongoTemplate.findAll(CanteenOpening.class, "opening");

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

From source file:com.citytechinc.cq.clientlibs.core.servlets.ComponentClientLibraryServlet.java

@Override
public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    Optional<LibraryType> requestedLibraryType = Optional.fromNullable(LibraryType.fromRequest(request));

    if (requestedLibraryType == null) {
        LOG.error("Invalid extension for client library");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//w  w  w.  jav  a 2s . c o m
    }

    Optional<String> brand = lookupBrandForRequest(request);

    try {
        final Resource jcrContent = request.getResource().getChild(JcrConstants.JCR_CONTENT);

        String compiledLibrary = clientLibraryRepository.compileClientLibrary(jcrContent,
                requestedLibraryType.get(), brand);
        response.setContentType(requestedLibraryType.get().contentType);
        response.getWriter().write(compiledLibrary);
    } catch (ClientLibraryCompilationException e) {
        LOG.error("Error encountered requesting page library for " + request.getResource().getPath(), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.eureka.v1_0.account.information.api.AccountInformationController.java

@ResponseBody
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
public CreateAccountResponse createAccount(@RequestBody CreateAccountRequest createAccountRequest,
        HttpServletRequest request, HttpServletResponse response) {
    if (createAccountRequest != null) {
        try {/*from w  w  w . jav a2  s .com*/
            CreateAccountResponse createAccountResponse = this.accountInformationApiService
                    .createAccount(createAccountRequest);
            witLoggerService.debug(JaxbHandler.toXml(createAccountRequest));
            if (createAccountResponse != null) {
                witLoggerService.debug(JaxbHandler.toXml(createAccountResponse));
                response.setStatus(HttpServletResponse.SC_OK);
                return createAccountResponse;
            } else {
                response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
            }
        } catch (Exception ex) {
            witLoggerService.warn(ex);
            ex.printStackTrace();
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return null;
}

From source file:com.epam.wilma.webapp.config.servlet.stub.upload.MultiPartFormUploadServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
    if (!isMultipartContent) {
        out.println("You are not trying to upload");
    } else {/*w  ww.  j  a va  2  s .co m*/
        try {
            List<FileItem> fields = upload.parseRequest(request);
            String msg = filesParser.parseMultiPartFiles(fields);
            LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg));
            out.write(msg);
        } catch (Exception e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            out.write("File uploading failed! cause: " + e.getMessage());
            LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e);
        }
    }
}

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

private boolean generateReport(Integer billId, HttpServletResponse response, Bill bill, JasperReport report)
        throws IOException {
    String name = report.getName();
    if (StringUtils.isEmpty(bill.getReceiptNumber())) {
        report.setName(bill.getReceiptNumber());
    } else {/* w  ww .j  a  va 2s  . c  om*/
        report.setName(String.valueOf(billId));
    }

    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("billId", bill.getId());

    try {
        ReportGenerator.generateHtmlAndWriteToResponse(report, params, response);
    } catch (IOException e) {
        if (StringUtils.isEmpty(bill.getReceiptNumber())) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Error generating report for receipt '" + bill.getReceiptNumber() + "'");
        } else {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Error generating report for bill '" + billId + "'");
        }

        return false;
    } finally {
        // Reset the report name
        report.setName(name);
    }

    return true;
}

From source file:fedora.server.management.UploadServlet.java

/**
 * The servlet entry point. http://host:port/fedora/management/upload
 *//*from  www.  j  a  v a 2s  .  c o m*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Context context = ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri, request);
    try {
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload();

        // Parse the request, looking for "file"
        InputStream in = null;
        FileItemIterator iter = upload.getItemIterator(request);
        while (in == null && iter.hasNext()) {
            FileItemStream item = iter.next();
            LOG.info("Got next item: isFormField=" + item.isFormField() + " fieldName=" + item.getFieldName());
            if (!item.isFormField() && item.getFieldName().equals("file")) {
                in = item.openStream();
            }
        }
        if (in == null) {
            sendResponse(HttpServletResponse.SC_BAD_REQUEST, "No data sent.", response);
        } else {
            sendResponse(HttpServletResponse.SC_CREATED, s_management.putTempStream(context, in), response);
        }
    } catch (AuthzException ae) {
        throw RootException.getServletException(ae, request, "Upload", new String[0]);
    } catch (Exception e) {
        e.printStackTrace();
        sendResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                e.getClass().getName() + ": " + e.getMessage(), response);
    }
}

From source file:com.agiletec.apsadmin.system.dispatcher.Struts2ServletDispatcher.java

@Override
public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
    ActionMapper actionMapper = new ExtendedDefaultActionMapper();
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    ServletContext servletContext = getServletContext();
    String timerKey = "FilterDispatcher_doFilter: ";
    try {/*from   w  w  w .  j a  va  2 s .c  o m*/
        UtilTimerStack.push(timerKey);
        request = prepareDispatcherAndWrapRequest(request, response);
        ActionMapping mapping;
        try {
            mapping = actionMapper.getMapping(request, dispatcher.getConfigurationManager());
        } catch (Exception ex) {
            LOG.error("error getting ActionMapping", ex);
            dispatcher.sendError(request, response, servletContext,
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
            return;
        }

        if (mapping == null) {
            // there is no action in this request, should we look for a static resource?
            String resourcePath = RequestUtils.getServletPath(request);

            if ("".equals(resourcePath) && null != request.getPathInfo()) {
                resourcePath = request.getPathInfo();
            }

            if (serveStatic && resourcePath.startsWith("/struts")) {
                String name = resourcePath.substring("/struts".length());
                findStaticResource(name, request, response);
            }

            return;
        }

        dispatcher.serviceAction(request, response, servletContext, mapping);

    } finally {
        try {
            cleanUp(req);
        } finally {
            UtilTimerStack.pop(timerKey);
        }
    }
}