Java Code Examples for javax.servlet.http.HttpServletResponse#SC_GONE

The following examples show how to use javax.servlet.http.HttpServletResponse#SC_GONE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletStatusHandler.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, IStatus error) throws ServletException {
	int httpCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
	ServerStatus serverStatus;
	if (error instanceof ServerStatus) {
		serverStatus = (ServerStatus) error;
		httpCode = serverStatus.getHttpCode();
	} else {
		serverStatus = new ServerStatus(error, httpCode);
	}
	response.setCharacterEncoding("UTF-8");
	//TODO change check for a generic property
	if ("TIAM".equals(PreferenceHelper.getString(ServerConstants.CONFIG_AUTH_NAME, null))) {
		if (httpCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
			httpCode = 599;
		}
		if (httpCode == HttpServletResponse.SC_NOT_FOUND) {
			httpCode = HttpServletResponse.SC_GONE;
		}
	}
	response.setStatus(httpCode);
	response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
	response.setContentType(ProtocolConstants.CONTENT_TYPE_JSON);
	try {
		response.getWriter().print(serverStatus.toJSON().toString());
	} catch (IOException ioe) {
		//just throw a servlet exception
		throw new ServletException(error.getMessage(), error.getException());
	}
	return true;
}
 
Example 2
Source File: CmsEvents.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected static int verifySubContent(Delegator delegator, String contentId, String contentIdFrom) throws GeneralException {
    List<GenericValue> contentAssoc = EntityQuery.use(delegator).from("ContentAssoc")
            .where("contentId", contentIdFrom, "contentIdTo", contentId, "contentAssocTypeId", "SUB_CONTENT")
            .cache().queryList();

    boolean hadContent = false;
    if (UtilValidate.isNotEmpty(contentAssoc)) {
        hadContent = true;
    }
    contentAssoc = EntityUtil.filterByDate(contentAssoc);
    if (UtilValidate.isEmpty(contentAssoc)) {
        List<GenericValue> assocs = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentIdFrom).cache().filterByDate().queryList();
        if (assocs != null) {
            for (GenericValue assoc : assocs) {
                int subContentStatusCode = verifySubContent(delegator, contentId, assoc.getString("contentIdTo"));
                if (subContentStatusCode == HttpServletResponse.SC_OK) {
                    return HttpServletResponse.SC_OK;
                } else if (subContentStatusCode == HttpServletResponse.SC_GONE) {
                    hadContent = true;
                }
            }
        }
    } else {
        if (Debug.verboseOn()) Debug.logVerbose("Found assocs: " + contentAssoc, module);
        return HttpServletResponse.SC_OK;
    }
    if (hadContent) return HttpServletResponse.SC_GONE;
    return HttpServletResponse.SC_NOT_FOUND;
}
 
Example 3
Source File: ManagementException.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public static ManagementException createGoneManagementException(final String message)
{
    return new ManagementException(HttpServletResponse.SC_GONE, message, null);
}
 
Example 4
Source File: CmsEvents.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
protected static int verifyContentToWebSite(Delegator delegator, String webSiteId, String contentId) throws GeneralException {
    // first check if the passed in contentId is a publish point for the web site
    List<GenericValue> publishPoints = null;
    boolean hadContent = false;
    try {
        publishPoints = EntityQuery.use(delegator).from("WebSiteContent")
                .where("webSiteId", webSiteId, "contentId", contentId, "webSiteContentTypeId", "PUBLISH_POINT")
                .orderBy("-fromDate").cache().queryList();
    } catch (GenericEntityException e) {
        throw e;
    }
    if (UtilValidate.isNotEmpty(publishPoints)) {
        hadContent = true;
    }
    publishPoints = EntityUtil.filterByDate(publishPoints);
    if (UtilValidate.isNotEmpty(publishPoints)) {
        if (Debug.verboseOn()) Debug.logVerbose("Found publish points: " + publishPoints, module);
        return HttpServletResponse.SC_OK;
    } else {
        // the passed in contentId is not a publish point for the web site;
        // however we will publish its content if it is a node of one of the trees that have a publish point as the root
        List<GenericValue> topLevelContentValues = EntityQuery.use(delegator).from("WebSiteContent")
                .where("webSiteId", webSiteId, "webSiteContentTypeId", "PUBLISH_POINT")
                .orderBy("-fromDate").cache().filterByDate().queryList();

        if (topLevelContentValues != null) {
            for (GenericValue point: topLevelContentValues) {
                int subContentStatusCode = verifySubContent(delegator, contentId, point.getString("contentId"));
                if (subContentStatusCode == HttpServletResponse.SC_OK) {
                    return HttpServletResponse.SC_OK;
                } else if (subContentStatusCode == HttpServletResponse.SC_GONE) {
                    hadContent = true;
                }
            }
        }
    }
    int responseCode;
    if (hadContent) {
        responseCode = HttpServletResponse.SC_GONE;
    } else {
        responseCode = HttpServletResponse.SC_NOT_FOUND;
    }
    Debug.logWarning("Could not verify contentId [" + contentId + "] to webSiteId [" + webSiteId + "], returning code: " + responseCode, module);
    return responseCode;
}