org.kohsuke.stapler.StaplerRequest.getServerName()方法的使用及代码示例

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

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

StaplerRequest.getServerName介绍

暂无

代码示例

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

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Jenkins.getInstance().getRootUrl();
  if(rootUrl !=null)
    // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
    return rootUrl;
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if(! (req.getScheme().equals("http") && req.getLocalPort()==80 || req.getScheme().equals("https") && req.getLocalPort()==443))
    buf.append(':').append(req.getLocalPort());
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

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

/**
 * Obtains the host name of the Hudson server that clients can use to talk back to.
 * <p>
 * This is primarily used in {@code slave-agent.jnlp.jelly} to specify the destination
 * that the agents talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Jenkins.getInstance().getRootUrl();
  try {
    if(url!=null) {
      String host = new URL(url).getHost();
      if(host!=null)
        return host;
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

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

String scheme = getXForwardedHeader(req, "X-Forwarded-Proto", req.getScheme());
buf.append(scheme).append("://");
String host = getXForwardedHeader(req, "X-Forwarded-Host", req.getServerName());
int index = host.indexOf(':');
int port = req.getServerPort();

代码示例来源:origin: org.kohsuke.stapler/stapler

public String getFullUrl() {
  StringBuilder buf = new StringBuilder();
  StaplerRequest req = Stapler.getCurrentRequest();
  buf.append(req.getScheme());
  buf.append("://");
  buf.append(req.getServerName());
  if(req.getServerPort()!=80)
    buf.append(':').append(req.getServerPort());
  buf.append(getUrl());
  return buf.toString();
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

public String getFullUrl() {
  StringBuilder buf = new StringBuilder();
  StaplerRequest req = Stapler.getCurrentRequest();
  buf.append(req.getScheme());
  buf.append("://");
  buf.append(req.getServerName());
  if(req.getServerPort()!=80)
    buf.append(':').append(req.getServerPort());
  buf.append(getUrl());
  return buf.toString();
}

代码示例来源:origin: stapler/stapler

public String getFullUrl() {
  StringBuilder buf = new StringBuilder();
  StaplerRequest req = Stapler.getCurrentRequest();
  buf.append(req.getScheme());
  buf.append("://");
  buf.append(req.getServerName());
  if(req.getServerPort()!=80)
    buf.append(':').append(req.getServerPort());
  buf.append(getUrl());
  return buf.toString();
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Hudson.getInstance().getRootUrl();
  if(rootUrl !=null)
    // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
    return rootUrl;
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if(req.getLocalPort()!=80)
    buf.append(':').append(req.getLocalPort());
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Hudson.getInstance().getRootUrl();
  if (rootUrl != null) // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
  {
    return rootUrl;
  }
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if (req.getLocalPort() != 80) {
    buf.append(':').append(req.getLocalPort());
  }
  buf.append(getRequestRootPath(req)).append('/');
  return buf.toString();
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Hudson.getInstance().getRootUrl();
  if(rootUrl !=null)
    // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
    return rootUrl;
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if(req.getLocalPort()!=80)
    buf.append(':').append(req.getLocalPort());
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Hudson.getInstance().getRootUrl();
  if(rootUrl !=null)
    // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
    return rootUrl;
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if(req.getLocalPort()!=80)
    buf.append(':').append(req.getLocalPort());
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Gets the absolute URL of Hudson top page, such as "http://localhost/hudson/".
 *
 * <p>
 * Unlike {@link #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.
 *
 * @since 1.263
 */
public String getRootUrlFromRequest() {
  StaplerRequest req = Stapler.getCurrentRequest();
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme() + "://");
  buf.append(req.getServerName());
  if (req.getServerPort() != 80) {
    buf.append(':').append(req.getServerPort());
  }
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

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

/**
 * Infers the hudson installation URL from the given request.
 */
public static String inferHudsonURL(StaplerRequest req) {
  String rootUrl = Jenkins.getInstance().getRootUrl();
  if(rootUrl !=null)
    // prefer the one explicitly configured, to work with load-balancer, frontend, etc.
    return rootUrl;
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme()).append("://");
  buf.append(req.getServerName());
  if(! (req.getScheme().equals("http") && req.getLocalPort()==80 || req.getScheme().equals("https") && req.getLocalPort()==443))
    buf.append(':').append(req.getLocalPort());
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Gets the absolute URL of Hudson top page, such as "http://localhost/hudson/".
 *
 * <p>
 * Unlike {@link #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.
 *
 * @since 1.263
 */
public String getRootUrlFromRequest() {
  StaplerRequest req = Stapler.getCurrentRequest();
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme() + "://");
  buf.append(req.getServerName());
  if (req.getServerPort() != 80) {
    buf.append(':').append(req.getServerPort());
  }
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

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

/**
 * Obtains the host name of the Hudson server that clients can use to talk back to.
 * <p>
 * This is primarily used in <tt>slave-agent.jnlp.jelly</tt> to specify the destination
 * that the agents talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Jenkins.getInstance().getRootUrl();
  try {
    if(url!=null) {
      String host = new URL(url).getHost();
      if(host!=null)
        return host;
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Obtains the host name of the Hudson server that clients can use to talk back to.
 * <p>
 * This is primarily used in <tt>slave-agent.jnlp.jelly</tt> to specify the destination
 * that the slaves talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Hudson.getInstance().getRootUrl();
  try {
    if(url!=null) {
      String host = new URL(url).getHost();
      if(host!=null)
        return host;
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Gets the absolute URL of Hudson top page, such as "http://localhost/hudson/".
 *
 * <p>
 * Unlike {@link #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.
 *
 * @since 1.263
 */
public String getRootUrlFromRequest() {
  StaplerRequest req = Stapler.getCurrentRequest();
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme() + "://");
  buf.append(req.getServerName());
  if (req.getServerPort() != 80) {
    buf.append(':').append(req.getServerPort());
  }
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Obtains the host name of the Hudson server that clients can use to talk
 * back to. <p> This is primarily used in <tt>slave-agent.jnlp.jelly</tt> to
 * specify the destination that the slaves talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Hudson.getInstance().getRootUrl();
  try {
    if (url != null) {
      String host = new URL(url).getHost();
      if (host != null) {
        return host;
      }
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Obtains the host name of the Hudson server that clients can use to talk back to.
 * <p>
 * This is primarily used in <tt>slave-agent.jnlp.jelly</tt> to specify the destination
 * that the slaves talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Hudson.getInstance().getRootUrl();
  try {
    if(url!=null) {
      String host = new URL(url).getHost();
      if(host!=null)
        return host;
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Gets the absolute URL of Hudson top page, such as
 * "http://localhost/hudson/".
 *
 * <p>
 * Unlike {@link #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.
 *
 * @since 1.263
 */
public String getRootUrlFromRequest() {
  StaplerRequest req = Stapler.getCurrentRequest();
  StringBuilder buf = new StringBuilder();
  buf.append(req.getScheme() + "://");
  buf.append(req.getServerName());
  if (req.getServerPort() != 80) {
    buf.append(':').append(req.getServerPort());
  }
  buf.append(req.getContextPath()).append('/');
  return buf.toString();
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Obtains the host name of the Hudson server that clients can use to talk back to.
 * <p>
 * This is primarily used in <tt>slave-agent.jnlp.jelly</tt> to specify the destination
 * that the slaves talk to.
 */
public String getServerName() {
  // Try to infer this from the configured root URL.
  // This makes it work correctly when Hudson runs behind a reverse proxy.
  String url = Hudson.getInstance().getRootUrl();
  try {
    if(url!=null) {
      String host = new URL(url).getHost();
      if(host!=null)
        return host;
    }
  } catch (MalformedURLException e) {
    // fall back to HTTP request
  }
  return Stapler.getCurrentRequest().getServerName();
}

相关文章

微信公众号

最新文章

更多

StaplerRequest类方法