/** * Perform a restart of Jenkins, if we can. * * This first replaces "app" to {@link HudsonIsRestarting} */ @CLIMethod(name="restart") public void doRestart(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, RestartNotSupportedException { checkPermission(ADMINISTER); if (req != null && req.getMethod().equals("GET")) { req.getView(this,"_restart.jelly").forward(req,rsp); return; } if (req == null || req.getMethod().equals("POST")) { restart(); } if (rsp != null) { rsp.sendRedirect2("."); } }
/** * Accepts the new description. */ @RequirePOST @Restricted(DoNotUse.class) public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); setDescription(req.getParameter("description")); rsp.sendRedirect("."); // go to the top page }
/** * Returns the build number in the body. */ public void doBuildNumber(StaplerResponse rsp) throws IOException { rsp.setContentType("text/plain"); rsp.setCharacterEncoding("US-ASCII"); rsp.setStatus(HttpServletResponse.SC_OK); rsp.getWriter().print(number); }
/** * Sends out an arbitrary HTML fragment as the output. */ protected void respond(StaplerResponse rsp, String html) throws IOException, ServletException { rsp.setContentType("text/html;charset=UTF-8"); rsp.getWriter().print(html); }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("text/html;charset=UTF-8"); rsp.getWriter().println("<html><body><script>" + "window.applyCompletionHandler = function (w) {" + " with(w) {" + script + " }" + "};" + "</script></body></html>"); } };
/** * For debugging. Expose URL to perform GC. */ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings("DM_GC") @RequirePOST public void doGc(StaplerResponse rsp) throws IOException { checkPermission(Jenkins.ADMINISTER); System.gc(); rsp.setStatus(HttpServletResponse.SC_OK); rsp.setContentType("text/plain"); rsp.getWriter().println("GCed"); }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); rsp.addHeader("Allow", "POST"); rsp.setContentType("text/html"); PrintWriter w = rsp.getWriter(); w.println("<html><head><title>POST required</title></head><body>"); w.println("POST is required for " + target.getQualifiedName() + "<br>"); w.println("<form method='POST'><input type='submit' value='Try POSTing'></form>"); w.println("</body></html>"); } });
String path = req.getRestOfPath(); if(path.contains("..")) throw new ServletException("Illegal path: "+path); rsp.setHeader("X-Plugin-Short-Name",pw.getShortName()); rsp.setHeader("X-Plugin-Long-Name",pw.getLongName()); rsp.setHeader("X-Plugin-From", Messages.Descriptor_From( pw.getLongName().replace("Hudson","Jenkins").replace("hudson","jenkins"), pw.getUrl())); RequestDispatcher rd = Stapler.getCurrentRequest().getView(c, "help"+path); if(rd!=null) {// template based help page rd.forward(req,rsp); return; if(url!=null) { rsp.setContentType("text/html;charset=UTF-8"); try (InputStream in = url.openStream()) { String literal = IOUtils.toString(in,"UTF-8"); rsp.getWriter().println(Util.replaceMacro(literal, Collections.singletonMap("rootURL",req.getContextPath()))); rsp.sendError(SC_NOT_FOUND);
/** * Parses trackback ping. */ public static void doTrackback( Object it, StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { String url = req.getParameter("url"); rsp.setStatus(HttpServletResponse.SC_OK); rsp.setContentType("application/xml; charset=UTF-8"); try (PrintWriter pw = rsp.getWriter()) { pw.println("<response>"); pw.println("<error>" + (url != null ? 0 : 1) + "</error>"); if (url == null) { pw.println("<message>url must be specified</message>"); } pw.println("</response>"); } }
/** * Renders a clickable map. */ public void doMap(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.checkIfModified(timestamp, rsp)) return; ChartRenderingInfo info = new ChartRenderingInfo(); render(req,info); rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().println(ChartUtilities.getImageMap( "map", info )); } }
private void _errorWithMarkup(String message, String cssClass) throws IOException, ServletException { if(message==null) { ok(); } else { response.setContentType("text/html;charset=UTF-8"); // 1x16 spacer needed for IE since it doesn't support min-height response.getWriter().print("<div class="+ cssClass +"><img src='"+ request.getContextPath()+ Jenkins.RESOURCE_PATH+"/images/none.gif' height=16 width=1>"+ message+"</div>"); } }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("text/html;charset=UTF-8"); rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); rsp.setHeader("X-Jenkins-Select-Error", selectionCleared ? "clear" : "retain"); rsp.getWriter().print(renderHtml()); }
rsp.serveExposedBean(req,bean,Flavor.XML); return; rsp.setStatus(HttpServletResponse.SC_BAD_REQUEST); rsp.getWriter().print(Messages.Api_WrapperParamInvalid()); return; rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); rsp.getWriter().print(Messages.Api_NoXPathMatch(xpath)); return; } else if (list.size() > 1) { rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); rsp.getWriter().print(Messages.Api_MultipleMatch(xpath,list.size())); return; } else { rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester"); return; try (OutputStream o = rsp.getCompressedOutputStream(req)) { if (isSimpleOutput(result)) { rsp.setContentType("text/plain;charset=UTF-8"); String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString(); o.write(text.getBytes("UTF-8")); rsp.setContentType("application/xml;charset=UTF-8"); new XMLWriter(o).write(result);
/** * Accepts and serves the job description */ public void doDescription(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { //read rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().write(Util.fixNull(this.getDescription())); return; } if (req.getMethod().equals("POST")) { checkPermission(CONFIGURE); // submission if (req.getParameter("description") != null) { this.setDescription(req.getParameter("description")); rsp.sendError(SC_NO_CONTENT); return; } } // huh? rsp.sendError(SC_BAD_REQUEST); }
public void doUpdateBuildStatConfiguration(StaplerRequest req, StaplerResponse res) throws ServletException, IOException { Hudson.getInstance().checkPermission(getRequiredPermission()); boolean regenerateId = Boolean.valueOf(req.getParameter("regenerateId")).booleanValue(); BuildStatConfiguration config = FromRequestObjectFactory.createBuildStatConfiguration(req.getParameter("buildStatId"), req); business.updateBuildStatConfiguration(req.getParameter("buildStatId"), config, regenerateId); String json = JSONObject.fromObject(config).toString(); res.getWriter().write(json); }
String pattern = req.getParameter("pattern"); if(pattern==null) pattern = req.getParameter("path"); // compatibility with Hudson<1.129 if(pattern!=null && Util.isSafeToRedirectTo(pattern)) {// avoid open redirect rsp.sendRedirect2(pattern); return; rsp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "Trying to access a file outside of the directory, target: " + base); return; rsp.setContentType("application/zip"); zip(rsp, root, baseFile, rest); return; rsp.setContentType("text/plain;charset=UTF-8"); try (OutputStream os = rsp.getOutputStream()) { for (VirtualFile kid : baseFile.list()) { os.write(kid.getName().getBytes("UTF-8")); StringBuffer reqUrl = req.getRequestURL(); if(reqUrl.charAt(reqUrl.length()-1)!='/') { rsp.sendRedirect2(reqUrl.append('/').toString()); return; rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return;
/** * Accepts the update to the node configuration. */ @RequirePOST public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException { checkPermission(CONFIGURE); String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name")); Jenkins.checkGoodName(proposedName); Node node = getNode(); if (node == null) { throw new ServletException("No such node " + nodeName); } if ((!proposedName.equals(nodeName)) && Jenkins.getActiveInstance().getNode(proposedName) != null) { throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name"); } String nExecutors = req.getSubmittedForm().getString("numExecutors"); if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) { throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors"); } Node result = node.reconfigure(req, req.getSubmittedForm()); Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result); // take the user back to the agent top page. rsp.sendRedirect2("../" + result.getNodeName() + '/'); }
/** * Standard implementation of {@link ParameterizedJob#doBuild}. */ @SuppressWarnings("deprecation") public final void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { if (delay == null) { delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(asJob().getQuietPeriod(), TimeUnit.SECONDS)); } if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable")); } // if a build is parameterized, let that take over ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (pp != null && !req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(pp, "index.jelly").forward(req, rsp); return; } hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); if (pp != null) { pp._doBuild(req, rsp, delay); return; } Queue.Item item = Jenkins.getInstance().getQueue().schedule2(asJob(), delay.getTimeInSeconds(), getBuildCause(asJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }