本文整理汇总了Java中org.kohsuke.stapler.StaplerResponse.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java StaplerResponse.setContentType方法的具体用法?Java StaplerResponse.setContentType怎么用?Java StaplerResponse.setContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kohsuke.stapler.StaplerResponse
的用法示例。
在下文中一共展示了StaplerResponse.setContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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);
}
示例3: doDeployText
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* Sends out the raw console output.
*/
public void doDeployText(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
// Prevent jelly from flushing stream so Content-Length header can be added afterwards
FlushProofOutputStream out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req));
try {
getLogText().writeLogTo(0, out);
} catch (IOException e) {
// see comment in writeLogTo() method
InputStream input = getLogInputStream();
try {
IOUtils.copy(input, out);
} finally {
IOUtils.closeQuietly(input);
}
}
out.close();
}
示例4: doLogTail
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doLogTail(final StaplerRequest req, final StaplerResponse rsp) throws IOException, ServletException {
rsp.setContentType("text/plain;charset=UTF-8");
final Joiner joiner = Joiner.on("\n");
final PlainTextConsoleOutputStream out = new PlainTextConsoleOutputStream(new FlushProofOutputStream(rsp.getCompressedOutputStream(req)));
try {
out.write(joiner.join(getLog(5000)).getBytes());
} catch (final IOException e) {
// see comment in writeLogTo() method
final InputStream input = getLogInputStream();
try {
IOUtils.copy(input, out);
} finally {
IOUtils.closeQuietly(input);
}
} finally {
IOUtils.closeQuietly(out);
}
}
示例5: doSubmit
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
// '$class' in form data tells Stapler which Fruit subclass to use,
// older versions of Jenkins/Stapler used 'stapler-class'
Fruit fruit = req.bindJSON(Fruit.class, req.getSubmittedForm().getJSONObject("fruit"));
rsp.setContentType("text/plain");
new XStream2().toXML(fruit, rsp.getWriter());
}
示例6: doPdfReport
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doPdfReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/pdf");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + PDF_REPORT_NAME);
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例7: doOsaPdfReport
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doOsaPdfReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/pdf");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + OSA_PDF_REPORT_NAME);
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例8: doOsaHtmlReport
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doOsaHtmlReport(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/html");
ServletOutputStream outputStream = rsp.getOutputStream();
File buildDirectory = owner.getRootDir();
File a = new File(buildDirectory, "/checkmarx/" + "OSAReport.html");
IOUtils.copy(a, outputStream);
outputStream.flush();
outputStream.close();
}
示例9: doIndex
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* Displays the JSON payload from GitHub. Stapler API.
*
* @param req request
* @param rsp response
* @throws IOException
*/
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("application/json;charset=UTF-8");
// Prevent jelly from flushing stream so Content-Length header can be added afterwards
try (FlushProofOutputStream out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req))) {
IOUtils.copy(getPayloadFile(), out);
}
}
示例10: jsonResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public static HttpResponse jsonResponse(final Object payload) {
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest request, StaplerResponse response, Object node) throws IOException, ServletException {
response.setContentType("application/json");
if (payload != null) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
objectMapper.writeValue(buffer, payload);
response.getOutputStream().write(buffer.toByteArray());
}
}
};
}
示例11: jsonResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public static HttpResponse jsonResponse(final CollectorRegistry collectorRegistry) {
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest request, StaplerResponse response, Object node) throws IOException, ServletException {
response.setStatus(StaplerResponse.SC_OK);
response.setContentType(TextFormat.CONTENT_TYPE_004);
StringWriter buffer = new StringWriter();
TextFormat.write004(buffer, collectorRegistry.metricFamilySamples());
buffer.close();
response.getWriter().write(buffer.toString());
}
};
}
示例12: doPollingLog
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* TODO is it secure?
*/
public void doPollingLog(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
// Prevent jelly from flushing stream so Content-Length header can be added afterwards
FlushProofOutputStream out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req));
try {
getPollingLogText().writeLogTo(0, out);
} finally {
closeQuietly(out);
}
}
示例13: toJSONResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* Serves the JSON response.
* @param item Data to be serialized to JSON
* @return HTTP response with application/json MIME type
*/
private static HttpResponse toJSONResponse(final Object item) {
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
ObjectMapper mapper = new ObjectMapper();
rsp.setContentType("application/json;charset=UTF-8");
mapper.writeValue(rsp.getWriter(), item);
}
};
}
示例14: generateResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@Override
public void generateResponse(StaplerRequest req,
StaplerResponse rsp,
Object o) throws IOException, ServletException {
rsp.setStatus(status);
rsp.setContentType("application/json");
rsp.getWriter().println(json);
}
示例15: writeBody
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
private void writeBody(StaplerResponse response, JSONObject body) throws IOException {
response.setContentType("application/json");
PrintWriter writer = response.getWriter();
writer.write(body.toString());
writer.flush();
writer.close();
}