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


Java SlingHttpServletResponse.setHeader方法代码示例

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


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

示例1: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
		throws ServletException, IOException {

	String fileName = request.getParameter("filename");
	String content = request.getParameter("content");

	if (fileName == null || fileName.length() == 0) {
		LOGGER.error("Parameter fileName is required");
		return;
	}

	response.setContentType("application/octet-stream"); // Your content type
	response.setHeader("Content-Disposition",
			"attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));

	InputStream input = IOUtils.toInputStream(content);

	int read = 0;
	byte[] bytes = new byte[BYTES_DOWNLOAD];
	OutputStream os = response.getOutputStream();

	while ((read = input.read(bytes)) != -1) {
		os.write(bytes, 0, read);
	}
	input.close();
	os.flush();
	os.close();
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:30,代码来源:ScriptResultServlet.java

示例2: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
                                                    throws ServletException, IOException {
    response.setContentType("application/json");
    response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");

    // parse query parameters
    String tagsStr = StringUtils.defaultString(request.getParameter(PARAM_TAGS));
    String[] tags = tagsStr.split("[, ;]+");
    String combineTagsOr = StringUtils.defaultString(request.getParameter(PARAM_COMBINE_TAGS_OR), "true");

    // execute health checks
    HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
    options.setCombineTagsWithOr(Boolean.valueOf(combineTagsOr));
    options.setForceInstantExecution(true);
    List<HealthCheckExecutionResult> results = healthCheckExecutor.execute(options, tags);

    // check results
    boolean allOk = true;
    for(HealthCheckExecutionResult result : results) {
        if(!result.getHealthCheckResult().isOk()) {
            allOk = false;
            break;
        }
    }

    // set appropriate status code
    if(!allOk) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    } else {
        response.setStatus(HttpServletResponse.SC_OK);
    }

    // write out JSON response
    JSONObject resultJson = new JSONObject();
    try {
        generateResponse(results, resultJson);
    } catch(JSONException ex) {
        logger.error("Could not serialize result into JSON", ex);
    }
    response.getWriter().write(resultJson.toString());
}
 
开发者ID:shinesolutions,项目名称:aem-healthcheck,代码行数:43,代码来源:HealthCheckExecutorServlet.java

示例3: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
		throws ServletException, IOException {
	String fileName = request.getParameter("filename");
	String filePath = request.getParameter("filepath");

	String mode = request.getParameter("mode");

	try {
		final ResourceResolver resourceResolver = request.getResourceResolver();
		final Session session = resourceResolver.adaptTo(Session.class);

		if (!("view").equals(mode)) {
			response.setContentType("application/octet-stream"); // Your content type
			response.setHeader("Content-Disposition",
					"attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
		}

		String path = StringUtils.replace(filePath, "_jcr_content", "jcr:content");

		Node jcrContent = session.getNode(path + "/jcr:content");

		InputStream input = jcrContent.getProperty("jcr:data").getBinary().getStream();

		session.save();
		int read;
		byte[] bytes = new byte[BYTES_DOWNLOAD];
		OutputStream os = response.getOutputStream();

		while ((read = input.read(bytes)) != -1) {
			os.write(bytes, 0, read);
		}
		input.close();
		os.flush();
		os.close();

	} catch (RepositoryException e) {
		LOGGER.error(e.getMessage(), e);
		response.sendRedirect("/etc/cqsm.html");
		// response.sendError(500);
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:43,代码来源:ScriptDownloadServlet.java


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