org.apache.http.client.utils.URIBuilder.getHost()方法的使用及代码示例

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

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

URIBuilder.getHost介绍

暂无

代码示例

代码示例来源:origin: dounine/clouddisk

public String getRedHost() {
  try {
    final URIBuilder uriBuilder =new URIBuilder(getRedSchmemHost());
    return uriBuilder.getHost();
  } catch (URISyntaxException e) {
    LOGGER.error(ERROR,e);
  }
  return null;
}

代码示例来源:origin: org.apache.hadoop/hadoop-azure

protected HttpUriRequest getHttpRequest(String[] urls, String path,
  List<NameValuePair> queryParams, int urlIndex, String httpMethod,
  boolean requiresNewAuth) throws URISyntaxException, IOException {
 URIBuilder uriBuilder = null;
 uriBuilder =
   new URIBuilder(urls[urlIndex]).setPath(path).setParameters(queryParams);
 if (uriBuilder.getHost().equals("localhost")) {
  uriBuilder.setHost(InetAddress.getLocalHost().getCanonicalHostName());
 }
 HttpUriRequest httpUriRequest = null;
 switch (httpMethod) {
 case HttpPut.METHOD_NAME:
  httpUriRequest = new HttpPut(uriBuilder.build());
  break;
 case HttpPost.METHOD_NAME:
  httpUriRequest = new HttpPost(uriBuilder.build());
  break;
 default:
  httpUriRequest = new HttpGet(uriBuilder.build());
  break;
 }
 return httpUriRequest;
}

代码示例来源:origin: dounine/clouddisk

public String getRedSchmemHost() {
  final DifferPress differPress = getDependAccountResult(DifferPress.class);
  if (null == differPress) {
    throw new CloudDiskException(MsgConst.HOST_VALUE_NOT_NULL);
  } else {
    final URIBuilder uri = differPress.getRedirectUrl();
    return new StringBuilder(uri.getScheme()).append("://").append(uri.getHost()).toString();
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ROOT));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: com.blackducksoftware.tools/common-framework

/**
 * Provides information from the server URL.
 *
 * @param urlInfo
 *            the url info
 * @return the string
 */
@Override
public String findURLInformation(final URL_INFORMATION urlInfo) {
  String returnString = null;
  try {
    final URIBuilder builder = new URIBuilder(serverURL);
    if (urlInfo == URL_INFORMATION.HOST) {
      returnString = builder.getHost();
    } else if (urlInfo == URL_INFORMATION.PORT) {
      returnString = Integer.toString(builder.getPort());
    } else if (urlInfo == URL_INFORMATION.PROTOCOL) {
      returnString = builder.getScheme();
    }
  } catch (final Exception e) {
    log.warn("Unable to determine host name for: " + serverURL, e);
  }
  return returnString;
}

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ENGLISH));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ROOT));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ROOT));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: com.hynnet/httpclient

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ROOT));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ENGLISH));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: Nextdoor/bender

/**
 * @since 4.1
 */
protected URI createLocationURI(final String location) throws ProtocolException {
  try {
    final URIBuilder b = new URIBuilder(new URI(location).normalize());
    final String host = b.getHost();
    if (host != null) {
      b.setHost(host.toLowerCase(Locale.ROOT));
    }
    final String path = b.getPath();
    if (TextUtils.isEmpty(path)) {
      b.setPath("/");
    }
    return b.build();
  } catch (final URISyntaxException ex) {
    throw new ProtocolException("Invalid redirect URI: " + location, ex);
  }
}

代码示例来源:origin: kamax-matrix/mxhsd

private JsonObject sendPost(URIBuilder target, JsonElement payload) {
  try {
    if (!target.getScheme().equals("matrix")) {
      throw new IllegalArgumentException("Scheme can only be matrix");
    }
    String domain = target.getHost();
    target.setScheme("https");
    IRemoteAddress addr = resolver.resolve(target.getHost());
    target.setHost(addr.getHost());
    target.setPort(addr.getPort());
    return sendPost(domain, target.build(), payload);
  } catch (URISyntaxException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: kamax-matrix/mxhsd

private JsonObject sendPut(URIBuilder target, JsonElement payload) {
  try {
    if (!target.getScheme().equals("matrix")) {
      throw new IllegalArgumentException("Scheme can only be matrix");
    }
    String domain = target.getHost();
    target.setScheme("https");
    IRemoteAddress addr = resolver.resolve(target.getHost());
    target.setHost(addr.getHost());
    target.setPort(addr.getPort());
    return sendPut(domain, target.build(), payload);
  } catch (URISyntaxException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: kamax-matrix/mxhsd

private JsonObject sendGet(URIBuilder target) {
  try {
    if (!target.getScheme().equals("matrix")) {
      throw new IllegalArgumentException("Scheme can only be matrix");
    }
    String domain = target.getHost();
    target.setScheme("https");
    IRemoteAddress addr = resolver.resolve(target.getHost());
    target.setHost(addr.getHost());
    target.setPort(addr.getPort());
    return sendGet(domain, target.build());
  } catch (URISyntaxException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
  Args.notNull(uri, "URI");
  if (uri.isOpaque()) {
    return uri;
  }
  final URIBuilder uribuilder = new URIBuilder(uri);
  if (uribuilder.getUserInfo() != null) {
    uribuilder.setUserInfo(null);
  }
  if (TextUtils.isEmpty(uribuilder.getPath())) {
    uribuilder.setPath("/");
  }
  if (uribuilder.getHost() != null) {
    uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ROOT));
  }
  uribuilder.setFragment(null);
  return uribuilder.build();
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
  Args.notNull(uri, "URI");
  if (uri.isOpaque()) {
    return uri;
  }
  final URIBuilder uribuilder = new URIBuilder(uri);
  if (uribuilder.getUserInfo() != null) {
    uribuilder.setUserInfo(null);
  }
  if (TextUtils.isEmpty(uribuilder.getPath())) {
    uribuilder.setPath("/");
  }
  if (uribuilder.getHost() != null) {
    uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ROOT));
  }
  uribuilder.setFragment(null);
  return uribuilder.build();
}

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
  Args.notNull(uri, "URI");
  if (uri.isOpaque()) {
    return uri;
  }
  final URIBuilder uribuilder = new URIBuilder(uri);
  if (uribuilder.getUserInfo() != null) {
    uribuilder.setUserInfo(null);
  }
  if (TextUtils.isEmpty(uribuilder.getPath())) {
    uribuilder.setPath("/");
  }
  if (uribuilder.getHost() != null) {
    uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ENGLISH));
  }
  uribuilder.setFragment(null);
  return uribuilder.build();
}

代码示例来源:origin: ibinti/bugvm

/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
  Args.notNull(uri, "URI");
  if (uri.isOpaque()) {
    return uri;
  }
  final URIBuilder uribuilder = new URIBuilder(uri);
  if (uribuilder.getUserInfo() != null) {
    uribuilder.setUserInfo(null);
  }
  if (TextUtils.isEmpty(uribuilder.getPath())) {
    uribuilder.setPath("/");
  }
  if (uribuilder.getHost() != null) {
    uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ROOT));
  }
  uribuilder.setFragment(null);
  return uribuilder.build();
}

代码示例来源:origin: com.hynnet/httpclient

/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
  Args.notNull(uri, "URI");
  if (uri.isOpaque()) {
    return uri;
  }
  final URIBuilder uribuilder = new URIBuilder(uri);
  if (uribuilder.getUserInfo() != null) {
    uribuilder.setUserInfo(null);
  }
  if (TextUtils.isEmpty(uribuilder.getPath())) {
    uribuilder.setPath("/");
  }
  if (uribuilder.getHost() != null) {
    uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ROOT));
  }
  uribuilder.setFragment(null);
  return uribuilder.build();
}

代码示例来源:origin: com.intuit.karate/karate-apache

@Override
protected void buildCookie(com.intuit.karate.http.Cookie c) {
  BasicClientCookie cookie = new BasicClientCookie(c.getName(), c.getValue());
  for (Entry<String, String> entry : c.entrySet()) {
    switch (entry.getKey()) {
      case DOMAIN:
        cookie.setDomain(entry.getValue());
        break;
      case PATH:
        cookie.setPath(entry.getValue());
        break;
    }
  }
  if (cookie.getDomain() == null) {
    cookie.setDomain(uriBuilder.getHost());
  }
  cookieStore.addCookie(cookie);
}

相关文章