Ejemplo n.º 1
0
  /** Accepts <tt>config.xml</tt> submission, as well as serve it. */
  @WebMethod(name = "config.xml")
  public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException {
    checkPermission(Jenkins.ADMINISTER);
    if (req.getMethod().equals("GET")) {
      // read
      rsp.setContentType("application/xml");
      Jenkins.XSTREAM2.toXML(getNode(), rsp.getOutputStream());
      return;
    }
    if (req.getMethod().equals("POST")) {
      // submission
      Node result = (Node) Jenkins.XSTREAM2.fromXML(req.getReader());

      replaceBy(result);
      return;
    }

    // huh?
    rsp.sendError(SC_BAD_REQUEST);
  }
  /**
   * Action when 'restore' button is pressed: Replace current config file by older version.
   *
   * @param req Incoming StaplerRequest
   * @param rsp Outgoing StaplerResponse
   * @throws IOException If something goes wrong
   */
  public final void doRestore(StaplerRequest req, StaplerResponse rsp) throws IOException {
    checkConfigurePermission();
    final String timestamp = req.getParameter("timestamp");

    final XmlFile xmlFile = getHistoryDao().getOldRevision(slave, timestamp);
    final Slave newSlave = (Slave) Jenkins.XSTREAM2.fromXML(xmlFile.getFile());
    final List<Node> nodes = new ArrayList<Node>();
    nodes.addAll(hudson.getNodes());
    nodes.remove(slave);
    nodes.add(newSlave);
    slave = newSlave;
    hudson.setNodes(nodes);
    rsp.sendRedirect(getHudson().getRootUrl() + slave.toComputer().getUrl());
  }