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


Java StaplerResponse类代码示例

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


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

示例1: doEndOfflineAgentJobs

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
public void doEndOfflineAgentJobs(final StaplerRequest request, final StaplerResponse response) {

		Jenkins j;
		if ((j = Jenkins.getInstance()) != null) {
			Queue queue = j.getQueue();
			if (queue != null) {
				for (Item job : queue.getItems()) {
					if (job.getCauseOfBlockage() instanceof BecauseNodeIsOffline
							|| job.getCauseOfBlockage() instanceof BecauseLabelIsOffline) {
						queue.cancel(job);
					}
				}
			}
		}

		try {
			response.sendRedirect2(request.getRootPath());
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
开发者ID:jenkinsci,项目名称:no-agent-job-purge-plugin,代码行数:22,代码来源:PurgeNoAgentJobs.java

示例2: doTestIcon

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

示例5: plotGraph

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
/**
 * Generates and writes the plotpipeline to the response output stream.
 *
 * @param req
 *            the incoming request
 * @param rsp
 *            the response stream
 * @throws IOException
 */
public void plotGraph(StaplerRequest req, StaplerResponse rsp)
        throws IOException {
    if ( ChartUtil.awtProblemCause != null) {
        // Not available. Send out error message.
        rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
        return;
    }
    setWidth(req);
    setHeight(req);
    setNumBuilds(req);
    setRightBuildNum(req);
    setHasLegend(req);
    setTitle(req);
    setStyle(req);
    setUseDescr(req);
    // need to force regenerate the plotpipeline in case build
    // descriptions (used for tool tips) have changed
    generatePlot(true);
    ChartUtil.generateGraph(req, rsp, plot, getWidth(), getHeight());
}
 
开发者ID:MarkusDNC,项目名称:plot-plugin,代码行数:30,代码来源:Plot.java

示例6: plotGraphMap

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
/**
 * Generates and writes the plotpipeline's clickable map to the response output
 * stream.
 *
 * @param req
 *            the incoming request
 * @param rsp
 *            the response stream
 * @throws IOException
 */
public void plotGraphMap(StaplerRequest req, StaplerResponse rsp)
        throws IOException {
    if ( ChartUtil.awtProblemCause != null) {
        // not available. send out error message
        rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
        return;
    }
    setWidth(req);
    setHeight(req);
    setNumBuilds(req);
    setRightBuildNum(req);
    setHasLegend(req);
    setTitle(req);
    setStyle(req);
    setUseDescr(req);
    generatePlot(false);
    ChartRenderingInfo info = new ChartRenderingInfo();
    plot.createBufferedImage(getWidth(), getHeight(), info);
    rsp.setContentType("text/plain;charset=UTF-8");
    rsp.getWriter().println(
            ChartUtilities.getImageMap(getCsvFileName(), info));
}
 
开发者ID:MarkusDNC,项目名称:plot-plugin,代码行数:33,代码来源:Plot.java

示例7: whenEmptyHeaderTypeMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenEmptyHeaderTypeMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);

    //perform the test
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(403);

    String expectedOutput = "Only push event can be accepted.";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:20,代码来源:GogsWebHookTest.java

示例8: whenWrongHeaderTypeMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenWrongHeaderTypeMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("junk");

    //perform the testÎ
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(403);

    String expectedOutput = "Only push event can be accepted.";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:21,代码来源:GogsWebHookTest.java

示例9: whenQueryStringIsNullMustThrowException

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenQueryStringIsNullMustThrowException() throws Exception {
    //Prepare the SUT
    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("push");
    when(staplerRequest.getQueryString()).thenReturn(null);
    GogsWebHook gogsWebHook = new GogsWebHook();


    try {
        gogsWebHook.doIndex(staplerRequest, staplerResponse);
    } catch (NullPointerException e) {
        String expectedErrMsg = "The queryString in the request is null";
        assertEquals("Not the expected error message.", expectedErrMsg, e.getMessage());
        log.info("call failed as expected.");
        return;
    }
    fail("The call should have failed.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:21,代码来源:GogsWebHookTest.java

示例10: whenNoJobInQueryStringMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenNoJobInQueryStringMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("push");
    when(staplerRequest.getQueryString()).thenReturn("foo=bar&blaah=blaah");

    //perform the testÎ
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(404);

    String expectedOutput = "Parameter 'job' is missing.";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:22,代码来源:GogsWebHookTest.java

示例11: whenEmptyJobInQueryStringMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenEmptyJobInQueryStringMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("push");
    when(staplerRequest.getQueryString()).thenReturn("job&foo=bar");

    //perform the testÎ
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(404);

    String expectedOutput = "No value assigned to parameter 'job'";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:22,代码来源:GogsWebHookTest.java

示例12: whenEmptyJob2InQueryStringMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenEmptyJob2InQueryStringMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("push");
    when(staplerRequest.getQueryString()).thenReturn("job=&foo=bar");

    //perform the testÎ
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(404);

    String expectedOutput = "No value assigned to parameter 'job'";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:22,代码来源:GogsWebHookTest.java

示例13: whenUriDoesNotContainUrlNameMustReturnError

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
@Test
public void whenUriDoesNotContainUrlNameMustReturnError() throws Exception {
    //Prepare the SUT
    File uniqueFile = File.createTempFile("webHookTest_", ".txt", new File("target"));

    StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
    StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
    when(staplerRequest.getHeader("X-Gogs-Event")).thenReturn("push");
    when(staplerRequest.getQueryString()).thenReturn("job=myJob");


    MockServletInputStream inputStream = new MockServletInputStream("body");
    when(staplerRequest.getInputStream()).thenReturn(inputStream);
    when(staplerRequest.getRequestURI()).thenReturn("/badUri/aaa");

    //perform the testÎ
    performDoIndexTest(staplerRequest, staplerResponse, uniqueFile);

    //validate that everything was done as planed
    verify(staplerResponse).setStatus(404);

    String expectedOutput = "No payload or URI contains invalid entries.";
    isExpectedOutput(uniqueFile, expectedOutput);

    log.info("Test succeeded.");
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:27,代码来源:GogsWebHookTest.java

示例14: doDynamic

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    // Relax the Content Security Policy
    System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "");
    System.setProperty("jenkins.model.DirectoryBrowserSupport.CSP", "");

    DirectoryBrowserSupport dbs = new DirectoryBrowserSupport(this, new FilePath(this.dir()), this.getTitle(), getUrlName(), false);
    File report = new File(dir(), DONUT_REPORT_FILENAME);

    if (!report.exists()) {
        rsp.sendRedirect(Functions.getResourcePath() + "/plugin/donut-jenkins-plugin/error.html");
        return;
    }

    dbs.setIndexFileName(DONUT_REPORT_FILENAME);
    dbs.generateResponse(req, rsp, this);
}
 
开发者ID:DonutReport,项目名称:donut-jenkins-plugin,代码行数:17,代码来源:DonutAction.java

示例15: doIndex

import org.kohsuke.stapler.StaplerResponse; //导入依赖的package包/类
/**
 * Used by Jenkins Stapler service when get request on URL jenkins_host/getUrlName()
 *
 * @param request - request
 * @param response - response
 * @throws IOException
 */
@SuppressWarnings("unused")
public void doIndex(StaplerRequest request, StaplerResponse response) throws IOException {
    final float coverage = Float.parseFloat(request.getParameter("coverage"));
    final float masterCoverage = Float.parseFloat(request.getParameter("masterCoverage"));

    response.setContentType("image/svg+xml");

    String svg = IOUtils.toString(this.getClass().getResourceAsStream(
            "/com/github/terma/jenkins/githubprcoveragestatus/Icon/icon.svg"));

    final Message message = new Message(coverage, masterCoverage);
    svg = StringUtils.replace(svg, "{{ message }}", message.forIcon());

    final int coveragePercent = Percent.of(coverage);
    String color;
    if (coveragePercent < Configuration.getYellowThreshold()) color = "#b94947"; // red
    else if (coveragePercent < Configuration.getGreenThreshold()) color = "#F89406"; // yellow
    else color = "#97CA00"; // green
    svg = StringUtils.replace(svg, "{{ color }}", color);

    response.getWriter().write(svg);
}
 
开发者ID:terma,项目名称:github-pr-coverage-status,代码行数:30,代码来源:CoverageStatusIconAction.java


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