org.kohsuke.stapler.StaplerRequest类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.kohsuke.stapler.StaplerRequest类的一些代码示例,展示了StaplerRequest类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StaplerRequest类的具体详情如下:
包路径:org.kohsuke.stapler.StaplerRequest
类名称:StaplerRequest

StaplerRequest介绍

[英]Defines additional parameters/operations made available by Stapler.
[中]定义订书机提供的其他参数/操作。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException {
    // for compatibility reasons, the actual value is stored in Jenkins
    Jenkins j = Jenkins.get();
    final JSONObject optJSONObject = json.optJSONObject("useProjectNamingStrategy");
    if (optJSONObject != null) {
      final JSONObject strategyObject = optJSONObject.getJSONObject("namingStrategy");
      final String className = strategyObject.getString("$class");
      try {
        Class clazz = Class.forName(className, true, j.getPluginManager().uberClassLoader);
        final ProjectNamingStrategy strategy = (ProjectNamingStrategy) req.bindJSON(clazz, strategyObject);
        j.setProjectNamingStrategy(strategy);
      } catch (ClassNotFoundException e) {
        throw new FormException(e, "namingStrategy");
      }
    }
    if (j.getProjectNamingStrategy() == null) {
      j.setProjectNamingStrategy(DefaultProjectNamingStrategy.DEFAULT_NAMING_STRATEGY);
    }
    return true;
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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>");
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
  String proxiedViewName = req.getSubmittedForm().getString("proxiedViewName");
  if (Jenkins.getInstance().getView(proxiedViewName) == null) {
    throw new FormException("Not an existing global view", "proxiedViewName");
  }
  this.proxiedViewName = proxiedViewName;
}

代码示例来源:origin: jenkinsci/jenkins

private boolean needToAddToCurrentView(StaplerRequest req) throws ServletException {
  String json = req.getParameter("json");
  if (json != null && json.length() > 0) {
    // Submitted via UI
    JSONObject form = req.getSubmittedForm();
    return form.has("addToCurrentView") && form.getBoolean("addToCurrentView");
  } else {
    // Submitted via API
    return true;
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Depending on whether the user said "yes" or "no", send him to the right place.
 */
@RequirePOST
public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException {
  if(req.hasParameter("no")) {
    disable(true);
    rsp.sendRedirect(req.getContextPath()+"/manage");
  } else {
    rsp.sendRedirect(req.getContextPath()+"/newView");
  }
}

代码示例来源:origin: jenkinsci/jenkins

public void doCommand(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
  final Jenkins jenkins = Jenkins.getActiveInstance();
  jenkins.checkPermission(Jenkins.READ);
  // Strip trailing slash
  final String commandName = req.getRestOfPath().substring(1);
  CLICommand command = CLICommand.clone(commandName);
  if (command == null) {
    rsp.sendError(HttpServletResponse.SC_NOT_FOUND, "No such command");
    return;
  }
  req.setAttribute("command", command);
  req.getView(this, "command.jelly").forward(req, rsp);
}

代码示例来源:origin: jenkinsci/jenkins

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>");
  }
}

代码示例来源:origin: jenkinsci/jenkins

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;
    try (InputStream in = url.openStream()) {
      String literal = IOUtils.toString(in,"UTF-8");
      rsp.getWriter().println(Util.replaceMacro(literal, Collections.singletonMap("rootURL",req.getContextPath())));

代码示例来源:origin: org.jenkins-ci.plugins/github-branch-source

@Override
  public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node)
      throws IOException, ServletException {
    rsp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    rsp.setContentType("text/html;charset=UTF-8");
    rsp.setHeader("X-Jenkins-Select-Error", clearList ? "clear" : "retain");
    rsp.getWriter().print(
        "<div class=\'error\'><img src=\'" + req.getContextPath()
            + Jenkins.RESOURCE_PATH + "/images/none.gif\' height=16 width=1>" + Util.escape(getMessage()) +
            "</div>");

  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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);
}

代码示例来源:origin: org.jenkins-ci.plugins/global-build-stats

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);
}

代码示例来源:origin: jenkinsci/jenkins

public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
    rsp.setStatus(SC_SERVICE_UNAVAILABLE);
    req.getView(this,"index.jelly").forward(req,rsp);
  }
}

代码示例来源:origin: jenkinsci/jenkins

public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
  List<Ancestor> l = req.getAncestors();
  for( int i=l.size()-1; i>=0; i-- ) {
    Ancestor a = l.get(i);
    if (a.getObject() instanceof SearchableModelObject) {
      SearchableModelObject smo = (SearchableModelObject) a.getObject();
      if(LOGGER.isLoggable(Level.FINE)){
        LOGGER.fine(String.format("smo.displayName=%s, searchName=%s",smo.getDisplayName(), smo.getSearchName()));
      }
      SearchIndex index = smo.getSearchIndex();
      String query = req.getParameter("q");
      if(query!=null) {
        SuggestedItem target = find(index, query, smo);
        if(target!=null) {
          // found
          rsp.sendRedirect2(req.getContextPath()+target.getUrl());
          return;
        }
      }
    }
  }
  // no exact match. show the suggestions
  rsp.setStatus(SC_NOT_FOUND);
  req.getView(this,"search-failed.jelly").forward(req,rsp);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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(".");
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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(".");
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Deletes the build when the button is pressed.
 */
@RequirePOST
public void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  checkPermission(DELETE);
  // We should not simply delete the build if it has been explicitly
  // marked to be preserved, or if the build should not be deleted
  // due to dependencies!
  String why = getWhyKeepLog();
  if (why!=null) {
    sendError(Messages.Run_UnableToDelete(getFullDisplayName(), why), req, rsp);
    return;
  }
  try{
    delete();
  }
  catch(IOException ex){
    req.setAttribute("stackTraces", Functions.printThrowable(ex));
    req.getView(this, "delete-retry.jelly").forward(req, rsp);  
    return;
  }
  rsp.sendRedirect2(req.getContextPath()+'/' + getParent().getUrl());
}

代码示例来源:origin: jenkinsci/jenkins

JSONObject formData = req.getSubmittedForm();
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
  String name = jo.getString("name");
WaitingItem item = Jenkins.getInstance().getQueue().schedule(
    getJob(), delay.getTimeInSeconds(), new ParametersAction(values), new CauseAction(new Cause.UserIdCause()));
if (item!=null) {
  String url = formData.optString("redirectTo");
  if (url==null || !Util.isSafeToRedirectTo(url))   // avoid open redirect
    url = req.getContextPath()+'/'+item.getUrl();
  rsp.sendRedirect(formData.optInt("statusCode",SC_CREATED), url);
} else
  rsp.sendRedirect(".");

代码示例来源:origin: jenkinsci/jenkins

@RequirePOST
@Override
public void doLaunchSlaveAgent(StaplerRequest req, StaplerResponse rsp) throws IOException {
  checkPermission(CONNECT);
    
  if(channel!=null) {
    try {
      req.getView(this, "already-launched.jelly").forward(req, rsp);
    } catch (IOException x) {
      throw x;
    } catch (/*Servlet*/Exception x) {
      throw new IOException(x);
    }
    return;
  }
  connect(true);
  // TODO: would be nice to redirect the user to "launching..." wait page,
  // then spend a few seconds there and poll for the completion periodically.
  rsp.sendRedirect("log");
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Handles the form submission from the "/computer/new" page, which is the first form for creating a new node.
 * By default, it shows the configuration page for entering details, but subtypes can override this differently.
 *
 * @param name
 *      Name of the new node.
 */
public void handleNewNodePage(ComputerSet computerSet, String name, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
  computerSet.checkName(name);
  req.setAttribute("descriptor", this);
  req.getView(computerSet,"_new.jelly").forward(req,rsp);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Sign up for the user account.
 */
public void doSignup( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  if (getSecurityRealm().allowsSignup()) {
    req.getView(getSecurityRealm(), "signup.jelly").forward(req, rsp);
    return;
  }
  req.getView(SecurityRealm.class, "signup.jelly").forward(req, rsp);
}

相关文章

微信公众号

最新文章

更多

StaplerRequest类方法