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


Java StaplerResponse.addHeader方法代码示例

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


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

示例1: cors

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public HttpResponse cors(@CheckForNull String accessKey, final HttpResponse resp) {
    final MetricsAccessKey key = getAccessKey(accessKey);
    return key == null ? resp : new HttpResponse() {
        public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node)
                throws IOException, ServletException {
            String origin = req.getHeader("Origin");
            if (StringUtils.isNotBlank(origin) && key.isOriginAllowed(origin)) {
                rsp.addHeader("Access-Control-Allow-Origin", origin);
                rsp.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
                rsp.addHeader("Access-Control-Allow-Headers", "Accept, Authorization");
                if ("OPTIONS".equals(req.getMethod())) {
                    rsp.setStatus(200);
                    return;
                }
            }
            resp.generateResponse(req, rsp, node);
        }
    };
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:20,代码来源:MetricsAccessKey.java

示例2: exitWebHook

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
 * Exit the WebHook
 *
 * @param result GogsResults
 */
private void exitWebHook(GogsResults result, StaplerResponse resp) throws IOException {
    if (result.getStatus() != 200) {
        LOGGER.warning(result.getMessage());
    }
    JSONObject json = new JSONObject();
    json.element("result", result.getStatus() == 200 ? "OK" : "ERROR");
    json.element("message", result.getMessage());
    resp.setStatus(result.getStatus());
    resp.addHeader("Content-Type", "application/json");
    PrintWriter printer = resp.getWriter();
    printer.print(json.toString());
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:18,代码来源:GogsWebHook.java

示例3: doProgressText

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
 * Implements the progressive text handling.
 * This method is used as a "web method" with progressiveText.jelly.
 */
public void doProgressText(StaplerRequest req, StaplerResponse rsp) throws IOException {
    setContentType(rsp);
    rsp.setStatus(HttpServletResponse.SC_OK);

    if(!source.exists()) {
        // file doesn't exist yet
        rsp.addHeader("X-Text-Size","0");
        rsp.addHeader("X-More-Data","true");
        return;
    }

    long start = 0;
    String s = req.getParameter("start");
    if(s!=null)
        start = Long.parseLong(s);

    if(source.length() < start )
        start = 0;  // text rolled over

    CharSpool spool = new CharSpool();
    long r = writeLogTo(start,spool);

    rsp.addHeader("X-Text-Size",String.valueOf(r));
    if(!completed)
        rsp.addHeader("X-More-Data","true");

    Writer w = createWriter(req, rsp, r - start);
    spool.writeTo(new LineEndNormalizingWriter(w));
    w.close();
}
 
开发者ID:fabric8io,项目名称:fabric8-jenkins-workflow-steps,代码行数:35,代码来源:LargeText.java

示例4: doGenerateKey

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public FormValidation doGenerateKey(StaplerResponse rsp, URL ec2EndpointUrl, boolean useInstanceProfileForCredentials, String accessId, String secretKey)
        throws IOException, ServletException {
    try {
        AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
        AmazonEC2 ec2 = connect(credentialsProvider, ec2EndpointUrl);
        List<KeyPairInfo> existingKeys = ec2.describeKeyPairs().getKeyPairs();

        int n = 0;
        while (true) {
            boolean found = false;
            for (KeyPairInfo k : existingKeys) {
                if (k.getKeyName().equals("hudson-" + n)) {
                    found = true;
                }
            }
            if (!found) {
                break;
            }
            n++;
        }

        CreateKeyPairRequest request = new CreateKeyPairRequest("hudson-" + n);
        KeyPair key = ec2.createKeyPair(request).getKeyPair();

        rsp.addHeader("script", "findPreviousFormItem(button,'privateKey').value='" + key.getKeyMaterial().replace("\n", "\\n") + "'");

        return FormValidation.ok(Messages.EC2Cloud_Success());
    } catch (AmazonClientException e) {
        LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e);
        return FormValidation.error(e.getMessage());
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:33,代码来源:EC2Cloud.java


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