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


Java HttpResponse类代码示例

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


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

示例1: doPost

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

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
    * Serves the testCoverage badge image. TO DO
    * @param req
    * @param rsp
    * @param job
    * @return
    */
   @SuppressWarnings("rawtypes")
public HttpResponse doTestIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job) {
       Job<?, ?> project = getProject(job);
       Integer testPass = null;
       Integer testTotal = null;

       if (project.getLastCompletedBuild() != null) {
       	AbstractTestResultAction testAction =  project.getLastCompletedBuild().getAction(AbstractTestResultAction.class);
		if(testAction != null){
			int total = testAction.getTotalCount();
			int pass = total - testAction.getFailCount() - testAction.getSkipCount();
			
			testTotal = total;
			testPass = pass;
		}
       }
       return iconResolver.getTestResultImage(testPass, testTotal);
   }
 
开发者ID:SxMShaDoW,项目名称:embeddable-badges-plugin,代码行数:26,代码来源:PublicBadgeAction.java

示例3: doBuildDescriptionIcon

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
 * Serves the Build Description badge image.
 * @param req
 * @param rsp
 * @param job
 * @return
 */
public HttpResponse doBuildDescriptionIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job) {
    Job<?, ?> project = getProject(job);
    String buildDescription = null;
    
    /*if (project.getLastSuccessfulBuild() != null) {
        buildDescription = project.getLastSuccessfulBuild().getDescription();
    }*/
    
    /*if (project.getLastBuild() != null) {
        buildDescription = project.getLastBuild().getDescription();
    }*/
    
    if (project.getLastCompletedBuild() != null) {
        buildDescription = project.getLastCompletedBuild().getDescription();
    }
    
    return iconResolver.getBuildDescriptionImage(buildDescription);
}
 
开发者ID:SxMShaDoW,项目名称:embeddable-badges-plugin,代码行数:26,代码来源:PublicBadgeAction.java

示例4: doImpersonate

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

示例5: doQueryJiraFields

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doQueryJiraFields(@QueryParameter String issueKey)
{
    try
    {
        if (!Config.getGlobalConfig().isJiraConfigComplete())
        {
            return FormValidation.error("JIRA settings are not set in global config");
        }
        final Map<String, String> jiraFields = getJiraClientSvc().getJiraFields(issueKey);
        return new ForwardToView(this, "/org/jenkinsci/plugins/jiraext/view/UpdateField/jiraFields.jelly")
                .with("jiraFieldMap", jiraFields);
    }
    catch (Throwable t)
    {
        String message =  "Error finding FieldIds for issueKey: " + issueKey;
        logger.log(Level.WARNING, message, t);
        return FormValidation.error(t, message);
    }
}
 
开发者ID:jenkinsci,项目名称:jira-ext-plugin,代码行数:20,代码来源:UpdateField.java

示例6: doProvision

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doProvision(@QueryParameter String template) throws ServletException, IOException {
    checkPermission(PROVISION);
    if (template == null) {
        throw HttpResponses.error(SC_BAD_REQUEST, "The 'template' query parameter is missing");
    }
    SlaveTemplate t = getTemplate(template);
    if (t == null) {
        throw HttpResponses.error(SC_BAD_REQUEST, "No such template: " + template);
    }

    StringWriter sw = new StringWriter();
    StreamTaskListener listener = new StreamTaskListener(sw);
    try {
        EC2AbstractSlave node = t.provision(listener);
        Hudson.getInstance().addNode(node);

        return HttpResponses.redirectViaContextPath("/computer/" + node.getNodeName());
    } catch (AmazonClientException e) {
        throw HttpResponses.error(SC_INTERNAL_SERVER_ERROR, e);
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:22,代码来源:EC2Cloud.java

示例7: doRawContainerInfo

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
 * Retrieves the latest container status via API.
 * The output will be retrieved in JSON. Supports filers. Missing 
 * &quot;since&quot; and &quot;until&quot; 
 * @param id ID of the container, for which the info should be retrieved.
 *    Short container IDs are not supported.
 * @throws IOException Processing error
 * @throws ServletException Servlet error
 * @return Raw JSON output compatible with docker inspect
 */
public HttpResponse doRawContainerInfo(@QueryParameter(required = true) String id) 
        throws IOException, ServletException {     
    checkPermission(DockerTraceabilityPlugin.READ_DETAILS);
    
    //TODO: check containerID format
    final DockerTraceabilityReport report = DockerTraceabilityHelper.getLastReport(id);
    if (report == null) {
        return HttpResponses.error(404, "No info available for the containerId=" + id);
    }
    final InspectContainerResponse inspectInfo = report.getContainer();
    if (inspectInfo == null) {
        assert false : "Input logic should reject such cases";
        return HttpResponses.error(500, "Cannot retrieve the container's status"); 
    }
    
    // Return raw JSON in the response
    InspectContainerResponse[] out = {inspectInfo};
    return toJSONResponse(out);
}
 
开发者ID:jenkinsci,项目名称:docker-traceability-plugin,代码行数:30,代码来源:DockerTraceabilityRootAction.java

示例8: do_perform

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
 *  Performs the notification on 'POST' action named "perform"
 *
 * @param req StaplerRequest
 * @param rsp StaplerResponse
 * @return HttpResponse
 */
public HttpResponse do_perform(final StaplerRequest req, final StaplerResponse rsp)  {
    // Only administrator can create a new site.
    Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);

    // TODO: display the progression

    for(ResendProjectAction resendProjectAction: resendActions){
        try {
            final NotificationHandler notifHandler = new NotificationHandler(resendProjectAction.getConfig());
            for(Map.Entry<AbstractBuild<?,?>, List<ResendBuildAction>> resendBuildAction: resendProjectAction.getResendActionPerBuild().entrySet()){
                notifHandler.send(resendBuildAction.getKey(), resendBuildAction.getValue());
            }

        } catch (Exception e ){
            GrapesPlugin.getLogger().log(Level.SEVERE, "[GRAPES] Failed to re-send notification: ", e);
        }
    }

    refresh();

    return HttpRedirect.DOT;
}
 
开发者ID:Axway,项目名称:grapes-jenkins-plugin,代码行数:30,代码来源:AdministrateResendAction.java

示例9: cors

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

示例10: doHealthcheck

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

示例11: doHealthcheckOk

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

示例12: doIndex

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

示例13: doFinishLogin

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doFinishLogin(StaplerRequest request, StaplerResponse rsp) throws IOException {

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

        if (code == null || code.trim().length() == 0) {
            Log.info("doFinishLogin: missing code.");
            return HttpResponses.redirectToContextRoot();
        }

        String content = postForAccessToken(code);

        String accessToken = extractToken(content);
        updateOfflineAccessTokenForUser(accessToken);
        request.getSession().setAttribute("access_token", accessToken);

        String newProjectSetupUrl = getJenkinsRootUrl() + "/" + GithubReposController.URL;
        return HttpResponses.redirectTo(newProjectSetupUrl);
    }
 
开发者ID:groupon,项目名称:DotCi,代码行数:19,代码来源:GithubOauthLoginAction.java

示例14: doIssue

import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
 * Generates a response containing issue data, but first logs in to YouTrack.
 *
 * @return the response.
 */
public HttpResponse doIssue() {

    return new HttpResponse() {
        public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {

            String id = req.getParameter("id");
            YouTrackSite youTrackSite = YouTrackSite.get(project);
            if (youTrackSite == null) {
                rsp.getWriter().write("YouTrack integration not set up for this project");
                return;
            }

            YouTrackServer youTrackServer = new YouTrackServer(youTrackSite.getUrl());
            User user = youTrackServer.login(youTrackSite.getUsername(), youTrackSite.getPassword());
            Issue issue = youTrackServer.getIssue(user, id);

            Gson gson = new Gson();
            String json = gson.toJson(issue);
            rsp.getWriter().write(json);
        }
    };
}
 
开发者ID:erikzielke,项目名称:youtrack-jenkins,代码行数:28,代码来源:YouTrackIssueAction.java

示例15: doPostCredential

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


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