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


Java StaplerResponse.setStatus方法代码示例

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


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

示例1: generateResponse

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
 * TO DO
 * @param req
 * @param rsp
 * @param node
 * @throws IOException
 * @throws ServletException
 */
@Override
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
    // Check if the latest badge is already cached
	String v = req.getHeader("If-None-Match");
    if (etag.equals(v)) {
        rsp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }

    rsp.setHeader("ETag", etag);
    rsp.setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
    rsp.setHeader("Cache-Control", "no-cache, private");
    rsp.setHeader("Content-Type", "image/svg+xml;charset=utf-8");
    rsp.setHeader("Content-Length", length);
    rsp.getOutputStream().write(payload);
}
 
开发者ID:SxMShaDoW,项目名称:embeddable-badges-plugin,代码行数:25,代码来源:StatusImage.java

示例2: 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

示例3: generateResponse

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@Override
public void generateResponse( StaplerRequest req, StaplerResponse rsp, Object node )
    throws IOException, ServletException
{
    String v = req.getHeader( "If-None-Match" );
    if ( etag.equals( v ) )
    {
        rsp.setStatus( SC_NOT_MODIFIED );
        return;
    }

    rsp.setHeader( "ETag", etag );
    rsp.setHeader( "Expires", "Fri, 01 Jan 1984 00:00:00 GMT" );
    rsp.setHeader( "Cache-Control", "no-cache, private" );
    rsp.setHeader( "Content-Type", "image/svg+xml;charset=utf-8" );
    rsp.setHeader( "Content-Length", length );
    rsp.getOutputStream().write( payload.getBytes() );
}
 
开发者ID:yannickcr,项目名称:jenkins-status-badges-plugin,代码行数:19,代码来源:StatusImage.java

示例4: 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

示例5: 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

示例6: jsonResponse

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public static HttpResponse jsonResponse(final CollectorRegistry collectorRegistry) {
    return new HttpResponse() {
        @Override
        public void generateResponse(StaplerRequest request, StaplerResponse response, Object node) throws IOException, ServletException {
            response.setStatus(StaplerResponse.SC_OK);
            response.setContentType(TextFormat.CONTENT_TYPE_004);

            StringWriter buffer = new StringWriter();
            TextFormat.write004(buffer, collectorRegistry.metricFamilySamples());
            buffer.close();
            response.getWriter().write(buffer.toString());
        }
    };
}
 
开发者ID:fabric8io,项目名称:fabric8-jenkins-workflow-steps,代码行数:15,代码来源:MetricsRequest.java

示例7: generateResponse

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@Override
public void generateResponse(StaplerRequest req,
    StaplerResponse rsp,
    Object o) throws IOException, ServletException {

    rsp.setStatus(status);
    rsp.setContentType("application/json");
    rsp.getWriter().println(json);
}
 
开发者ID:dpires,项目名称:jenkins-slack-webhook-plugin,代码行数:10,代码来源:JsonResponse.java

示例8: doIndex

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@RequirePOST
public void doIndex(StaplerRequest request, StaplerResponse response) {
    if (isJenkinsValidation(request)) {
        response.setHeader(X_INSTANCE_IDENTITY, Identity.getValueOrDefault(this.identity));
        response.setStatus(HTTP_OK);
        return;
    }

    String payload = getPayload(request);

    checkState(payload != null, "Not intended to be browsed interactively (must specify payload parameter)."
            + " Ensure that the web hook Content-Type header is application/x-www-form-urlencoded");

    String eventName = getEventType(request);
    GitHubEvent event = GitHubEvent.from(eventName);
    switch (event) {
        case PING:
        case SUPPORT:
            response.setStatus(HTTP_OK);
            break;
        case PUSH:
            PushCause cause = createCause(payload);
            this.triggerBuilds(Jenkins.getInstance(), cause);
            break;
        case UNKNOWN:
            String msg = String.format("Spoon WebHook event type (%s) is not supported. Only push and support events are supported", eventName);
            throw new IllegalArgumentException(msg);
    }
}
 
开发者ID:spoonapps,项目名称:jenkins,代码行数:30,代码来源:SpoonWebHook.java

示例9: generateResponse

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void generateResponse(StaplerRequest req, StaplerResponse resp, Object node) throws IOException,
        ServletException {
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setHeader(MetricsRootAction.CACHE_CONTROL, MetricsRootAction.NO_CACHE);
    resp.setContentType(PLAIN_TEXT_CONTENT_TYPE);
    final PrintWriter writer = resp.getWriter();
    try {
        writer.println(CONTENT);
    } finally {
        writer.close();
    }
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:16,代码来源:MetricsRootAction.java

示例10: doDynamic

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doDynamic(StaplerRequest request, StaplerResponse response) {
    String token = request.getOriginalRestOfPath().substring(1); //Strip leading slash

    CharBuffer dest = CharBuffer.allocate(request.getContentLength());

    try {
        BufferedReader reader = request.getReader();

        while (reader.read(dest) > 0) {
            //Intentionally blank
        }
    } catch (IOException e) {
        response.setStatus(400);
        return;
    }

    dest.rewind();
    String content = dest.toString();

    Logger.getLogger(WebhookRootAction.class.getName())
            .info("Webhook called with " + token);

    WaitForWebhookExecution exec;
    synchronized (webhooks) {
        exec = webhooks.remove(token);
        if (exec == null) {
            //pipeline has not yet waited on webhook, add an entry to track 
            //that it was already triggered
            alreadyPosted.put(token, content);
        }
    }

    if (exec != null) {
        exec.onTriggered(content);
        response.setHeader("Result", "WebhookTriggered");
        response.setStatus(200);
    } else {
        response.setStatus(202);
    }

}
 
开发者ID:cpitman,项目名称:webhook-step,代码行数:42,代码来源:WebhookRootAction.java

示例11: writeStatus

import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void writeStatus(StaplerResponse rsp, JSReturnCollection status) throws IOException {
    Writer compressedWriter = rsp.getWriter();
    JSONSerializer.toJSON(status).write(compressedWriter);
    rsp.setStatus(200);
    compressedWriter.flush();
}
 
开发者ID:jenkinsci,项目名称:lucene-search-plugin,代码行数:7,代码来源:LuceneManager.java


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