jenkins.model.Jenkins.getRootUrlFromRequest()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(154)

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

Jenkins.getRootUrlFromRequest介绍

[英]Gets the absolute URL of Jenkins top page, such as http://localhost/jenkins/.

Unlike #getRootUrl(), which uses the manually configured value, this one uses the current request to reconstruct the URL. The benefit is that this is immune to the configuration mistake (users often fail to set the root URL correctly, especially when a migration is involved), but the downside is that unless you are processing a request, this method doesn't work.

Please note that this will not work in all cases if Jenkins is running behind a reverse proxy which has not been fully configured. Specifically the Host and X-Forwarded-Proto headers must be set. Running Jenkins behind Apache shows some examples of configuration.
[中]获取Jenkins首页的绝对URL,例如http://localhost/jenkins/.
与使用手动配置的值的#getRootUrl()不同,这个函数使用当前请求来重建URL。这样做的好处是不受配置错误的影响(用户通常无法正确设置根URL,尤其是在涉及迁移时),但缺点是,除非您正在处理请求,否则此方法不起作用。
请注意,如果Jenkins在未完全配置的反向代理后运行,则这不会在所有情况下都起作用。特别是必须设置主机和X-Forwarded-Proto头。Running Jenkins behind Apache显示了一些配置示例。

代码示例

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

@StaplerDispatchable
public void getTestForReverseProxySetup(String rest) {
  Jenkins j = Jenkins.getInstance();
  String inferred = j.getRootUrlFromRequest() + "manage";
  // TODO this could also verify that j.getRootUrl() has been properly configured, and send a different message if not
  if (rest.startsWith(inferred)) { // not using equals due to JENKINS-24014
    throw HttpResponses.ok();
  } else {
    LOGGER.log(Level.WARNING, "{0} vs. {1}", new Object[] {inferred, rest});
    throw HttpResponses.errorWithoutStack(404, inferred + " vs. " + rest);
  }
}

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

return getRootUrlFromRequest();
return null;

代码示例来源:origin: jenkinsci/scm-sync-configuration-plugin

public PageMatcher getPageMatcherMatching(String url){
  String rootUrl = Jenkins.getInstance().getRootUrlFromRequest();
  String cleanedUrl = null;
  if(url.startsWith(rootUrl)){
    cleanedUrl = url.substring(rootUrl.length());
  } else {
    cleanedUrl = url;
  }
  for(PageMatcher pm : pageMatchers){
    if(pm.getUrlRegex().matcher(cleanedUrl).matches()){
      return pm;
    }
  }
  return null;
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
 * Exposes our URL (as we will be invoked from an unknown page so we need an absolute URL).
 *
 * @return our URL.
 */
public String getUrl() {
  return String.format(
      "%sdescriptor/%s/resolver/%s/provider/%s/context/%s",
      Jenkins.getActiveInstance().getRootUrlFromRequest(),
      CredentialsSelectHelper.class.getName(),
      Util.rawEncode(resolver.getClass().getName()),
      Util.rawEncode(provider.getClass().getName()),
      Util.rawEncode(token)
  );
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public void getTestForReverseProxySetup(String rest) {
  Jenkins j = Jenkins.getInstance();
  String inferred = j.getRootUrlFromRequest() + "manage";
  // TODO this could also verify that j.getRootUrl() has been properly configured, and send a different message if not
  if (rest.startsWith(inferred)) { // not using equals due to JENKINS-24014
    throw HttpResponses.ok();
  } else {
    LOGGER.log(Level.WARNING, "{0} vs. {1}", new Object[] {inferred, rest});
    throw HttpResponses.errorWithoutStack(404, inferred + " vs. " + rest);
  }
}

代码示例来源:origin: jenkinsci/credentials-plugin

/**
 * Exposes our URL (as we will be invoked from an unknown page so we need an absolute URL).
 *
 * @return our URL.
 */
public String getUrl() {
  return String.format(
      "%sdescriptor/%s/resolver/%s/provider/%s/context/%s",
      Jenkins.getActiveInstance().getRootUrlFromRequest(),
      CredentialsSelectHelper.class.getName(),
      Util.rawEncode(resolver.getClass().getName()),
      Util.rawEncode(provider.getClass().getName()),
      Util.rawEncode(token)
  );
}

代码示例来源:origin: hudson.plugins/project-inheritance

public void doLeaveCreationResult() {
  //Redirect back to the central managment page
  try {
    Jenkins j = Jenkins.getInstance();
    String rootURL = j.getRootUrlFromRequest();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    rsp.sendRedirect(rootURL + "/manage");
  } catch (IOException ex) {
    //Ignore
  } catch (NullPointerException ex) {
    //Ignore
  }
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
 * Gets the check id url for the specified store.
 *
 * @param store the store.
 * @return the url of the id check endpoint.
 * @throws UnsupportedEncodingException if the JVM does not implement the JLS.
 */
public String getCheckIdUrl(CredentialsStore store) throws UnsupportedEncodingException {
  ModelObject context = store.getContext();
  for (ContextResolver r : ExtensionList.lookup(ContextResolver.class)) {
    String token = r.getToken(context);
    if (token != null) {
      return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl()
          + "/checkId?provider=" + r.getClass().getName() + "&token="
          + URLEncoder.encode(token, "UTF-8");
    }
  }
  return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl()
      + "/checkId?provider=null&token=null";
}

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

public void doLeaveCreationResult() {
  //Redirect back to the central management page
  try {
    Jenkins j = Jenkins.getInstance();
    String rootURL = j.getRootUrlFromRequest();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    rsp.sendRedirect(rootURL + "/manage");
  } catch (IOException ex) {
    //Ignore
  } catch (NullPointerException ex) {
    //Ignore
  }
}

代码示例来源:origin: jenkinsci/credentials-plugin

/**
 * Gets the check id url for the specified store.
 *
 * @param store the store.
 * @return the url of the id check endpoint.
 * @throws UnsupportedEncodingException if the JVM does not implement the JLS.
 */
public String getCheckIdUrl(CredentialsStore store) throws UnsupportedEncodingException {
  ModelObject context = store.getContext();
  for (ContextResolver r : ExtensionList.lookup(ContextResolver.class)) {
    String token = r.getToken(context);
    if (token != null) {
      return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl()
          + "/checkId?provider=" + r.getClass().getName() + "&token="
          + URLEncoder.encode(token, "UTF-8");
    }
  }
  return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl()
      + "/checkId?provider=null&token=null";
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

return getRootUrlFromRequest();
return null;

代码示例来源:origin: hudson.plugins/project-inheritance

/**
 * This starts the job creation and redirects the user to the result page.
 * <p>
 * <b>Do NOT call this directly</b>, if not triggered by the user. Instead
 * call {@link #triggerCreateProjects()}.
 */
public void doCreateProjects() {
  //Trigger the project creation
  this.lastCreationState = this.triggerCreateProjects();
  
  Jenkins j = Jenkins.getInstance();
  String rootURL = j.getRootUrlFromRequest();
  
  //Redirect to the status page for job creation
  try {
    StaplerResponse rsp = Stapler.getCurrentResponse();
    rsp.sendRedirect(rootURL + "/project_creation/showCreationResults");
  } catch (IOException ex) {
    //Ignore
  } catch (NullPointerException ex) {
    //Ignore
  }
}

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

/**
 * This starts the job creation and redirects the user to the result page.
 * <p>
 * <b>Do NOT call this directly</b>, if not triggered by the user. Instead
 * call {@link #triggerCreateProjects()}.
 */
public void doCreateProjects() {
  //Trigger the project creation
  this.lastCreationState = this.triggerCreateProjects();
  
  Jenkins j = Jenkins.getInstance();
  String rootURL = j.getRootUrlFromRequest();
  
  //Redirect to the status page for job creation
  try {
    StaplerResponse rsp = Stapler.getCurrentResponse();
    rsp.sendRedirect(rootURL + "/project_creation/showCreationResults");
  } catch (IOException ex) {
    //Ignore
  } catch (NullPointerException ex) {
    //Ignore
  }
}

代码示例来源:origin: jenkinsci/fitnesse-plugin

private void generateUrl() {
  Run<?,?> build = o.getRun();
  String buildLink = build.getUrl();
  String actionUrl = o.getTestResultAction().getUrlName();
  this.url = Jenkins.getActiveInstance().getRootUrlFromRequest() + buildLink + actionUrl + o.getUrl();
}

相关文章

Jenkins类方法