当前位置: 首页>>代码示例>>Java>>正文


Java SlingHttpServletResponse.sendError方法代码示例

本文整理汇总了Java中org.apache.sling.api.SlingHttpServletResponse.sendError方法的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletResponse.sendError方法的具体用法?Java SlingHttpServletResponse.sendError怎么用?Java SlingHttpServletResponse.sendError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.api.SlingHttpServletResponse的用法示例。


在下文中一共展示了SlingHttpServletResponse.sendError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doModifyProduct

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
private void doModifyProduct(SlingHttpServletRequest request, SlingHttpServletResponse response, CommerceSession session) throws IOException {
    String qty = request.getParameter("quantity");
    int quantity = StringUtils.isNumeric(qty) ? xssAPI.getValidInteger(qty, 1) : -1;
    if (quantity < 0) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    String entryNumber = request.getParameter("entryNumber");
    int entry = xssAPI.getValidInteger(entryNumber, -1);
    try {
        if (entry < 0 || entry >= session.getCartEntries().size()) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        if (quantity > 0) {
            session.modifyCartEntry(entry, quantity);
        } else {
            session.deleteCartEntry(entry);
        }

    } catch (CommerceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:27,代码来源:CartEntryServlet.java

示例2: doAddProduct

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
private void doAddProduct(SlingHttpServletRequest request, SlingHttpServletResponse response, CommerceSession session)
        throws IOException {
    String productPath = request.getParameter("product-path");
    String qty = request.getParameter("product-quantity");

    Resource productResource = request.getResourceResolver().getResource(productPath);
    Product product = productResource.adaptTo(Product.class);

    int quantity = 1;
    if (qty != null && qty.length() > 0) {
        quantity = xssAPI.getValidInteger(qty, 1);
        if (quantity < 0) {
            quantity = 1;
        }
    }

    try {
        session.addCartEntry(product, quantity);
    } catch (CommerceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:23,代码来源:CartEntryServlet.java

示例3: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
		throws IOException, ServletException {
	log.trace("doGet");
	String suffix = request.getRequestPathInfo().getSuffix();

	if (StringUtils.isNotEmpty(suffix)) {
		log.debug("Retrieving data layer for {}", suffix);
		Resource resource = request.getResourceResolver().getResource(suffix);
		if (resource != null) {

			HttpServletRequest req = requestResponseFactory.createRequest("GET", suffix + ".html");
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			HttpServletResponse resp = requestResponseFactory.createResponse(baos);
			requestProcessor.processRequest(req, resp, request.getResourceResolver());

			DataLayer dataLayer = DataLayerUtil.getDataLayer(req);
			if (dataLayer != null) {
				response.setContentType("application/json");
				response.getWriter().write(DataLayerUtil.toJSON(dataLayer));
			} else {
				log.warn("No Data Layer found for {}", suffix);
				response.sendError(404, "No Data Layer found for " + suffix);
			}

		} else {
			log.warn("No Resource found at {}", suffix);
			response.sendError(404, "No Resource found at " + suffix);
		}
	} else {
		response.sendError(400, "Missing Suffix");
	}

}
 
开发者ID:PerficientDigital,项目名称:AEM-DataLayer,代码行数:34,代码来源:DataLayerTestServlet.java

示例4: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response)
        throws IOException {
    Page currentPage = getCurrentPage(request);
    if (currentPage != null) {
        Resource searchResource = getSearchContentResource(request, currentPage);
        if (searchResource != null) {
            List<ListItem> results = getResults(request, searchResource, currentPage);
            writeJson(results, response);
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:15,代码来源:SearchResultServlet.java

示例5: doDeleteProduct

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
private void doDeleteProduct(SlingHttpServletRequest request, SlingHttpServletResponse response, CommerceSession session) throws IOException {
    String entryNumber = request.getParameter("entryNumber");
    int entry = xssAPI.getValidInteger(entryNumber, -1);
    try {
        if (entry < 0 || entry >= session.getCartEntries().size()) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }
        session.deleteCartEntry(entry);
    } catch (CommerceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-sample-we-retail,代码行数:14,代码来源:CartEntryServlet.java

示例6: doFilter

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
 * Prevent unauthorables from accessing Sling's user admin.
 *
 * @param request The Sling HTTP Servlet Request.
 * @param response The Sling HTTP Servlet Response.
 * @param chain The Filter Chain to continue processin the response.
 */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain chain) throws IOException, ServletException {

    // Since this is a Sling Filter, the request and response objects are guaranteed
    // to be of types SlingHttpServletRequest and SlingHttpServletResponse.
    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)response;
    final String path = slingRequest.getPathInfo().toLowerCase();
    final String method = slingRequest.getMethod();

    response.setCharacterEncoding(CharEncoding.UTF_8);

    if ("POST".equals(method) && path.startsWith("/system")) {
        if (userService != null) {
            final boolean allow = userService.isAuthorable(slingRequest.getResourceResolver().adaptTo(Session.class));

            if (allow) {
                chain.doFilter(request, response);
            } else {
                slingResponse.sendError(SlingHttpServletResponse.SC_FORBIDDEN);
            }
        } else {
            slingResponse.sendError(SlingHttpServletResponse.SC_FORBIDDEN);
        }
    } else {
        chain.doFilter(request, response);
    }
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:37,代码来源:SystemFilter.java

示例7: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	boolean executed = doBase(HttpMethod.GET, request, response);
	if (!executed) {
		log.debug("Could not find REST operation {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
	}
}
 
开发者ID:HeroDigital,项目名称:sling-rest,代码行数:9,代码来源:SlingRestServiceServlet.java

示例8: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	boolean executed = doBase(HttpMethod.POST, request, response);
	if (!executed) {
		log.debug("Could not find REST operation {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
	}
}
 
开发者ID:HeroDigital,项目名称:sling-rest,代码行数:9,代码来源:SlingRestServiceServlet.java

示例9: doPut

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	boolean executed = doBase(HttpMethod.PUT, request, response);
	if (!executed) {
		log.debug("Could not find REST operation {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
	}
}
 
开发者ID:HeroDigital,项目名称:sling-rest,代码行数:9,代码来源:SlingRestServiceServlet.java

示例10: doDelete

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doDelete(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	boolean executed = doBase(HttpMethod.DELETE, request, response);
	if (!executed) {
		log.debug("Could not find REST operation {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
	}
}
 
开发者ID:HeroDigital,项目名称:sling-rest,代码行数:9,代码来源:SlingRestServiceServlet.java

示例11: doFilter

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
 * Handle blog posts that are not published. If the user is authenticated,
 * display a preview bar. If the user is anonymous, seve a 404.
 *
 * @param request The Sling HTTP Servlet Request.
 * @param response The Sling HTTP Servlet Response.
 * @param chain The Filter Chain to continue processin the response.
 */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain chain) throws IOException, ServletException {

    // Since this is a Sling Filter, the request and response objects are guaranteed
    // to be of types SlingHttpServletRequest and SlingHttpServletResponse.
    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)response;

    final Resource resource = slingRequest.getResource();
    final String method = slingRequest.getMethod();
    final String resourceType = resource.getResourceType();

    response.setCharacterEncoding(CharEncoding.UTF_8);

    if ("GET".equals(method) && PublickConstants.PAGE_TYPE_BLOG.equals(resourceType)) {

        if (!resource.getValueMap().get("visible", false)) {
            final boolean authorable = userService.isAuthorable(slingRequest.getResourceResolver().adaptTo(Session.class));

            /* If user is logged in and page isn't published, inject a preview bar. */
            if (authorable) {
                PrintWriter out = response.getWriter();
                CharResponseWrapper responseWrapper = new CharResponseWrapper((HttpServletResponse)response);

                try {
                  chain.doFilter(request, responseWrapper);
                } catch (Exception e) {
                  LOGGER.error("Could not continue chain", e);
                  chain.doFilter(request, response);
                }

                final String servletResponse = new String(responseWrapper.toString());
                final String previewHeader = getPreviewHeader(slingRequest, PREVIEW_HEADER_PATH);

                /* Insert component before body close tag. Append to end if body close tag doesn't exist. */
                if (servletResponse != null && servletResponse.contains(INSERTION_TAG)) {
                    String[] html = servletResponse.split(INSERTION_TAG);

                    out.write(html[0] + INSERTION_TAG + previewHeader + html[1]);
                } else {
                    out.write(servletResponse + previewHeader);
                }
            } else {
                /* If user is not logged in and page isn't published, forward to 404. */
                slingResponse.sendError(SlingHttpServletResponse.SC_NOT_FOUND);
            }
        } else {
            chain.doFilter(request, slingResponse);
        }
    } else {
        chain.doFilter(request, slingResponse);
    }
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:63,代码来源:PreviewFilter.java

示例12: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	// Convert request to convenience object
	RenditionMeta renditionMeta = buildRenditionMeta(request);
	if (renditionMeta == null) {
		log.debug("Failed to build rendition meta for {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}
	
	// Resolve image resource
	Resource resource = request.getResource();
	if (resource == null) {
		log.debug("Missing dam asset at {}", request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}
	
	// Adapt image resource to dam object, supports node with fileReference to image
	Asset damAsset = resource.adaptTo(Asset.class);
	if (damAsset == null) {
		damAsset = extractAssetFromFileReference(resource);
	}
	if (damAsset == null) {
		log.debug("Cannot resolve dam asset at {} for {}", resource.getPath(), request.getPathInfo());
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return;
	}
	
	// Resolve dam asset + meta data to actual rendition
	Rendition rendition = assetRenditionResolver.resolveRendition(damAsset, renditionMeta);
	if (rendition == null) {
		if (redirectOnMissingRendition) {
			sendRedirectToOriginalRendition(request, response, damAsset);
			return;
		} else {
			log.debug("Missing rendition for {} and {}", renditionMeta, damAsset.getPath());
			response.sendError(HttpServletResponse.SC_NOT_FOUND);
			return;
		}
	}
	
	// If extension does not match rendition mime type, redirect or 415 error
	if (!rendition.getMimeType().contains(renditionMeta.getExtension())) {
		if (redirectOnWrongType) {
			sendRedirectToProperExtension(request, response, rendition, renditionMeta);
			return;
		} else {
			log.debug("Wrong extension for {} and request {}", rendition.getMimeType(), renditionMeta.getExtension());
			response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
			return;
		}
	}
	
	writeResponse(response, rendition);
}
 
开发者ID:HeroDigital,项目名称:renditions-servlet,代码行数:57,代码来源:ImageRenditionServlet.java


注:本文中的org.apache.sling.api.SlingHttpServletResponse.sendError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。