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


Java RequirePOST类代码示例

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


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

示例1: doImpersonate

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的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

示例2: doClean

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@RequirePOST
public void doClean(StaplerRequest req, StaplerResponse res) throws IOException, ServletException {
    // TODO switch to Jenkins.getActiveInstance() once 1.590+ is the baseline
    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        throw new IllegalStateException("Jenkins has not been started, or was already shut down");
    }
    final Job job = jenkins.getItemByFullName(req.getParameter("job"), Job.class);
    Timer.get().submit(new Runnable() {
        @Override
        public void run() {
            try {
                job.logRotate();
            } catch (Exception e) {
                logger.log(Level.WARNING, "logRotate failed", e);
            }
        }
    });
    res.forwardToPreviousPage(req);
}
 
开发者ID:jenkinsci,项目名称:cloudbees-disk-usage-simple-plugin,代码行数:21,代码来源:QuickDiskUsagePlugin.java

示例3: doClearRepo

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@RequirePOST
public FormValidation doClearRepo() throws IOException {
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.DELETE)) {
            pulls = new HashMap<>();
            save();
            result = FormValidation.ok("Pulls deleted");
        } else {
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can\'t delete repository file '{}'",
                configFile.getFile().getAbsolutePath(), e);
        result = FormValidation.error(e, "Can't delete: %s", e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:20,代码来源:GitHubPRRepository.java

示例4: doRunTrigger

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
/**
 * Run trigger from web.
 */
@RequirePOST
public FormValidation doRunTrigger() {
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.BUILD)) {
            GitHubPRTrigger trigger = JobHelper.ghPRTriggerFromJob(job);
            if (trigger != null) {
                trigger.run();
                result = FormValidation.ok("GitHub PR trigger run");
                LOG.debug("GitHub PR trigger run for {}", job);
            } else {
                LOG.error("GitHub PR trigger not available for {}", job);
                result = FormValidation.error("GitHub PR trigger not available");
            }
        } else {
            LOG.warn("No permissions to run GitHub PR trigger");
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can't run trigger", e);
        result = FormValidation.error(e, "Can't run trigger: %s", e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:29,代码来源:GitHubPRRepository.java

示例5: doRebuildAllFailed

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@RequirePOST
public FormValidation doRebuildAllFailed() throws IOException {
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.BUILD)) {
            Map<Integer, List<Run<?, ?>>> builds = getAllPrBuilds();
            for (List<Run<?, ?>> buildList : builds.values()) {
                if (!buildList.isEmpty() && Result.FAILURE.equals(buildList.get(0).getResult())) {
                    Run<?, ?> lastBuild = buildList.get(0);
                    rebuild(lastBuild);
                }
            }
            result = FormValidation.ok("Rebuild scheduled");
        } else {
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e);
        result = FormValidation.error(e, "Can't start rebuild: %s", e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:24,代码来源:GitHubPRRepository.java

示例6: doClearRepo

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@Override
@RequirePOST
public FormValidation doClearRepo() throws IOException {
    LOG.debug("Got clear GitHub Branch repo request for {}", getJob().getFullName());
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.DELETE)) {
            branches = new HashMap<>();
            save();
            result = FormValidation.ok("Branches deleted");
        } else {
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can't delete repository file '{}'.",
                configFile.getFile().getAbsolutePath(), e);
        result = FormValidation.error(e, "Can't delete: " + e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:22,代码来源:GitHubBranchRepository.java

示例7: doRunTrigger

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@Override
@RequirePOST
public FormValidation doRunTrigger() throws IOException {
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.BUILD)) {
            GitHubBranchTrigger trigger = ghBranchTriggerFromJob(job);
            if (trigger != null) {
                trigger.run();
                result = FormValidation.ok("GitHub Branch trigger run");
                LOG.debug("GitHub Branch trigger run for {}", job);
            } else {
                LOG.error("GitHub Branch trigger not available for {}", job);
                result = FormValidation.error("GitHub Branch trigger not available");
            }
        } else {
            LOG.warn("No permissions to run GitHub Branch trigger");
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can't run trigger", e.getMessage());
        result = FormValidation.error(e, "Can't run trigger: %s", e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:27,代码来源:GitHubBranchRepository.java

示例8: doRebuildAllFailed

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@Override
@RequirePOST
public FormValidation doRebuildAllFailed() throws IOException {
    FormValidation result;
    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (instance.hasPermission(Item.BUILD)) {
            Map<String, List<Run<?, ?>>> builds = getAllBranchBuilds();
            for (List<Run<?, ?>> buildList : builds.values()) {
                if (!buildList.isEmpty() && Result.FAILURE.equals(buildList.get(0).getResult())) {
                    Run<?, ?> lastBuild = buildList.get(0);
                    rebuild(lastBuild);
                }
            }
            result = FormValidation.ok("Rebuild scheduled");
        } else {
            result = FormValidation.error("Forbidden");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e.getMessage());
        result = FormValidation.error(e, "Can't start rebuild: %s", e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:25,代码来源:GitHubBranchRepository.java

示例9: doPostCredential

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的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: doRebuild

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@RequirePOST
public FormValidation doRebuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (!instance.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String prNumberParam = "prNumber";
        int prId = 0;
        if (req.hasParameter(prNumberParam)) {
            prId = Integer.valueOf(req.getParameter(prNumberParam));
        }

        Map<Integer, List<Run<?, ?>>> builds = getAllPrBuilds();
        List<Run<?, ?>> prBuilds = builds.get(prId);
        if (prBuilds != null && !prBuilds.isEmpty()) {
            if (rebuild(prBuilds.get(0))) {
                result = FormValidation.ok("Rebuild scheduled");
            } else {
                result = FormValidation.warning("Rebuild not scheduled");
            }
        } else {
            result = FormValidation.warning("Build not found");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e);
        result = FormValidation.error(e, "Can't start rebuild: " + e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:34,代码来源:GitHubPRRepository.java

示例11: doBuild

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@RequirePOST
public FormValidation doBuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (!instance.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String param = "branchName";
        String branchName = null;
        if (req.hasParameter(param)) {
            branchName = req.getParameter(param);
        }
        if (isNull(branchName) || !getBranches().containsKey(branchName)) {
            return FormValidation.error("No branch to build");
        }

        final GitHubBranch localBranch = getBranches().get(branchName);
        final GitHubBranchCause cause = new GitHubBranchCause(localBranch, this, "Manual run.", false);
        final JobRunnerForBranchCause runner = new JobRunnerForBranchCause(getJob(),
                ghBranchTriggerFromJob(getJob()));
        final QueueTaskFuture<?> queueTaskFuture = runner.startJob(cause);

        if (nonNull(queueTaskFuture)) {
            result = FormValidation.ok("Build scheduled");
        } else {
            result = FormValidation.warning("Build not scheduled");
        }
    } catch (Exception e) {
        LOG.error("Can't start build", e.getMessage());
        result = FormValidation.error(e, "Can't start build: " + e.getMessage());
    }

    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:38,代码来源:GitHubBranchRepository.java

示例12: doRebuild

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
@Override
@RequirePOST
public FormValidation doRebuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        Jenkins instance = GitHubWebHook.getJenkinsInstance();
        if (!instance.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String param = "branchName";
        String branchName = "";
        if (req.hasParameter(param)) {
            branchName = req.getParameter(param);
        }

        Map<String, List<Run<?, ?>>> allBuilds = getAllBranchBuilds();
        List<Run<?, ?>> branchBuilds = allBuilds.get(branchName);
        if (branchBuilds != null && !allBuilds.isEmpty()) {
            if (rebuild(branchBuilds.get(0))) {
                result = FormValidation.ok("Rebuild scheduled");
            } else {
                result = FormValidation.warning("Rebuild not scheduled");
            }
        } else {
            result = FormValidation.warning("Build not found");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e.getMessage());
        result = FormValidation.error(e, "Can't start rebuild: " + e.getMessage());
    }
    return result;
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:35,代码来源:GitHubBranchRepository.java

示例13: doSubmitContainerStatus

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
/**
 * Submits a new event through Jenkins API.
 * @param inspectData JSON output of docker inspect container (array of container infos)
 * @param hostName Optional name of the host, which submitted the event
 *      &quot;unknown&quot; by default
 * @param hostId Optional host ID. 
 *      &quot;unknown&quot; by default
 * @param status Optional status of the container. 
 *      By default, an artificial {@link DockerEventType#NONE} will be used.    
 * @param time Optional time when the event happened. 
 *      The time is specified in seconds since January 1, 1970, 00:00:00 GMT
 *      Default value - current time
 * @param environment Optional field, which describes the environment
 * @param imageName Optional field, which provides the name of the image
 * @return {@link HttpResponse}
 * @throws IOException Request processing error
 * @throws ServletException Servlet error
 */
//TODO: parameters check
@RequirePOST
public HttpResponse doSubmitContainerStatus(
        @QueryParameter(required = true) String inspectData,
        @QueryParameter(required = false) String hostId,
        @QueryParameter(required = false) String hostName,
        @QueryParameter(required = false) String status,
        @QueryParameter(required = false) long time,
        @QueryParameter(required = false) @CheckForNull String environment,
        @QueryParameter(required = false) @CheckForNull String imageName
) throws IOException, ServletException { 
    checkPermission(DockerTraceabilityPlugin.SUBMIT);
    final ObjectMapper mapper = new ObjectMapper();
    final InspectContainerResponse[] inspectContainerResponses = mapper.readValue(inspectData, InspectContainerResponse[].class);
    final long eventTime = time != 0 ? time : System.currentTimeMillis()/1000;
    final String effectiveHostName = StringUtils.isNotBlank(hostName) ? hostName : "unknown";
    final String effectiveHostId = StringUtils.isNotBlank(hostId) ? hostId : "unknown";
    final String effectiveStatus = StringUtils.isNotBlank(status) 
            ? status.toUpperCase(Locale.ENGLISH) : DockerEventType.NONE.toString();
    final String effectiveImageName = hudson.Util.fixEmpty(imageName);
    final String effectiveEnvironment = hudson.Util.fixEmpty(environment);
    
    
    for (InspectContainerResponse inspectContainerResponse : inspectContainerResponses) {
        final Event event = new DockerEvent(effectiveStatus, inspectContainerResponse.getImageId(), 
                effectiveHostId, eventTime).toDockerEvent();
        final Info hostInfo = new DockerInfo(effectiveHostId, effectiveHostName).toInfo();

        DockerTraceabilityReport res = new DockerTraceabilityReport(event, hostInfo,
                inspectContainerResponse, 
                inspectContainerResponse.getImageId(), effectiveImageName,
                /* InspectImageResponse */ null, new LinkedList<String>(), effectiveEnvironment);
        DockerTraceabilityReportListener.fire(res);
    }
    return HttpResponses.ok();
}
 
开发者ID:jenkinsci,项目名称:docker-traceability-plugin,代码行数:55,代码来源:DockerTraceabilityRootAction.java

示例14: doSubmitReport

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
/**
 * Submits a new {@link DockerTraceabilityReport} via API.
 * @param json String representation of {@link DockerTraceabilityReport}
 * @return {@link HttpResponse}
 * @throws ServletException Servlet error
 * @throws IOException Processing error
 */
@RequirePOST
public HttpResponse doSubmitReport(@QueryParameter(required = true) String json) 
        throws IOException, ServletException { 
    checkPermission(DockerTraceabilityPlugin.SUBMIT);
    ObjectMapper mapper = new ObjectMapper();
    final DockerTraceabilityReport report = mapper.readValue(json, DockerTraceabilityReport.class);
    DockerTraceabilityReportListener.fire(report);
    return HttpResponses.ok();
}
 
开发者ID:jenkinsci,项目名称:docker-traceability-plugin,代码行数:17,代码来源:DockerTraceabilityRootAction.java

示例15: doDeleteContainer

import org.kohsuke.stapler.interceptor.RequirePOST; //导入依赖的package包/类
/**
 * Removes the container reference from the registry.
 * @param id Container ID. Method supports full 64-char IDs only.
 * @throws IOException Cannot save the updated {@link DockerTraceabilityRootAction}
 * @throws ServletException Servlet exception
 * @return response
 */
@RequirePOST
public HttpResponse doDeleteContainer(@QueryParameter(required = true) String id) 
        throws IOException, ServletException {  
    checkPermission(DockerTraceabilityPlugin.DELETE);
    removeContainerID(id);
    return HttpResponses.ok();
}
 
开发者ID:jenkinsci,项目名称:docker-traceability-plugin,代码行数:15,代码来源:DockerTraceabilityRootAction.java


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