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


Java HttpResponses类代码示例

本文整理汇总了Java中hudson.util.HttpResponses的典型用法代码示例。如果您正苦于以下问题:Java HttpResponses类的具体用法?Java HttpResponses怎么用?Java HttpResponses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doPost

import hudson.util.HttpResponses; //导入依赖的package包/类
public HttpResponse doPost(StaplerRequest request) throws IOException {
    if (!request.getMethod().equals("POST")) {
        return HttpResponses
                .error(HttpServletResponse.SC_BAD_REQUEST,
                        "Only POST requests are supported, this was a " + request.getMethod() + " request");
    }
    if (!"application/json".equals(request.getContentType())) {
        return HttpResponses
                .error(HttpServletResponse.SC_BAD_REQUEST,
                        "Only application/json content is supported, this was " + request.getContentType());
    }
    String type = request.getHeader("X-Gitea-Event");
    if (StringUtils.isBlank(type)) {
        return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST,
                "Expecting a Gitea event, missing expected X-Gitea-Event header");
    }
    String origin = SCMEvent.originOf(request);
    boolean processed = false;
    for (GiteaWebhookHandler<?, ?> h : ExtensionList.lookup(GiteaWebhookHandler.class)) {
        if (h.matches(type)) {
            h.process(request.getInputStream(), origin);
            processed = true;
        }
    }
    return HttpResponses.plainText(processed ? "Processed" : "Ignored");
}
 
开发者ID:jenkinsci,项目名称:gitea-plugin,代码行数:27,代码来源:GiteaWebhookAction.java

示例2: doImpersonate

import hudson.util.HttpResponses; //导入依赖的package包/类
@RequirePOST
public HttpResponse doImpersonate(StaplerRequest req, @QueryParameter String name) {
    Authentication auth = Jenkins.getAuthentication();
    GrantedAuthority[] authorities = auth.getAuthorities();
    if (authorities == null || StringUtils.isBlank(name)) {
        return HttpResponses.redirectToContextRoot();
    }
    GrantedAuthority authority = null;
    for (GrantedAuthority a : authorities) {
        if (a.getAuthority().equals(name)) {
            authority = a;
            break;
        }
    }
    if (authority == null) {
        return HttpResponses.redirectToContextRoot();
    }
    if (!SecurityRealm.AUTHENTICATED_AUTHORITY.equals(authority)) {
        ACL.impersonate(new ImpersonationAuthentication(auth, authority, SecurityRealm.AUTHENTICATED_AUTHORITY));
    } else {
        ACL.impersonate(new ImpersonationAuthentication(auth, SecurityRealm.AUTHENTICATED_AUTHORITY));
    }
    return HttpResponses.redirectToContextRoot();
}
 
开发者ID:jenkinsci,项目名称:impersonation-plugin,代码行数:25,代码来源:ImpersonationAction.java

示例3: execute

import hudson.util.HttpResponses; //导入依赖的package包/类
public void execute() {
    if (pushHook.getRepository() != null && pushHook.getRepository().getUrl() == null) {
        LOGGER.log(Level.WARNING, "No repository url found.");
        return;
    }

    if (project instanceof Job<?, ?>) {
        ACL.impersonate(ACL.SYSTEM, new TriggerNotifier(project, secretToken, Jenkins.getAuthentication()) {
            @Override
            protected void performOnPost(GitLabPushTrigger trigger) {
                trigger.onPost(pushHook);
            }
        });
        throw HttpResponses.ok();
    }
    if (project instanceof SCMSourceOwner) {
        ACL.impersonate(ACL.SYSTEM, new SCMSourceOwnerNotifier());
        throw HttpResponses.ok();
    }
    throw HttpResponses.errorWithoutStack(409, "Push Hook is not supported for this project");
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:22,代码来源:PushBuildAction.java

示例4: doHealthcheck

import hudson.util.HttpResponses; //导入依赖的package包/类
/**
 * Binds the health checks to the CORS aware URL {@code /metrics/healthcheck} where the metrics access key is
 * provided in the form field {@code key} or an {@code Authorization: Jenkins-Metrics-Key {key}} header
 *
 * @param req the request
 * @param key the key from the form field.
 * @return the {@link HttpResponse}
 * @throws IllegalAccessException if the access attempt is invalid.
 */
@SuppressWarnings("unused") // stapler binding
@Restricted(NoExternalUse.class) // stapler binding
public HttpResponse doHealthcheck(StaplerRequest req, @QueryParameter("key") String key)
        throws IllegalAccessException {
    requireCorrectMethod(req);
    if (StringUtils.isBlank(key)) {
        key = getKeyFromAuthorizationHeader(req);
    }
    Metrics.checkAccessKeyHealthCheck(key);
    long ifModifiedSince = req.getDateHeader("If-Modified-Since");
    long maxAge = getCacheControlMaxAge(req);
    Metrics.HealthCheckData data = Metrics.getHealthCheckData();
    if (data == null || (maxAge != -1 && data.getLastModified() + maxAge < System.currentTimeMillis())) {
        data = new Metrics.HealthCheckData(Metrics.healthCheckRegistry().runHealthChecks());
    } else if (ifModifiedSince != -1 && data.getLastModified() < ifModifiedSince) {
        return Metrics.cors(key, HttpResponses.status(HttpServletResponse.SC_NOT_MODIFIED));
    }
    return Metrics.cors(key, new HealthCheckResponse(data));
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:29,代码来源:MetricsRootAction.java

示例5: doHealthcheckOk

import hudson.util.HttpResponses; //导入依赖的package包/类
/**
 * Condense the health check into one bit of information
 * for frontend reverse proxies like haproxy.
 *
 * Other health check calls requires authentication, which
 * is not suitable for the haproxy use. But this endpoint
 * only exposes one bit information, it's deemed OK to be exposed
 * unsecurely.
 *
 * return status 200 if everything is OK, 503 (service unavailable) otherwise
 *
 * @param req the request
 * @return the HTTP response
 */
@SuppressWarnings("unused") // stapler binding
@Restricted(NoExternalUse.class) // stapler binding
public HttpResponse doHealthcheckOk(StaplerRequest req) {
    long ifModifiedSince = req.getDateHeader("If-Modified-Since");
    long maxAge = getCacheControlMaxAge(req);
    Metrics.HealthCheckData data = Metrics.getHealthCheckData();
    if (data == null || (maxAge != -1 && data.getLastModified() + maxAge < System.currentTimeMillis())) {
        data = new Metrics.HealthCheckData(Metrics.healthCheckRegistry().runHealthChecks());
    } else if (ifModifiedSince != -1 && data.getLastModified() < ifModifiedSince) {
        return HttpResponses.status(HttpServletResponse.SC_NOT_MODIFIED);
    }
    for (HealthCheck.Result result : data.getResults().values()) {
        if (!result.isHealthy()) {
            return new StatusResponse(HttpServletResponse.SC_SERVICE_UNAVAILABLE, data.getLastModified(),
                    data.getExpires());
        }
    }
    return new StatusResponse(HttpServletResponse.SC_OK, data.getLastModified(), data.getExpires());
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:34,代码来源:MetricsRootAction.java

示例6: doIndex

import hudson.util.HttpResponses; //导入依赖的package包/类
/**
 * Web binding for {@literal /}
 *
 * @return the response
 */
@Restricted(NoExternalUse.class) // only for use by stapler web binding
public HttpResponse doIndex() {
    return HttpResponses
            .html("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" +
                    "        \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
                    "<html>\n" +
                    "<head>\n" +
                    "  <title>Metrics</title>\n" +
                    "</head>\n" +
                    "<body>\n" +
                    "  <h1>Operational Menu</h1>\n" +
                    "  <ul>\n" +
                    "    <li><a href=\"./metrics?pretty=true\">Metrics</a></li>\n" +
                    "    <li><a href=\"./ping\">Ping</a></li>\n" +
                    "    <li><a href=\"./threads\">Threads</a></li>\n" +
                    "    <li><a href=\"./healthcheck?pretty=true\">Healthcheck</a></li>\n" +
                    "  </ul>\n" +
                    "</body>\n" +
                    "</html>");
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:26,代码来源:MetricsRootAction.java

示例7: getProject

import hudson.util.HttpResponses; //导入依赖的package包/类
public Job<?, ?> getProject( String job, StaplerRequest req, StaplerResponse rsp )
    throws HttpResponses.HttpResponseException
{
    Job<?, ?> p;

    SecurityContext orig = ACL.impersonate( ACL.SYSTEM );
    try
    {
        p = Jenkins.getInstance().getItemByFullName( job, Job.class );
    }
    finally
    {
        SecurityContextHolder.setContext( orig );
    }

    if ( p == null )
    {
        throw org.kohsuke.stapler.HttpResponses.notFound();
    }

    return p;
}
 
开发者ID:yannickcr,项目名称:jenkins-status-badges-plugin,代码行数:23,代码来源:BuildStatus.java

示例8: getDynamic

import hudson.util.HttpResponses; //导入依赖的package包/类
@Override
public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
    try {
        final Build item = getRun(Combination.fromString(token));
        if (item != null) {
            if (item.getNumber() == this.getNumber()) {
                return item;
            } else {
                // redirect the user to the correct URL
                String url = Functions.joinPath(item.getUrl(), req.getRestOfPath());
                final String qs = req.getQueryString();
                if (qs != null) {
                    url += '?' + qs;
                }
                throw HttpResponses.redirectViaContextPath(url);
            }
        }
    } catch (final IllegalArgumentException e) {
        // failed to parse the token as Combination. Must be something else
    }
    return super.getDynamic(token, req, rsp);
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:23,代码来源:DynamicBuild.java

示例9: doPostCredential

import hudson.util.HttpResponses; //导入依赖的package包/类
/**
 * Submits the Oracle account username/password.
 */
@RequirePOST
public HttpResponse doPostCredential(@QueryParameter String username, @QueryParameter String password) throws IOException, ServletException {
    Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
    this.username = username;
    this.password = Secret.fromString(password);
    save();
    return HttpResponses.redirectTo("credentialOK");
}
 
开发者ID:jenkinsci,项目名称:apache-httpcomponents-client-4-api-plugin,代码行数:12,代码来源:Client4JDKInstaller.java

示例10: doStopTracking

import hudson.util.HttpResponses; //导入依赖的package包/类
@Restricted(DoNotUse.class)
public HttpResponses.HttpResponseException doStopTracking(@QueryParameter int id) {
    for (WorkItem workItem : getBacklog()) {
        if (workItem.getId() == id) {
            boolean removed = backlog.remove(workItem);
            if (removed) { // Might be disposed or removed concurrently
                persist();
            }
            break;
        }
    }
    return HttpResponses.forwardToPreviousPage();
}
 
开发者ID:jenkinsci,项目名称:resource-disposer-plugin,代码行数:14,代码来源:AsyncResourceDisposer.java

示例11: doIndex

import hudson.util.HttpResponses; //导入依赖的package包/类
/**
 * Starts the deploy now action.
 *
 * @param req the request.
 * @return the response.
 */
@SuppressWarnings("unused") // used by stapler
public HttpResponse doIndex(StaplerRequest req) {
    if (!isDeployPossible(owner)) {
        return HttpResponses.notFound();
    }
    return HttpResponses.forwardToView(this, "configure");
}
 
开发者ID:jenkinsci,项目名称:deployer-framework-plugin,代码行数:14,代码来源:DeployNowProjectAction.java

示例12: execute

import hudson.util.HttpResponses; //导入依赖的package包/类
public void execute(StaplerResponse response) {
    if (build != null) {
        try {
            response.sendRedirect2(Jenkins.getInstance().getRootUrl() + build.getUrl());
        } catch (IOException e) {
            try {
                response.sendRedirect2(Jenkins.getInstance().getRootUrl() + build.getBuildStatusUrl());
            } catch (IOException e1) {
                throw HttpResponses.error(500, "Failed to redirect to build page");
            }
        }
    }
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:14,代码来源:BuildPageRedirectAction.java

示例13: writeStatusBody

import hudson.util.HttpResponses; //导入依赖的package包/类
@Override
protected void writeStatusBody(StaplerResponse response, Run<?, ?> build, BuildStatus status) {
    try {
        response.setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
        response.setHeader("Cache-Control", "no-cache, private");
        response.setHeader("Content-Type", "image/png");
        IOUtils.copy(getStatusImage(status), response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        throw HttpResponses.error(500, "Could not generate response.");
    }
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:13,代码来源:StatusPngAction.java

示例14: writeStatusBody

import hudson.util.HttpResponses; //导入依赖的package包/类
@Override
protected void writeStatusBody(StaplerResponse response, Run<?, ?> build, BuildStatus status) {
    try {
        JSONObject object = new JSONObject();
        object.put("sha", sha1);
        if (build != null) {
            object.put("id", build.getNumber());
        }
        object.put("status", status.getValue());
        writeBody(response, object);
    } catch (IOException e) {
        throw HttpResponses.error(500, "Failed to generate response");
    }
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:15,代码来源:StatusJsonAction.java

示例15: execute

import hudson.util.HttpResponses; //导入依赖的package包/类
public void execute(StaplerResponse response) {
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project);
    if (!hasGitSCM(item)) {
        throw HttpResponses.error(409, "The project has no GitSCM configured");
    }
    writeStatusBody(response, build, getStatus(build));
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:8,代码来源:BuildStatusAction.java


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