Example usage for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE

List of usage examples for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE.

Prototype

int SC_SERVICE_UNAVAILABLE

To view the source code for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE.

Click Source Link

Document

Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the request.

Usage

From source file:org.opencastproject.ingest.endpoint.IngestRestService.java

@POST
@Path("addZippedMediaPackage/{workflowDefinitionId}")
@Produces(MediaType.TEXT_XML)/*  w  w  w . ja  v  a2s. com*/
@RestQuery(name = "addZippedMediaPackage", description = "Create media package from a compressed file containing a manifest.xml document and all media tracks, metadata catalogs and attachments", pathParameters = {
        @RestParameter(description = "Workflow definition id", isRequired = true, name = WORKFLOW_DEFINITION_ID_PARAM, type = RestParameter.Type.STRING) }, restParameters = {
                @RestParameter(description = "The workflow instance ID to associate with this zipped mediapackage", isRequired = false, name = WORKFLOW_INSTANCE_ID_PARAM, type = RestParameter.Type.STRING) }, bodyParameter = @RestParameter(description = "The compressed (application/zip) media package file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), reponses = {
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_OK),
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_BAD_REQUEST),
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE) }, returnDescription = "")
public Response addZippedMediaPackage(@Context HttpServletRequest request,
        @PathParam("workflowDefinitionId") String wdID, @QueryParam("id") String wiID) {
    logger.debug("addZippedMediaPackage(HttpRequest)");
    if (!isIngestLimitEnabled() || getIngestLimit() > 0) {
        return ingestZippedMediaPackage(request, wdID, wiID);
    } else {
        logger.warn(
                "Delaying ingest because we have exceeded the maximum number of ingests this server is setup to do concurrently.");
        return Response.status(Status.SERVICE_UNAVAILABLE).build();
    }
}

From source file:org.opencastproject.ingest.endpoint.IngestRestService.java

@POST
@Path("addZippedMediaPackage")
@Produces(MediaType.TEXT_XML)//from w ww. j av a 2s  . com
@RestQuery(name = "addZippedMediaPackage", description = "Create media package from a compressed file containing a manifest.xml document and all media tracks, metadata catalogs and attachments", restParameters = {
        @RestParameter(description = "The workflow definition ID to run on this mediapackage. "
                + "This parameter has to be set in the request prior to the zipped mediapackage "
                + "(This parameter is deprecated. Please use /addZippedMediaPackage/{workflowDefinitionId} instead)", isRequired = false, name = WORKFLOW_DEFINITION_ID_PARAM, type = RestParameter.Type.STRING),
        @RestParameter(description = "The workflow instance ID to associate with this zipped mediapackage. "
                + "This parameter has to be set in the request prior to the zipped mediapackage "
                + "(This parameter is deprecated. Please use /addZippedMediaPackage/{workflowDefinitionId} with a path parameter instead)", isRequired = false, name = WORKFLOW_INSTANCE_ID_PARAM, type = RestParameter.Type.STRING) }, bodyParameter = @RestParameter(description = "The compressed (application/zip) media package file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), reponses = {
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_OK),
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_BAD_REQUEST),
                        @RestResponse(description = "", responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE) }, returnDescription = "")
public Response addZippedMediaPackage(@Context HttpServletRequest request) {
    logger.debug("addZippedMediaPackage(HttpRequest)");
    if (!isIngestLimitEnabled() || getIngestLimit() > 0) {
        return ingestZippedMediaPackage(request, null, null);
    } else {
        logger.warn(
                "Delaying ingest because we have exceeded the maximum number of ingests this server is setup to do concurrently.");
        return Response.status(Status.SERVICE_UNAVAILABLE).build();
    }
}

From source file:org.energy_home.jemma.internal.shapi.M2MLocalService.java

protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {
    String requestUri = servletRequest.getRequestURI();
    initResponse(servletResponse);/*www.ja v a2  s.  c om*/
    requestUri = replaceFilters(requestUri, false);
    if (requestUri.startsWith(M2MConstants.URL_HAG_SCL_BASE)) {
        try {
            if (requestUri.startsWith(subscriptionItemsAddressedId)) {
                if (requestUri.endsWith(M2MContainerAddress.ALL_ID_FILTER))
                    servletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                else {
                    String subscriptionId = requestUri.substring(subscriptionItemsAddressedId.length() + 1,
                            requestUri.length());
                    SubscriptionInfo subscriptionInfo = null;
                    synchronized (subscriptionInfos) {
                        for (Iterator iterator = subscriptionInfos.iterator(); iterator.hasNext();) {
                            subscriptionInfo = (SubscriptionInfo) iterator.next();
                            if (subscriptionInfo.subscription.getId().equals(subscriptionId)) {
                                iterator.remove();
                                break;
                            }
                        }
                    }
                }
            } else {
                AHContainerAddress containerAddress = new AHM2MContainerAddress(requestUri);
                if (!isValidLocalHagId(containerAddress.getHagId()))
                    servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
                String appliancePid = containerAddress.getAppliancePid();
                if (containerAddress.getAppliancePid() != null && containerAddress.getEndPointId() == null
                        && containerAddress.getContainerName() == null) {
                    ContentInstance ci = hapService.getLocalContentInstance(containerAddress);
                    boolean result = false;
                    // Only existing resources are deleted
                    if (ci != null) {
                        result = appliancesProxy.deleteAppliance(appliancePid);
                        if (!result) {
                            servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
                            return;
                        }
                    } else {
                        servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
                        return;
                    }

                } else {
                    servletResponse.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
                }
                ContentInstance ci = new ContentInstance();
                ci.setId(System.currentTimeMillis());
                writeXmlObject(servletResponse, ci);
            }
        } catch (Exception e) {
            LOG.error("service: error while parsing local request", e);
            servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        }
    } else {
        servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:org.opencms.main.OpenCmsCore.java

/**
 * This method performs the error handling for OpenCms.<p>
 *
 * @param cms the current cms context, might be null !
 * @param req the client request/*from  w  w w  .ja v  a2 s .  c  o  m*/
 * @param res the client response
 * @param t the exception that occurred
 */
private void errorHandling(CmsObject cms, HttpServletRequest req, HttpServletResponse res, Throwable t) {

    // remove the controller attribute from the request
    CmsFlexController.removeController(req);

    boolean canWrite = (!res.isCommitted() && !res.containsHeader("Location"));
    int status = -1;
    boolean isGuest = true;

    if (t instanceof ServletException) {
        ServletException s = (ServletException) t;
        if (s.getRootCause() != null) {
            t = s.getRootCause();
        }
    } else if (t instanceof CmsSecurityException) {
        // access error - display login dialog
        if (canWrite) {
            try {
                m_authorizationHandler.requestAuthorization(req, res, getLoginFormURL(req, res));
            } catch (IOException ioe) {
                // there is nothing we can do about this
            }
            return;
        }
    } else if (t instanceof CmsDbEntryNotFoundException) {
        // user or group does not exist
        status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
        isGuest = false;
    } else if (t instanceof CmsVfsResourceNotFoundException) {
        // file not found - display 404 error.
        status = HttpServletResponse.SC_NOT_FOUND;
    } else if (t instanceof CmsException) {
        if (t.getCause() != null) {
            t = t.getCause();
        }
        LOG.error(t.getLocalizedMessage(), t);
    } else {
        LOG.error(t.getLocalizedMessage(), t);
    }

    if (status < 1) {
        // error code not set - set "internal server error" (500)
        status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    res.setStatus(status);

    try {
        if ((cms != null) && (cms.getRequestContext().getCurrentUser() != null)) {
            isGuest = isGuest && (cms.getRequestContext().getCurrentUser().isGuestUser()
                    || cms.userInGroup(cms.getRequestContext().getCurrentUser().getName(),
                            OpenCms.getDefaultUsers().getGroupGuests()));
        }
    } catch (CmsException e) {
        // result is false
        LOG.error(e.getLocalizedMessage(), e);
    }

    if (canWrite) {
        res.setContentType("text/html");
        CmsRequestUtil.setNoCacheHeaders(res);
        if (!isGuest && (cms != null) && !cms.getRequestContext().getCurrentProject().isOnlineProject()) {
            try {
                res.setStatus(HttpServletResponse.SC_OK);
                res.getWriter().print(createErrorBox(t, req, cms));
            } catch (IOException e) {
                // can be ignored
                LOG.error(e.getLocalizedMessage(), e);
            }
        } else {
            try {
                res.sendError(status, t.toString());
            } catch (IOException e) {
                // can be ignored
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
}