本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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));
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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);
}
示例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);
}