/** * {@inheritDoc} */ @Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { byte[] bytes = jsonObject.toString().getBytes(UTF8); rsp.setContentType("application/json; charset=UTF-8"); rsp.setContentLength(bytes.length); rsp.getOutputStream().write(bytes); } }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("application/xml"); View.this.writeXml(rsp.getOutputStream()); } };
public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required, Permission permission) throws IOException, ServletException { // this is legacy --- all views should be eventually converted to // the permission based model. if(required!=null && !Hudson.adminCheck(req, rsp)) { // check failed. commit the FORBIDDEN response, then abort. rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); rsp.getOutputStream().close(); throw new ServletException("Unauthorized access"); } // make sure the user owns the necessary permission to access this page. if(permission!=null) checkPermission(permission); }
OutputStream out = rsp.getOutputStream(); if (DIY_CHUNKING) { out = new ChunkedOutputStream(out);
/** * Generate schema. */ public void doSchema(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { setHeaders(rsp); rsp.setContentType("application/xml"); StreamResult r = new StreamResult(rsp.getOutputStream()); new SchemaGenerator(new ModelBuilder().get(bean.getClass())).generateSchema(r); r.getOutputStream().close(); }
res.getOutputStream().write(iv); res.getOutputStream().write(encrypted); } else { it.checkPermission(connectPermission);
/** * Generates a captcha image. */ public final void doCaptcha(StaplerRequest req, StaplerResponse rsp) throws IOException { if (captchaSupport != null) { String id = req.getSession().getId(); rsp.setContentType("image/png"); // source: https://stackoverflow.com/a/3414217 rsp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); rsp.setHeader("Pragma", "no-cache"); rsp.setHeader("Expires", "0"); captchaSupport.generateImage(id, rsp.getOutputStream()); } }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { // read rsp.setContentType("application/xml"); writeConfigDotXml(rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml((Source)new StreamSource(req.getReader())); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
BufferedImage image = render(req,null); rsp.setContentType("image/png"); ServletOutputStream os = rsp.getOutputStream(); ImageIO.write(image, "PNG", os); os.close();
private static void zip(StaplerResponse rsp, VirtualFile root, VirtualFile dir, String glob) throws IOException, InterruptedException { OutputStream outputStream = rsp.getOutputStream(); try (ZipOutputStream zos = new ZipOutputStream(outputStream)) { zos.setEncoding(System.getProperty("file.encoding")); // TODO JENKINS-20663 make this overridable via query parameter
@Override protected void writeStatusBody(StaplerResponse response, Run<?, ?> build, BuildStatus status) { try { response.setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT"); response.setHeader("Cache-Control", "no-cache, private"); response.setHeader("Content-Type", "image/png"); IOUtils.copy(getStatusImage(status), response.getOutputStream()); response.flushBuffer(); } catch (Exception e) { throw HttpResponses.error(500, "Could not generate response."); } }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (req.getMethod().equals("GET")) { // read checkPermission(EXTENDED_READ); rsp.setContentType("application/xml"); Node node = getNode(); if (node == null) { throw HttpResponses.notFound(); } Jenkins.XSTREAM2.toXMLUTF8(node, rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml(req.getInputStream()); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
try (OutputStream os = rsp.getOutputStream()) { for (VirtualFile kid : baseFile.list()) { os.write(kid.getName().getBytes("UTF-8"));
/** * Export live jenkins instance configuration as Yaml * @throws Exception */ @RequirePOST public void doExport(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { res.sendError(HttpServletResponse.SC_FORBIDDEN); return; } res.setContentType("application/x-yaml; charset=utf-8"); res.addHeader("Content-Disposition", "attachment; filename=jenkins.yaml"); export(res.getOutputStream()); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_DEFAULT_ENCODING") public void doIndex(StaplerResponse rsp) throws IOException { Process p = new ProcessBuilder("dot", "-Tpng").start(); writeDot(new PrintWriter(p.getOutputStream())); rsp.setContentType("image/png"); IOUtils.copy(p.getInputStream(), rsp.getOutputStream()); }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("application/xml"); View.this.writeXml(rsp.getOutputStream()); } };
public void doListViews(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Hudson.getInstance().createLauncher(TaskListener.NULL).launch().cmds(getCleartoolExe(), "lsview", "-short").stdout(baos).join(); rsp.setContentType("text/plain"); rsp.getOutputStream().println("ClearCase Views found:\n"); baos.writeTo(rsp.getOutputStream()); }
/** * Generates a captcha image. */ public final void doCaptcha(StaplerRequest req, StaplerResponse rsp) throws IOException { if (captchaSupport != null) { String id = req.getSession().getId(); rsp.setContentType("image/png"); rsp.addHeader("Cache-Control", "no-cache"); captchaSupport.generateImage(id, rsp.getOutputStream()); } }
/** * Generate schema. */ public void doSchema(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { rsp.setContentType("application/xml"); StreamResult r = new StreamResult(rsp.getOutputStream()); new SchemaGenerator(new ModelBuilder().get(bean.getClass())).generateSchema(r); r.getOutputStream().close(); }
/** * Generate schema. */ public void doSchema(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { setHeaders(rsp); rsp.setContentType("application/xml"); StreamResult r = new StreamResult(rsp.getOutputStream()); new SchemaGenerator(new ModelBuilder().get(bean.getClass())).generateSchema(r); r.getOutputStream().close(); }